Skip to content

Commit 7198a19

Browse files
committed
Merge branch 'gh-22'
2 parents ad3db9a + d1c639e commit 7198a19

File tree

4 files changed

+123
-88
lines changed

4 files changed

+123
-88
lines changed

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfiguration.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.seasar.doma.boot.autoconfigure;
1717

18+
import javax.sql.DataSource;
19+
1820
import org.seasar.doma.jdbc.Config;
1921
import org.seasar.doma.jdbc.EntityListenerProvider;
2022
import org.seasar.doma.jdbc.Naming;
@@ -26,17 +28,12 @@
2628
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2729
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2830
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
29-
import org.springframework.boot.context.properties.ConfigurationProperties;
3031
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3132
import org.springframework.context.annotation.Bean;
3233
import org.springframework.context.annotation.Configuration;
3334
import org.springframework.dao.support.PersistenceExceptionTranslator;
3435
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
3536

36-
import javax.sql.DataSource;
37-
38-
import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;
39-
4037
/**
4138
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
4239
* Auto-configuration} for Doma.
@@ -91,11 +88,10 @@ public DomaConfigBuilder domaConfigBuilder() {
9188

9289
@Bean
9390
@ConditionalOnMissingBean(Config.class)
94-
@ConfigurationProperties(prefix = DOMA_PREFIX)
9591
public DomaConfig config(DataSource dataSource, Dialect dialect,
9692
SqlFileRepository sqlFileRepository, Naming naming,
9793
EntityListenerProvider entityListenerProvider,
98-
DomaConfigBuilder domaConfigBuilder) {
94+
DomaConfigBuilder domaConfigBuilder, DomaProperties domaProperties) {
9995
if (domaConfigBuilder.dataSource() == null) {
10096
domaConfigBuilder.dataSource(dataSource);
10197
}
@@ -111,7 +107,7 @@ public DomaConfig config(DataSource dataSource, Dialect dialect,
111107
if (domaConfigBuilder.entityListenerProvider() == null) {
112108
domaConfigBuilder.entityListenerProvider(entityListenerProvider);
113109
}
114-
return new DomaConfig(domaConfigBuilder);
110+
return domaConfigBuilder.build(domaProperties);
115111
}
116112

117113
}

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaConfig.java

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,17 @@
1515
*/
1616
package org.seasar.doma.boot.autoconfigure;
1717

18+
import javax.sql.DataSource;
19+
1820
import org.seasar.doma.jdbc.*;
1921
import org.seasar.doma.jdbc.dialect.Dialect;
2022

21-
import javax.sql.DataSource;
22-
2323
/**
2424
* {@link Config} implementation used in doma-spring-boot.
2525
*
2626
* @author Toshiaki Maki
2727
*/
2828
public class DomaConfig implements Config {
29-
/**
30-
* Datasource name.
31-
*/
32-
private String dataSourceName = Config.class.getName();
33-
34-
/**
35-
* Type of SQL log in the exception.
36-
*/
37-
private SqlLogType exceptionSqlLogType = SqlLogType.NONE;
38-
39-
/**
40-
* Limit for the maximum number of rows. Ignored unless this value is greater than 0.
41-
*/
42-
private int maxRows = 0;
43-
/**
44-
* Hint to the number of rows that should be fetched. Ignored unless this value is
45-
* greater than 0.
46-
*/
47-
private int fetchSize = 0;
48-
/**
49-
* Number of seconds the driver will wait for a <code>Statement</code> object to
50-
* execute. Ignored unless this value is greater than 0.
51-
*/
52-
private int queryTimeout = 0;
53-
/**
54-
* Size in executing <code>PreparedStatement#addBatch()</code>. Regarded as 1 unless
55-
* this value is greater than 1.
56-
*/
57-
private int batchSize = 0;
5829

5930
private final DataSource dataSource;
6031
private final Dialect dialect;
@@ -69,8 +40,9 @@ public class DomaConfig implements Config {
6940
private final MapKeyNaming mapKeyNaming;
7041
private final Commenter commenter;
7142
private final EntityListenerProvider entityListenerProvider;
43+
private final DomaProperties domaProperties;
7244

73-
public DomaConfig(DomaConfigBuilder builder) {
45+
public DomaConfig(DomaConfigBuilder builder, DomaProperties domaProperties) {
7446
this.dataSource = builder.dataSource();
7547
this.dialect = builder.dialect();
7648
this.jdbcLogger = builder.jdbcLogger();
@@ -84,6 +56,7 @@ public DomaConfig(DomaConfigBuilder builder) {
8456
this.mapKeyNaming = builder.mapKeyNaming();
8557
this.commenter = builder.commenter();
8658
this.entityListenerProvider = builder.entityListenerProvider();
59+
this.domaProperties = domaProperties;
8760
}
8861

8962
@Override
@@ -98,11 +71,7 @@ public Dialect getDialect() {
9871

9972
@Override
10073
public String getDataSourceName() {
101-
return this.dataSourceName;
102-
}
103-
104-
public void setDataSourceName(String dataSourceName) {
105-
this.dataSourceName = dataSourceName;
74+
return this.domaProperties.getDataSourceName();
10675
}
10776

10877
@Override
@@ -135,13 +104,9 @@ public QueryImplementors getQueryImplementors() {
135104
return this.queryImplementors;
136105
}
137106

138-
public void setExceptionSqlLogType(SqlLogType exceptionSqlLogType) {
139-
this.exceptionSqlLogType = exceptionSqlLogType;
140-
}
141-
142107
@Override
143108
public SqlLogType getExceptionSqlLogType() {
144-
return this.exceptionSqlLogType;
109+
return this.domaProperties.getExceptionSqlLogType();
145110
}
146111

147112
@Override
@@ -166,42 +131,39 @@ public Commenter getCommenter() {
166131

167132
@Override
168133
public int getMaxRows() {
169-
return this.maxRows;
170-
}
171-
172-
public void setMaxRows(int maxRows) {
173-
this.maxRows = maxRows;
134+
return this.domaProperties.getMaxRows();
174135
}
175136

176137
@Override
177138
public int getFetchSize() {
178-
return this.fetchSize;
179-
}
180-
181-
public void setFetchSize(int fetchSize) {
182-
this.fetchSize = fetchSize;
139+
return this.domaProperties.getFetchSize();
183140
}
184141

185142
@Override
186143
public int getQueryTimeout() {
187-
return this.queryTimeout;
188-
}
189-
190-
public void setQueryTimeout(int queryTimeout) {
191-
this.queryTimeout = queryTimeout;
144+
return this.domaProperties.getQueryTimeout();
192145
}
193146

194147
@Override
195148
public int getBatchSize() {
196-
return this.batchSize;
197-
}
198-
199-
public void setBatchSize(int batchSize) {
200-
this.batchSize = batchSize;
149+
return this.domaProperties.getBatchSize();
201150
}
202151

203152
@Override
204153
public EntityListenerProvider getEntityListenerProvider() {
205154
return this.entityListenerProvider;
206155
}
156+
157+
@Override
158+
public String toString() {
159+
return "DomaConfig{" + "dataSource=" + dataSource + ", dialect=" + dialect
160+
+ ", jdbcLogger=" + jdbcLogger + ", sqlFileRepository="
161+
+ sqlFileRepository + ", requiresNewController=" + requiresNewController
162+
+ ", classHelper=" + classHelper + ", commandImplementors="
163+
+ commandImplementors + ", queryImplementors=" + queryImplementors
164+
+ ", unknownColumnHandler=" + unknownColumnHandler + ", naming=" + naming
165+
+ ", mapKeyNaming=" + mapKeyNaming + ", commenter=" + commenter
166+
+ ", entityListenerProvider=" + entityListenerProvider
167+
+ ", domaProperties=" + domaProperties + '}';
168+
}
207169
}

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaConfigBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*/
1616
package org.seasar.doma.boot.autoconfigure;
1717

18+
import javax.sql.DataSource;
19+
1820
import org.seasar.doma.jdbc.*;
1921
import org.seasar.doma.jdbc.dialect.Dialect;
2022
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
2123

22-
import javax.sql.DataSource;
23-
2424
/**
2525
* Builder to create {@link DomaConfig}.
2626
*
@@ -179,7 +179,7 @@ public DomaConfigBuilder entityListenerProvider(
179179
return this;
180180
}
181181

182-
public DomaConfig build() {
183-
return new DomaConfig(this);
182+
public DomaConfig build(DomaProperties domaProperties) {
183+
return new DomaConfig(this, domaProperties);
184184
}
185185
}

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaProperties.java

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
*/
1616
package org.seasar.doma.boot.autoconfigure;
1717

18-
import org.seasar.doma.jdbc.GreedyCacheSqlFileRepository;
19-
import org.seasar.doma.jdbc.Naming;
20-
import org.seasar.doma.jdbc.NoCacheSqlFileRepository;
21-
import org.seasar.doma.jdbc.SqlFileRepository;
22-
import org.seasar.doma.jdbc.dialect.*;
23-
import org.springframework.boot.context.properties.ConfigurationProperties;
18+
import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;
2419

2520
import java.util.function.Supplier;
2621

27-
import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;
22+
import org.seasar.doma.jdbc.*;
23+
import org.seasar.doma.jdbc.dialect.*;
24+
import org.springframework.boot.context.properties.ConfigurationProperties;
2825

2926
/**
3027
* {@link ConfigurationProperties} for configuring Doma.
@@ -56,6 +53,36 @@ public class DomaProperties {
5653
*/
5754
private boolean exceptionTranslationEnabled = true;
5855

56+
/**
57+
* Datasource name.
58+
*/
59+
private String dataSourceName = Config.class.getName();
60+
61+
/**
62+
* Type of SQL log in the exception.
63+
*/
64+
private SqlLogType exceptionSqlLogType = SqlLogType.NONE;
65+
66+
/**
67+
* Limit for the maximum number of rows. Ignored unless this value is greater than 0.
68+
*/
69+
private int maxRows = 0;
70+
/**
71+
* Hint to the number of rows that should be fetched. Ignored unless this value is
72+
* greater than 0.
73+
*/
74+
private int fetchSize = 0;
75+
/**
76+
* Number of seconds the driver will wait for a <code>Statement</code> object to
77+
* execute. Ignored unless this value is greater than 0.
78+
*/
79+
private int queryTimeout = 0;
80+
/**
81+
* Size in executing <code>PreparedStatement#addBatch()</code>. Regarded as 1 unless
82+
* this value is greater than 1.
83+
*/
84+
private int batchSize = 0;
85+
5986
public DialectType getDialect() {
6087
return dialect;
6188
}
@@ -88,12 +115,58 @@ public void setExceptionTranslationEnabled(boolean exceptionTranslationEnabled)
88115
this.exceptionTranslationEnabled = exceptionTranslationEnabled;
89116
}
90117

91-
public DomaConfigBuilder initializeDomaConfigBuilder() {
92-
return new DomaConfigBuilder()
93-
.dialect(dialect.create())
94-
.sqlFileRepository(sqlFileRepository.create())
95-
.naming(naming.naming());
96-
}
118+
public String getDataSourceName() {
119+
return dataSourceName;
120+
}
121+
122+
public void setDataSourceName(String dataSourceName) {
123+
this.dataSourceName = dataSourceName;
124+
}
125+
126+
public SqlLogType getExceptionSqlLogType() {
127+
return exceptionSqlLogType;
128+
}
129+
130+
public void setExceptionSqlLogType(SqlLogType exceptionSqlLogType) {
131+
this.exceptionSqlLogType = exceptionSqlLogType;
132+
}
133+
134+
public int getMaxRows() {
135+
return maxRows;
136+
}
137+
138+
public void setMaxRows(int maxRows) {
139+
this.maxRows = maxRows;
140+
}
141+
142+
public int getFetchSize() {
143+
return fetchSize;
144+
}
145+
146+
public void setFetchSize(int fetchSize) {
147+
this.fetchSize = fetchSize;
148+
}
149+
150+
public int getQueryTimeout() {
151+
return queryTimeout;
152+
}
153+
154+
public void setQueryTimeout(int queryTimeout) {
155+
this.queryTimeout = queryTimeout;
156+
}
157+
158+
public int getBatchSize() {
159+
return batchSize;
160+
}
161+
162+
public void setBatchSize(int batchSize) {
163+
this.batchSize = batchSize;
164+
}
165+
166+
public DomaConfigBuilder initializeDomaConfigBuilder() {
167+
return new DomaConfigBuilder().dialect(dialect.create())
168+
.sqlFileRepository(sqlFileRepository.create()).naming(naming.naming());
169+
}
97170

98171
public static enum DialectType {
99172
STANDARD(StandardDialect::new), SQLITE(SqliteDialect::new), DB2(Db2Dialect::new), MSSQL(
@@ -148,6 +221,10 @@ public Naming naming() {
148221
public String toString() {
149222
return "DomaProperties{" + "dialect=" + dialect + ", sqlFileRepository="
150223
+ sqlFileRepository + ", naming=" + naming
151-
+ ", exceptionTranslationEnabled=" + exceptionTranslationEnabled + '}';
224+
+ ", exceptionTranslationEnabled=" + exceptionTranslationEnabled
225+
+ ", dataSourceName='" + dataSourceName + '\'' + ", exceptionSqlLogType="
226+
+ exceptionSqlLogType + ", maxRows=" + maxRows + ", fetchSize="
227+
+ fetchSize + ", queryTimeout=" + queryTimeout + ", batchSize="
228+
+ batchSize + '}';
152229
}
153230
}

0 commit comments

Comments
 (0)