Skip to content

Commit 049a9d6

Browse files
authored
Merge pull request #425 from domaframework/enhance-criteria-api
Enhance the Criteria API
2 parents 18baf43 + 5672410 commit 049a9d6

File tree

99 files changed

+4035
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4035
-993
lines changed

docs/criteria-api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ We support the following aggregate functions:
592592
* min(property)
593593
* sum(property)
594594

595-
These are defined in the ``org.seasar.doma.jdbc.criteria.AggregateFunctions`` class.
595+
These are defined in the ``org.seasar.doma.jdbc.criteria.expression.Expressions`` class.
596596
Use them with static import.
597597

598598
For example, you can pass the ``sum`` function to the select method:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class MysqlPagingTransformer extends StandardPagingTransformer {
99

10-
protected static String MAXIMUM_LIMIT = "18446744073709551615";
10+
public static String MAXIMUM_LIMIT = "18446744073709551615";
1111

1212
public MysqlPagingTransformer(long offset, long limit) {
1313
super(offset, limit);

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/AggregateFunctions.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/Entityql.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.List;
44
import java.util.Objects;
55
import java.util.function.Consumer;
6+
import org.seasar.doma.jdbc.BatchResult;
67
import org.seasar.doma.jdbc.Config;
8+
import org.seasar.doma.jdbc.Result;
79
import org.seasar.doma.jdbc.criteria.context.DeleteSettings;
810
import org.seasar.doma.jdbc.criteria.context.InsertSettings;
911
import org.seasar.doma.jdbc.criteria.context.SelectContext;
@@ -30,7 +32,7 @@ public Entityql(Config config) {
3032

3133
public <ENTITY> EntityqlSelectStatement<ENTITY> from(EntityMetamodel<ENTITY> entityMetamodel) {
3234
Objects.requireNonNull(entityMetamodel);
33-
return from(entityMetamodel, options -> {});
35+
return from(entityMetamodel, settings -> {});
3436
}
3537

3638
public <ENTITY> EntityqlSelectStatement<ENTITY> from(
@@ -43,13 +45,14 @@ public <ENTITY> EntityqlSelectStatement<ENTITY> from(
4345
return new EntityqlSelectStatement<>(config, declaration);
4446
}
4547

46-
public <ENTITY> Statement<ENTITY> update(EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
48+
public <ENTITY> Statement<Result<ENTITY>> update(
49+
EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
4750
Objects.requireNonNull(entityMetamodel);
4851
Objects.requireNonNull(entity);
49-
return update(entityMetamodel, entity, options -> {});
52+
return update(entityMetamodel, entity, settings -> {});
5053
}
5154

52-
public <ENTITY> Statement<ENTITY> update(
55+
public <ENTITY> Statement<Result<ENTITY>> update(
5356
EntityMetamodel<ENTITY> entityMetamodel,
5457
ENTITY entity,
5558
Consumer<UpdateSettings> settingsConsumer) {
@@ -61,13 +64,14 @@ public <ENTITY> Statement<ENTITY> update(
6164
return new EntityqlUpdateStatement<>(config, entityMetamodel, entity, settings);
6265
}
6366

64-
public <ENTITY> Statement<ENTITY> delete(EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
67+
public <ENTITY> Statement<Result<ENTITY>> delete(
68+
EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
6569
Objects.requireNonNull(entityMetamodel);
6670
Objects.requireNonNull(entity);
67-
return delete(entityMetamodel, entity, options -> {});
71+
return delete(entityMetamodel, entity, settings -> {});
6872
}
6973

70-
public <ENTITY> Statement<ENTITY> delete(
74+
public <ENTITY> Statement<Result<ENTITY>> delete(
7175
EntityMetamodel<ENTITY> entityMetamodel,
7276
ENTITY entity,
7377
Consumer<DeleteSettings> settingsConsumer) {
@@ -79,13 +83,14 @@ public <ENTITY> Statement<ENTITY> delete(
7983
return new EntityqlDeleteStatement<>(config, entityMetamodel, entity, settings);
8084
}
8185

82-
public <ENTITY> Statement<ENTITY> insert(EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
86+
public <ENTITY> Statement<Result<ENTITY>> insert(
87+
EntityMetamodel<ENTITY> entityMetamodel, ENTITY entity) {
8388
Objects.requireNonNull(entityMetamodel);
8489
Objects.requireNonNull(entity);
85-
return insert(entityMetamodel, entity, options -> {});
90+
return insert(entityMetamodel, entity, settings -> {});
8691
}
8792

88-
public <ENTITY> Statement<ENTITY> insert(
93+
public <ENTITY> Statement<Result<ENTITY>> insert(
8994
EntityMetamodel<ENTITY> entityMetamodel,
9095
ENTITY entity,
9196
Consumer<InsertSettings> settingsConsumer) {
@@ -97,14 +102,14 @@ public <ENTITY> Statement<ENTITY> insert(
97102
return new EntityqlInsertStatement<>(config, entityMetamodel, entity, settings);
98103
}
99104

100-
public <ENTITY> Statement<List<ENTITY>> update(
105+
public <ENTITY> Statement<BatchResult<ENTITY>> update(
101106
EntityMetamodel<ENTITY> entityMetamodel, List<ENTITY> entities) {
102107
Objects.requireNonNull(entityMetamodel);
103108
Objects.requireNonNull(entities);
104-
return update(entityMetamodel, entities, options -> {});
109+
return update(entityMetamodel, entities, settings -> {});
105110
}
106111

107-
public <ENTITY> Statement<List<ENTITY>> update(
112+
public <ENTITY> Statement<BatchResult<ENTITY>> update(
108113
EntityMetamodel<ENTITY> entityMetamodel,
109114
List<ENTITY> entities,
110115
Consumer<UpdateSettings> settingsConsumer) {
@@ -116,14 +121,14 @@ public <ENTITY> Statement<List<ENTITY>> update(
116121
return new EntityqlBatchUpdateStatement<>(config, entityMetamodel, entities, settings);
117122
}
118123

119-
public <ENTITY> Statement<List<ENTITY>> delete(
124+
public <ENTITY> Statement<BatchResult<ENTITY>> delete(
120125
EntityMetamodel<ENTITY> entityMetamodel, List<ENTITY> entities) {
121126
Objects.requireNonNull(entityMetamodel);
122127
Objects.requireNonNull(entities);
123-
return delete(entityMetamodel, entities, options -> {});
128+
return delete(entityMetamodel, entities, settings -> {});
124129
}
125130

126-
public <ENTITY> Statement<List<ENTITY>> delete(
131+
public <ENTITY> Statement<BatchResult<ENTITY>> delete(
127132
EntityMetamodel<ENTITY> entityMetamodel,
128133
List<ENTITY> entities,
129134
Consumer<DeleteSettings> settingsConsumer) {
@@ -135,14 +140,14 @@ public <ENTITY> Statement<List<ENTITY>> delete(
135140
return new EntityqlBatchDeleteStatement<>(config, entityMetamodel, entities, settings);
136141
}
137142

138-
public <ENTITY> Statement<List<ENTITY>> insert(
143+
public <ENTITY> Statement<BatchResult<ENTITY>> insert(
139144
EntityMetamodel<ENTITY> entityMetamodel, List<ENTITY> entities) {
140145
Objects.requireNonNull(entityMetamodel);
141146
Objects.requireNonNull(entities);
142-
return insert(entityMetamodel, entities, options -> {});
147+
return insert(entityMetamodel, entities, settings -> {});
143148
}
144149

145-
public <ENTITY> Statement<List<ENTITY>> insert(
150+
public <ENTITY> Statement<BatchResult<ENTITY>> insert(
146151
EntityMetamodel<ENTITY> entityMetamodel,
147152
List<ENTITY> entities,
148153
Consumer<InsertSettings> settingsConsumer) {

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/NativeSql.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public NativeSql(Config config) {
3434
}
3535

3636
public <ENTITY> NativeSqlSelectStarting<ENTITY> from(EntityMetamodel<ENTITY> entityMetamodel) {
37-
return from(entityMetamodel, (options) -> {});
37+
return from(entityMetamodel, (settings) -> {});
3838
}
3939

4040
public <ENTITY> NativeSqlSelectStarting<ENTITY> from(
@@ -51,7 +51,7 @@ public <ENTITY> NativeSqlSelectStarting<ENTITY> from(
5151

5252
public <ENTITY> NativeSqlUpdateStarting update(EntityMetamodel<ENTITY> entityMetamodel) {
5353
Objects.requireNonNull(entityMetamodel);
54-
return this.update(entityMetamodel, options -> {});
54+
return this.update(entityMetamodel, settings -> {});
5555
}
5656

5757
public <ENTITY> NativeSqlUpdateStarting update(
@@ -66,7 +66,7 @@ public <ENTITY> NativeSqlUpdateStarting update(
6666

6767
public <ENTITY> NativeSqlDeleteStarting delete(EntityMetamodel<ENTITY> entityMetamodel) {
6868
Objects.requireNonNull(entityMetamodel);
69-
return this.delete(entityMetamodel, options -> {});
69+
return this.delete(entityMetamodel, settings -> {});
7070
}
7171

7272
public <ENTITY> NativeSqlDeleteStarting delete(
@@ -81,7 +81,7 @@ public <ENTITY> NativeSqlDeleteStarting delete(
8181

8282
public <ENTITY> NativeSqlInsertStarting insert(EntityMetamodel<ENTITY> entityMetamodel) {
8383
Objects.requireNonNull(entityMetamodel);
84-
return this.insert(entityMetamodel, options -> {});
84+
return this.insert(entityMetamodel, settings -> {});
8585
}
8686

8787
public <ENTITY> NativeSqlInsertStarting insert(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.seasar.doma.jdbc.criteria.command;
2+
3+
import org.seasar.doma.jdbc.criteria.metamodel.EntityMetamodel;
4+
import org.seasar.doma.jdbc.criteria.metamodel.PropertyMetamodel;
5+
6+
public interface DataRow {
7+
8+
<ENTITY> ENTITY get(EntityMetamodel<ENTITY> entityEntityMetamodel);
9+
10+
<PROPERTY> PROPERTY get(PropertyMetamodel<PROPERTY> propertyMetamodel);
11+
}

doma-core/src/main/java/org/seasar/doma/jdbc/criteria/command/EntityPoolProvider.java

Lines changed: 3 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import static java.util.stream.Collectors.toList;
44

5-
import java.sql.CallableStatement;
6-
import java.sql.PreparedStatement;
75
import java.sql.ResultSet;
86
import java.sql.SQLException;
97
import java.util.ArrayList;
@@ -12,28 +10,21 @@
1210
import java.util.Map;
1311
import java.util.Objects;
1412
import java.util.stream.Collectors;
15-
import org.seasar.doma.DomaNullPointerException;
16-
import org.seasar.doma.internal.jdbc.command.JdbcValueGetter;
17-
import org.seasar.doma.jdbc.JdbcMappable;
18-
import org.seasar.doma.jdbc.JdbcMappingFunction;
19-
import org.seasar.doma.jdbc.JdbcMappingVisitor;
2013
import org.seasar.doma.jdbc.ObjectProvider;
2114
import org.seasar.doma.jdbc.criteria.metamodel.EntityMetamodel;
2215
import org.seasar.doma.jdbc.entity.EntityPropertyType;
2316
import org.seasar.doma.jdbc.entity.EntityType;
2417
import org.seasar.doma.jdbc.entity.Property;
2518
import org.seasar.doma.jdbc.query.Query;
26-
import org.seasar.doma.jdbc.type.JdbcType;
27-
import org.seasar.doma.wrapper.Wrapper;
2819

2920
public class EntityPoolProvider implements ObjectProvider<EntityPool> {
3021
private final List<EntityMetamodel<?>> entityMetamodels;
31-
private final JdbcMappingVisitor jdbcMappingVisitor;
22+
private final FetchSupport fetchSupport;
3223

3324
public EntityPoolProvider(List<EntityMetamodel<?>> entityMetamodels, Query query) {
3425
this.entityMetamodels = Objects.requireNonNull(entityMetamodels);
3526
Objects.requireNonNull(query);
36-
this.jdbcMappingVisitor = query.getConfig().getDialect().getJdbcMappingVisitor();
27+
this.fetchSupport = new FetchSupport(query);
3728
}
3829

3930
@Override
@@ -48,7 +39,7 @@ public EntityPool get(ResultSet resultSet) throws SQLException {
4839
List<Prop> props = new ArrayList<>(propertyTypes.size());
4940
for (EntityPropertyType<?, ?> propertyType : propertyTypes) {
5041
Property<Object, ?> property = (Property<Object, ?>) propertyType.createProperty();
51-
Object rawValue = fetch(resultSet, property, index++);
42+
Object rawValue = fetchSupport.fetch(resultSet, property, index++);
5243
props.add(new Prop(propertyType, property, rawValue));
5344
}
5445
if (props.stream().allMatch(p -> p.rawValue == null)) {
@@ -73,14 +64,6 @@ public EntityPool get(ResultSet resultSet) throws SQLException {
7364
return entityPool;
7465
}
7566

76-
private Object fetch(ResultSet resultSet, JdbcMappable<?> mappable, int index)
77-
throws SQLException {
78-
Wrapper<?> wrapper = mappable.getWrapper();
79-
JdbcValueGetterProxy proxy = new JdbcValueGetterProxy(new JdbcValueGetter(resultSet, index));
80-
wrapper.accept(jdbcMappingVisitor, proxy, mappable);
81-
return proxy.rawValue;
82-
}
83-
8467
private static class Prop {
8568
private final EntityPropertyType<?, ?> propType;
8669
private final Property<Object, ?> prop;
@@ -92,62 +75,4 @@ public Prop(EntityPropertyType<?, ?> propType, Property<Object, ?> prop, Object
9275
this.rawValue = rawValue;
9376
}
9477
}
95-
96-
private static class JdbcValueGetterProxy implements JdbcMappingFunction {
97-
private final JdbcValueGetter jdbcValueGetter;
98-
Object rawValue;
99-
100-
JdbcValueGetterProxy(JdbcValueGetter jdbcValueGetter) {
101-
Objects.requireNonNull(jdbcValueGetter);
102-
this.jdbcValueGetter = jdbcValueGetter;
103-
}
104-
105-
@Override
106-
public <R, V> R apply(Wrapper<V> wrapper, JdbcType<V> jdbcType) throws SQLException {
107-
JdbcTypeProxy<V> proxy = new JdbcTypeProxy<>(jdbcType);
108-
R result = jdbcValueGetter.apply(wrapper, proxy);
109-
rawValue = proxy.rawValue;
110-
return result;
111-
}
112-
}
113-
114-
private static class JdbcTypeProxy<T> implements JdbcType<T> {
115-
private final JdbcType<T> jdbcType;
116-
T rawValue;
117-
118-
JdbcTypeProxy(JdbcType<T> jdbcType) {
119-
Objects.requireNonNull(jdbcType);
120-
this.jdbcType = jdbcType;
121-
}
122-
123-
@Override
124-
public T getValue(ResultSet resultSet, int index)
125-
throws DomaNullPointerException, SQLException {
126-
T value = jdbcType.getValue(resultSet, index);
127-
rawValue = value;
128-
return value;
129-
}
130-
131-
@Override
132-
public void setValue(PreparedStatement preparedStatement, int index, T value)
133-
throws SQLException {
134-
jdbcType.setValue(preparedStatement, index, value);
135-
}
136-
137-
@Override
138-
public void registerOutParameter(CallableStatement callableStatement, int index)
139-
throws SQLException {
140-
jdbcType.registerOutParameter(callableStatement, index);
141-
}
142-
143-
@Override
144-
public T getValue(CallableStatement callableStatement, int index) throws SQLException {
145-
return jdbcType.getValue(callableStatement, index);
146-
}
147-
148-
@Override
149-
public String convertToLogFormat(T value) {
150-
return jdbcType.convertToLogFormat(value);
151-
}
152-
}
15378
}

0 commit comments

Comments
 (0)