Skip to content

Commit 6ec902f

Browse files
committed
Refactor
1 parent d826420 commit 6ec902f

File tree

6 files changed

+29
-37
lines changed

6 files changed

+29
-37
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/dialect/OracleMultiInsertAssembler.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class OracleMultiInsertAssembler<ENTITY> implements MultiInsertAssembler
1515
public final EntityType<?> entityType;
1616
public final Naming naming;
1717
public final Dialect dialect;
18-
public final List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes;
18+
public final List<EntityPropertyType<ENTITY, ?>> insertPropertyTypes;
1919
public final List<ENTITY> entities;
2020

2121
public OracleMultiInsertAssembler(MultiInsertAssemblerContext<ENTITY> context) {
2222
this.buf = context.buf;
2323
this.entityType = context.entityType;
2424
this.naming = context.naming;
2525
this.dialect = context.dialect;
26-
this.targetPropertyTypes = context.targetPropertyTypes;
26+
this.insertPropertyTypes = context.insertPropertyTypes;
2727
this.entities = context.entities;
2828
}
2929

@@ -34,19 +34,21 @@ public void assemble() {
3434
buf.appendSql("into ");
3535
buf.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
3636
buf.appendSql(" (");
37-
if (!targetPropertyTypes.isEmpty()) {
38-
for (EntityPropertyType<?, ?> propertyType : targetPropertyTypes) {
37+
if (!insertPropertyTypes.isEmpty()) {
38+
for (EntityPropertyType<?, ?> propertyType : insertPropertyTypes) {
3939
buf.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
4040
buf.appendSql(", ");
4141
}
4242
buf.cutBackSql(2);
4343
}
4444
buf.appendSql(") values (");
45-
for (EntityPropertyType<ENTITY, ?> propertyType : targetPropertyTypes) {
46-
Property<ENTITY, ?> property = propertyType.createProperty();
47-
property.load(entity);
48-
buf.appendParameter(property.asInParameter());
49-
buf.appendSql(", ");
45+
if (!insertPropertyTypes.isEmpty()) {
46+
for (EntityPropertyType<ENTITY, ?> propertyType : insertPropertyTypes) {
47+
Property<ENTITY, ?> property = propertyType.createProperty();
48+
property.load(entity);
49+
buf.appendParameter(property.asInParameter());
50+
buf.appendSql(", ");
51+
}
5052
}
5153
buf.cutBackSql(2);
5254
buf.appendSql(") ");

doma-core/src/main/java/org/seasar/doma/jdbc/dialect/StandardMultiInsertAssembler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public class StandardMultiInsertAssembler<ENTITY> implements MultiInsertAssemble
1515
public final EntityType<?> entityType;
1616
public final Naming naming;
1717
public final Dialect dialect;
18-
public final List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes;
18+
public final List<EntityPropertyType<ENTITY, ?>> insertPropertyTypes;
1919
public final List<ENTITY> entities;
2020

2121
public StandardMultiInsertAssembler(MultiInsertAssemblerContext<ENTITY> context) {
2222
this.buf = context.buf;
2323
this.entityType = context.entityType;
2424
this.naming = context.naming;
2525
this.dialect = context.dialect;
26-
this.targetPropertyTypes = context.targetPropertyTypes;
26+
this.insertPropertyTypes = context.insertPropertyTypes;
2727
this.entities = context.entities;
2828
}
2929

@@ -32,8 +32,8 @@ public void assemble() {
3232
buf.appendSql("insert into ");
3333
buf.appendSql(entityType.getQualifiedTableName(naming::apply, dialect::applyQuote));
3434
buf.appendSql(" (");
35-
if (!targetPropertyTypes.isEmpty()) {
36-
for (EntityPropertyType<?, ?> propertyType : targetPropertyTypes) {
35+
if (!insertPropertyTypes.isEmpty()) {
36+
for (EntityPropertyType<?, ?> propertyType : insertPropertyTypes) {
3737
buf.appendSql(propertyType.getColumnName(naming::apply, dialect::applyQuote));
3838
buf.appendSql(", ");
3939
}
@@ -43,8 +43,8 @@ public void assemble() {
4343
if (!entities.isEmpty()) {
4444
for (ENTITY entity : entities) {
4545
buf.appendSql("(");
46-
if (!targetPropertyTypes.isEmpty()) {
47-
for (EntityPropertyType<ENTITY, ?> propertyType : targetPropertyTypes) {
46+
if (!insertPropertyTypes.isEmpty()) {
47+
for (EntityPropertyType<ENTITY, ?> propertyType : insertPropertyTypes) {
4848
Property<ENTITY, ?> property = propertyType.createProperty();
4949
property.load(entity);
5050
buf.appendParameter(property.asInParameter());

doma-core/src/main/java/org/seasar/doma/jdbc/query/AutoMultiInsertQuery.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ private void assembleUpsertSql(PreparedSqlBuilder builder, Naming naming, Dialec
175175
idPropertyTypes,
176176
targetPropertyTypes,
177177
entities);
178-
UpsertAssembler upsertAssembler = dialect.getUpsertAssembler(context);
179-
upsertAssembler.assemble();
180-
sql = builder.build(this::comment);
178+
UpsertAssembler assembler = dialect.getUpsertAssembler(context);
179+
assembler.assemble();
181180
}
182181

183182
@Override

doma-core/src/main/java/org/seasar/doma/jdbc/query/MultiInsertAssemblerContext.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MultiInsertAssemblerContext<ENTITY> {
1919
public final EntityType<ENTITY> entityType;
2020
public final Naming naming;
2121
public final Dialect dialect;
22-
public final List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes;
22+
public final List<EntityPropertyType<ENTITY, ?>> insertPropertyTypes;
2323
public final List<ENTITY> entities;
2424

2525
/**
@@ -29,21 +29,21 @@ public class MultiInsertAssemblerContext<ENTITY> {
2929
* @param entityType the entity type
3030
* @param naming the naming convention
3131
* @param dialect the SQL dialect
32-
* @param targetPropertyTypes the property types that are targets for the insert
32+
* @param insertPropertyTypes the property types that are targets for the insert
3333
* @param entities the entities
3434
*/
3535
MultiInsertAssemblerContext(
3636
PreparedSqlBuilder buf,
3737
EntityType<ENTITY> entityType,
3838
Naming naming,
3939
Dialect dialect,
40-
List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes,
40+
List<EntityPropertyType<ENTITY, ?>> insertPropertyTypes,
4141
List<ENTITY> entities) {
4242
Objects.requireNonNull(buf);
4343
Objects.requireNonNull(entityType);
4444
Objects.requireNonNull(naming);
4545
Objects.requireNonNull(dialect);
46-
Objects.requireNonNull(targetPropertyTypes);
46+
Objects.requireNonNull(insertPropertyTypes);
4747
Objects.requireNonNull(entities);
4848
if (entities.isEmpty()) {
4949
throw new DomaIllegalArgumentException(
@@ -53,7 +53,7 @@ public class MultiInsertAssemblerContext<ENTITY> {
5353
this.entityType = entityType;
5454
this.naming = naming;
5555
this.dialect = dialect;
56-
this.targetPropertyTypes = targetPropertyTypes;
56+
this.insertPropertyTypes = insertPropertyTypes;
5757
this.entities = entities;
5858
}
5959
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/MultiInsertAssemblerContextBuilder.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,10 @@ public static <ENTITY> MultiInsertAssemblerContext<ENTITY> buildFromEntityList(
1414
EntityType<ENTITY> entityType,
1515
Naming naming,
1616
Dialect dialect,
17-
List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes,
17+
List<EntityPropertyType<ENTITY, ?>> insertPropertyTypes,
1818
List<ENTITY> entities) {
1919

20-
return buildInternal(buf, entityType, naming, dialect, targetPropertyTypes, entities);
21-
}
22-
23-
private static <ENTITY> MultiInsertAssemblerContext<ENTITY> buildInternal(
24-
PreparedSqlBuilder buf,
25-
EntityType<ENTITY> entityType,
26-
Naming naming,
27-
Dialect dialect,
28-
List<EntityPropertyType<ENTITY, ?>> targetPropertyTypes,
29-
List<ENTITY> entities) {
30-
31-
return new MultiInsertAssemblerContext<ENTITY>(
32-
buf, entityType, naming, dialect, targetPropertyTypes, entities);
20+
return new MultiInsertAssemblerContext<>(
21+
buf, entityType, naming, dialect, insertPropertyTypes, entities);
3322
}
3423
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/UpsertAssemblerContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public class UpsertAssemblerContext {
7272
Objects.requireNonNull(naming);
7373
Objects.requireNonNull(dialect);
7474
Objects.requireNonNull(keys);
75+
Objects.requireNonNull(insertPropertyTypes);
7576
Objects.requireNonNull(insertRows);
77+
Objects.requireNonNull(setValues);
7678
if (duplicateKeyType == DuplicateKeyType.EXCEPTION) {
7779
throw new DomaIllegalArgumentException(
7880
"duplicateKeyType",

0 commit comments

Comments
 (0)