Skip to content

Commit

Permalink
Merge branch 'gh-22'
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Jul 26, 2017
2 parents ad3db9a + d1c639e commit 7198a19
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.seasar.doma.boot.autoconfigure;

import javax.sql.DataSource;

import org.seasar.doma.jdbc.Config;
import org.seasar.doma.jdbc.EntityListenerProvider;
import org.seasar.doma.jdbc.Naming;
Expand All @@ -26,17 +28,12 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;

import javax.sql.DataSource;

import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;

/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
* Auto-configuration} for Doma.
Expand Down Expand Up @@ -91,11 +88,10 @@ public DomaConfigBuilder domaConfigBuilder() {

@Bean
@ConditionalOnMissingBean(Config.class)
@ConfigurationProperties(prefix = DOMA_PREFIX)
public DomaConfig config(DataSource dataSource, Dialect dialect,
SqlFileRepository sqlFileRepository, Naming naming,
EntityListenerProvider entityListenerProvider,
DomaConfigBuilder domaConfigBuilder) {
DomaConfigBuilder domaConfigBuilder, DomaProperties domaProperties) {
if (domaConfigBuilder.dataSource() == null) {
domaConfigBuilder.dataSource(dataSource);
}
Expand All @@ -111,7 +107,7 @@ public DomaConfig config(DataSource dataSource, Dialect dialect,
if (domaConfigBuilder.entityListenerProvider() == null) {
domaConfigBuilder.entityListenerProvider(entityListenerProvider);
}
return new DomaConfig(domaConfigBuilder);
return domaConfigBuilder.build(domaProperties);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,17 @@
*/
package org.seasar.doma.boot.autoconfigure;

import javax.sql.DataSource;

import org.seasar.doma.jdbc.*;
import org.seasar.doma.jdbc.dialect.Dialect;

import javax.sql.DataSource;

/**
* {@link Config} implementation used in doma-spring-boot.
*
* @author Toshiaki Maki
*/
public class DomaConfig implements Config {
/**
* Datasource name.
*/
private String dataSourceName = Config.class.getName();

/**
* Type of SQL log in the exception.
*/
private SqlLogType exceptionSqlLogType = SqlLogType.NONE;

/**
* Limit for the maximum number of rows. Ignored unless this value is greater than 0.
*/
private int maxRows = 0;
/**
* Hint to the number of rows that should be fetched. Ignored unless this value is
* greater than 0.
*/
private int fetchSize = 0;
/**
* Number of seconds the driver will wait for a <code>Statement</code> object to
* execute. Ignored unless this value is greater than 0.
*/
private int queryTimeout = 0;
/**
* Size in executing <code>PreparedStatement#addBatch()</code>. Regarded as 1 unless
* this value is greater than 1.
*/
private int batchSize = 0;

private final DataSource dataSource;
private final Dialect dialect;
Expand All @@ -69,8 +40,9 @@ public class DomaConfig implements Config {
private final MapKeyNaming mapKeyNaming;
private final Commenter commenter;
private final EntityListenerProvider entityListenerProvider;
private final DomaProperties domaProperties;

public DomaConfig(DomaConfigBuilder builder) {
public DomaConfig(DomaConfigBuilder builder, DomaProperties domaProperties) {
this.dataSource = builder.dataSource();
this.dialect = builder.dialect();
this.jdbcLogger = builder.jdbcLogger();
Expand All @@ -84,6 +56,7 @@ public DomaConfig(DomaConfigBuilder builder) {
this.mapKeyNaming = builder.mapKeyNaming();
this.commenter = builder.commenter();
this.entityListenerProvider = builder.entityListenerProvider();
this.domaProperties = domaProperties;
}

@Override
Expand All @@ -98,11 +71,7 @@ public Dialect getDialect() {

@Override
public String getDataSourceName() {
return this.dataSourceName;
}

public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
return this.domaProperties.getDataSourceName();
}

@Override
Expand Down Expand Up @@ -135,13 +104,9 @@ public QueryImplementors getQueryImplementors() {
return this.queryImplementors;
}

public void setExceptionSqlLogType(SqlLogType exceptionSqlLogType) {
this.exceptionSqlLogType = exceptionSqlLogType;
}

@Override
public SqlLogType getExceptionSqlLogType() {
return this.exceptionSqlLogType;
return this.domaProperties.getExceptionSqlLogType();
}

@Override
Expand All @@ -166,42 +131,39 @@ public Commenter getCommenter() {

@Override
public int getMaxRows() {
return this.maxRows;
}

public void setMaxRows(int maxRows) {
this.maxRows = maxRows;
return this.domaProperties.getMaxRows();
}

@Override
public int getFetchSize() {
return this.fetchSize;
}

public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
return this.domaProperties.getFetchSize();
}

@Override
public int getQueryTimeout() {
return this.queryTimeout;
}

public void setQueryTimeout(int queryTimeout) {
this.queryTimeout = queryTimeout;
return this.domaProperties.getQueryTimeout();
}

@Override
public int getBatchSize() {
return this.batchSize;
}

public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
return this.domaProperties.getBatchSize();
}

@Override
public EntityListenerProvider getEntityListenerProvider() {
return this.entityListenerProvider;
}

@Override
public String toString() {
return "DomaConfig{" + "dataSource=" + dataSource + ", dialect=" + dialect
+ ", jdbcLogger=" + jdbcLogger + ", sqlFileRepository="
+ sqlFileRepository + ", requiresNewController=" + requiresNewController
+ ", classHelper=" + classHelper + ", commandImplementors="
+ commandImplementors + ", queryImplementors=" + queryImplementors
+ ", unknownColumnHandler=" + unknownColumnHandler + ", naming=" + naming
+ ", mapKeyNaming=" + mapKeyNaming + ", commenter=" + commenter
+ ", entityListenerProvider=" + entityListenerProvider
+ ", domaProperties=" + domaProperties + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.seasar.doma.boot.autoconfigure;

import javax.sql.DataSource;

import org.seasar.doma.jdbc.*;
import org.seasar.doma.jdbc.dialect.Dialect;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;

import javax.sql.DataSource;

/**
* Builder to create {@link DomaConfig}.
*
Expand Down Expand Up @@ -179,7 +179,7 @@ public DomaConfigBuilder entityListenerProvider(
return this;
}

public DomaConfig build() {
return new DomaConfig(this);
public DomaConfig build(DomaProperties domaProperties) {
return new DomaConfig(this, domaProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
*/
package org.seasar.doma.boot.autoconfigure;

import org.seasar.doma.jdbc.GreedyCacheSqlFileRepository;
import org.seasar.doma.jdbc.Naming;
import org.seasar.doma.jdbc.NoCacheSqlFileRepository;
import org.seasar.doma.jdbc.SqlFileRepository;
import org.seasar.doma.jdbc.dialect.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;

import java.util.function.Supplier;

import static org.seasar.doma.boot.autoconfigure.DomaProperties.DOMA_PREFIX;
import org.seasar.doma.jdbc.*;
import org.seasar.doma.jdbc.dialect.*;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* {@link ConfigurationProperties} for configuring Doma.
Expand Down Expand Up @@ -56,6 +53,36 @@ public class DomaProperties {
*/
private boolean exceptionTranslationEnabled = true;

/**
* Datasource name.
*/
private String dataSourceName = Config.class.getName();

/**
* Type of SQL log in the exception.
*/
private SqlLogType exceptionSqlLogType = SqlLogType.NONE;

/**
* Limit for the maximum number of rows. Ignored unless this value is greater than 0.
*/
private int maxRows = 0;
/**
* Hint to the number of rows that should be fetched. Ignored unless this value is
* greater than 0.
*/
private int fetchSize = 0;
/**
* Number of seconds the driver will wait for a <code>Statement</code> object to
* execute. Ignored unless this value is greater than 0.
*/
private int queryTimeout = 0;
/**
* Size in executing <code>PreparedStatement#addBatch()</code>. Regarded as 1 unless
* this value is greater than 1.
*/
private int batchSize = 0;

public DialectType getDialect() {
return dialect;
}
Expand Down Expand Up @@ -88,12 +115,58 @@ public void setExceptionTranslationEnabled(boolean exceptionTranslationEnabled)
this.exceptionTranslationEnabled = exceptionTranslationEnabled;
}

public DomaConfigBuilder initializeDomaConfigBuilder() {
return new DomaConfigBuilder()
.dialect(dialect.create())
.sqlFileRepository(sqlFileRepository.create())
.naming(naming.naming());
}
public String getDataSourceName() {
return dataSourceName;
}

public void setDataSourceName(String dataSourceName) {
this.dataSourceName = dataSourceName;
}

public SqlLogType getExceptionSqlLogType() {
return exceptionSqlLogType;
}

public void setExceptionSqlLogType(SqlLogType exceptionSqlLogType) {
this.exceptionSqlLogType = exceptionSqlLogType;
}

public int getMaxRows() {
return maxRows;
}

public void setMaxRows(int maxRows) {
this.maxRows = maxRows;
}

public int getFetchSize() {
return fetchSize;
}

public void setFetchSize(int fetchSize) {
this.fetchSize = fetchSize;
}

public int getQueryTimeout() {
return queryTimeout;
}

public void setQueryTimeout(int queryTimeout) {
this.queryTimeout = queryTimeout;
}

public int getBatchSize() {
return batchSize;
}

public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
}

public DomaConfigBuilder initializeDomaConfigBuilder() {
return new DomaConfigBuilder().dialect(dialect.create())
.sqlFileRepository(sqlFileRepository.create()).naming(naming.naming());
}

public static enum DialectType {
STANDARD(StandardDialect::new), SQLITE(SqliteDialect::new), DB2(Db2Dialect::new), MSSQL(
Expand Down Expand Up @@ -148,6 +221,10 @@ public Naming naming() {
public String toString() {
return "DomaProperties{" + "dialect=" + dialect + ", sqlFileRepository="
+ sqlFileRepository + ", naming=" + naming
+ ", exceptionTranslationEnabled=" + exceptionTranslationEnabled + '}';
+ ", exceptionTranslationEnabled=" + exceptionTranslationEnabled
+ ", dataSourceName='" + dataSourceName + '\'' + ", exceptionSqlLogType="
+ exceptionSqlLogType + ", maxRows=" + maxRows + ", fetchSize="
+ fetchSize + ", queryTimeout=" + queryTimeout + ", batchSize="
+ batchSize + '}';
}
}

0 comments on commit 7198a19

Please sign in to comment.