Skip to content

Deriving Names

Philippe Marschall edited this page Oct 22, 2016 · 5 revisions

We have to derive database names from Java names. For example we have the name of the Java method and need to derive the name of the stored procedure from the Java method name. We require names for:

  • procedures
  • schemas
  • packages or modules

If the Java names do not match the database names then there are different options how we can derive them.

If there are simple rules how a database name can be derived from a Java name you can use NamingStrategy. This is most of the case when you have a naming convention that you follow. If this is not the case you can use the @ProcedureName, @Namespace and @Schema annotations.

For example let's say you want to call a stored procedure named sp_Blitz. You can either give the Java method the same name

public interface Demo {

  void sp_Blitz();

}

or use the @ProcedureName annotation

public interface Demo {

  @ProcedureName("sp_Blitz")
  void blitz();

}

or use a NamingStrategy. This is most useful when you have several stored procedures that all follow the same naming convention.

public interface Demo {

  void blitz();

}

Demo demo = ProcedureCallerFactory.of(Demo.class, dataSource)
    .withProcedureNamingStrategy(NamingStrategy.capitalize().thenPrefix("sp_"))
    .build();

The NamingStrategy comes with implementations of common transformations and allows chaining but you can also implement you own.