Skip to content

Commit

Permalink
Generator: Optimize SqlAdapter generation by using SqlTypeMapperHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyknic committed Oct 3, 2016
1 parent 189e4d6 commit 8e63ec5
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 119 deletions.
Expand Up @@ -68,6 +68,16 @@ protected Class makeCodeGenModel(File file) {


return newBuilder(file, getSupport().generatedEntityImplName()) return newBuilder(file, getSupport().generatedEntityImplName())


/**
* Class details
*/
.forEveryTable((clazz, table) -> {
clazz.public_()
.abstract_()
.add(getSupport().entityType())
.add(Constructor.of().protected_());
})

/** /**
* Getters * Getters
*/ */
Expand Down Expand Up @@ -99,7 +109,7 @@ protected Class makeCodeGenModel(File file) {
.forEveryColumn((clazz, col) -> { .forEveryColumn((clazz, col) -> {
clazz clazz
.add(Method.of(SETTER_METHOD_PREFIX + getSupport().typeName(col), getSupport().entityType()) .add(Method.of(SETTER_METHOD_PREFIX + getSupport().typeName(col), getSupport().entityType())
.public_().final_() .public_()
.add(OVERRIDE) .add(OVERRIDE)
.add(fieldFor(col)) .add(fieldFor(col))
.add("this." + getSupport().variableName(col) + " = " + getSupport().variableName(col) + ";") .add("this." + getSupport().variableName(col) + " = " + getSupport().variableName(col) + ";")
Expand Down Expand Up @@ -149,22 +159,15 @@ protected Class makeCodeGenModel(File file) {
); );
}); });
}) })


/**
* Class details
*/
// We need to make it POST_MAKE because other plugins might add fields // We need to make it POST_MAKE because other plugins might add fields
.forEveryTable(Phase.POST_MAKE, (clazz, table) -> { .forEveryTable(Phase.POST_MAKE, (clazz, table) -> {
clazz clazz
.add(toStringMethod(file)) .add(toStringMethod(file))
.add(equalsMethod()) .add(equalsMethod())
.add(hashCodeMethod()); .add(hashCodeMethod());
}) })
.build() .build();
.public_()
.abstract_()
.add(getSupport().generatedEntityType())
.add(Constructor.of().protected_());


} }


Expand Down
Expand Up @@ -95,8 +95,10 @@ public interface ReadFromResultSet {
String readFromResultSet(File file, Column c, AtomicInteger position); String readFromResultSet(File file, Column c, AtomicInteger position);
} }


public static String[] generateNewEntityFromBody(ReadFromResultSet readFromResultSet, TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) { public static String[] generateApplyResultSetBody(ReadFromResultSet readFromResultSet, TranslatorSupport<Table> support, File file, Supplier<Stream<? extends Column>> columnsSupplier) {


file.add(Import.of(SQLException.class));

final List<String> rows = new LinkedList<>(); final List<String> rows = new LinkedList<>();
rows.add("final " + support.entityName() + " entity = manager." + ENTITY_CREATE_METHOD_NAME + "();"); rows.add("final " + support.entityName() + " entity = manager." + ENTITY_CREATE_METHOD_NAME + "();");


Expand All @@ -110,7 +112,7 @@ public static String[] generateNewEntityFromBody(ReadFromResultSet readFromResul
}); });


rows.add("try " + block(streamBuilder.build())); rows.add("try " + block(streamBuilder.build()));
rows.add("catch (" + SQLException.class.getSimpleName() + " sqle) " + block( rows.add("catch (final " + SQLException.class.getSimpleName() + " sqle) " + block(
"throw new " + SpeedmentException.class.getSimpleName() + "(sqle);" "throw new " + SpeedmentException.class.getSimpleName() + "(sqle);"
)); ));
rows.add("return entity;"); rows.add("return entity;");
Expand Down

0 comments on commit 8e63ec5

Please sign in to comment.