Search in sources :

Example 1 with PostgresDialect

use of org.seasar.doma.jdbc.dialect.PostgresDialect in project doma-spring-boot by domaframework.

the class DomaAutoConfiguration method dialect.

@Bean
@ConditionalOnMissingBean
public Dialect dialect(Environment environment) {
    DialectType dialectType = domaProperties.getDialect();
    if (dialectType != null) {
        return dialectType.create();
    }
    String url = environment.getProperty("spring.datasource.url");
    if (url != null) {
        DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(url);
        switch(databaseDriver) {
            case DB2:
                return new Db2Dialect();
            case H2:
                return new H2Dialect();
            case HSQLDB:
                return new HsqldbDialect();
            case SQLSERVER:
            case JTDS:
                return new MssqlDialect();
            case MYSQL:
                return new MysqlDialect();
            case ORACLE:
                return new OracleDialect();
            case POSTGRESQL:
                return new PostgresDialect();
            case SQLITE:
                return new SqliteDialect();
            default:
                break;
        }
    }
    if (logger.isWarnEnabled()) {
        logger.warn("StandardDialect was selected because no explicit configuration and it is not possible to guess from 'spring.datasource.url property'");
    }
    return new StandardDialect();
}
Also used : HsqldbDialect(org.seasar.doma.jdbc.dialect.HsqldbDialect) MysqlDialect(org.seasar.doma.jdbc.dialect.MysqlDialect) H2Dialect(org.seasar.doma.jdbc.dialect.H2Dialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) DialectType(org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType) DatabaseDriver(org.springframework.boot.jdbc.DatabaseDriver) SqliteDialect(org.seasar.doma.jdbc.dialect.SqliteDialect) StandardDialect(org.seasar.doma.jdbc.dialect.StandardDialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with PostgresDialect

use of org.seasar.doma.jdbc.dialect.PostgresDialect in project doma by domaframework.

the class BuiltinIdentityIdGeneratorTest method test_identityReservationSql.

@Test
public void test_identityReservationSql() {
    MockConfig config = new MockConfig();
    config.setDialect(new PostgresDialect());
    MockResultSet resultSet = config.dataSource.connection.preparedStatement.resultSet;
    resultSet.rows.add(new RowData(11L));
    resultSet.rows.add(new RowData(12L));
    resultSet.rows.add(new RowData(13L));
    EntityType<IdGeneratedEmp> entityType = _IdGeneratedEmp.getSingletonInternal();
    BuiltinIdentityIdGenerator identityIdGenerator = new BuiltinIdentityIdGenerator();
    IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, entityType, new ReservedIdProvider(config, entityType, 3));
    Long value = identityIdGenerator.generatePreInsert(idGenerationConfig);
    assertEquals(new Long(11), value);
    assertEquals("select nextval(pg_catalog.pg_get_serial_sequence('\"CATA\".\"EMP\"', 'id')) from generate_series(1, 3)", config.dataSource.connection.preparedStatement.sql);
    value = identityIdGenerator.generatePreInsert(idGenerationConfig);
    assertEquals(new Long(12), value);
    value = identityIdGenerator.generatePreInsert(idGenerationConfig);
    assertEquals(new Long(13), value);
    try {
        identityIdGenerator.generatePreInsert(idGenerationConfig);
        fail();
    } catch (IllegalStateException e) {
        System.out.println(e.getMessage());
    }
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) example.entity._IdGeneratedEmp(example.entity._IdGeneratedEmp) IdGeneratedEmp(example.entity.IdGeneratedEmp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Example 3 with PostgresDialect

use of org.seasar.doma.jdbc.dialect.PostgresDialect in project doma by domaframework.

the class BuiltinTableIdGeneratorTest method test.

@Test
public void test() {
    MockConfig config = new MockConfig();
    config.setDialect(new PostgresDialect());
    MockConnection connection = new MockConnection();
    MockConnection connection2 = new MockConnection();
    MockResultSet resultSet2 = connection2.preparedStatement.resultSet;
    resultSet2.rows.add(new RowData(11L));
    final LinkedList<MockConnection> connections = new LinkedList<>();
    connections.add(connection);
    connections.add(connection2);
    config.dataSource = new MockDataSource() {

        @Override
        public Connection getConnection() {
            return connections.pop();
        }
    };
    BuiltinTableIdGenerator idGenerator = new BuiltinTableIdGenerator();
    idGenerator.setQualifiedTableName("aaa");
    idGenerator.setPkColumnName("PK");
    idGenerator.setPkColumnValue("EMP_ID");
    idGenerator.setValueColumnName("VALUE");
    idGenerator.setInitialValue(1);
    idGenerator.setAllocationSize(1);
    idGenerator.initialize();
    IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
    Long value = idGenerator.generatePreInsert(idGenerationConfig);
    assertEquals(new Long(10), value);
    assertEquals("update aaa set VALUE = VALUE + ? where PK = ?", connection.preparedStatement.sql);
    assertEquals(2, connection.preparedStatement.bindValues.size());
    assertEquals("select VALUE from aaa where PK = ?", connection2.preparedStatement.sql);
    assertEquals(1, connection2.preparedStatement.bindValues.size());
}
Also used : Connection(java.sql.Connection) MockConnection(org.seasar.doma.internal.jdbc.mock.MockConnection) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) MockConnection(org.seasar.doma.internal.jdbc.mock.MockConnection) LinkedList(java.util.LinkedList) RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Example 4 with PostgresDialect

use of org.seasar.doma.jdbc.dialect.PostgresDialect in project doma by domaframework.

the class GreedyCacheSqlFileRepositoryTest method testGetSqlFile_postgres.

@Test
public void testGetSqlFile_postgres() {
    PostgresDialect dialect = new PostgresDialect();
    String path = "META-INF/" + getClass().getName().replace(".", "/") + ".sql";
    GreedyCacheSqlFileRepository repository = new GreedyCacheSqlFileRepository();
    SqlFile sqlFile = repository.getSqlFile(method, path, dialect);
    assertEquals(path, sqlFile.getPath());
}
Also used : PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Example 5 with PostgresDialect

use of org.seasar.doma.jdbc.dialect.PostgresDialect in project doma by domaframework.

the class BuiltinIdentityIdGeneratorTest method test_identitySelectSql.

@Test
public void test_identitySelectSql() {
    MockConfig config = new MockConfig();
    config.setDialect(new PostgresDialect());
    MockResultSet resultSet = config.dataSource.connection.preparedStatement.resultSet;
    resultSet.rows.add(new RowData(11L));
    BuiltinIdentityIdGenerator identityIdGenerator = new BuiltinIdentityIdGenerator();
    IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
    Long value = identityIdGenerator.generatePostInsert(idGenerationConfig, config.dataSource.connection.preparedStatement);
    assertEquals(new Long(11), value);
    assertEquals("select currval(pg_catalog.pg_get_serial_sequence('\"CATA\".\"EMP\"', 'id'))", config.dataSource.connection.preparedStatement.sql);
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Aggregations

PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)7 Test (org.junit.jupiter.api.Test)6 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)5 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)4 RowData (org.seasar.doma.internal.jdbc.mock.RowData)4 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)2 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)2 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)2 IdGeneratedEmp (example.entity.IdGeneratedEmp)1 example.entity._IdGeneratedEmp (example.entity._IdGeneratedEmp)1 Connection (java.sql.Connection)1 LinkedList (java.util.LinkedList)1 DialectType (org.seasar.doma.boot.autoconfigure.DomaProperties.DialectType)1 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)1 MockDataSource (org.seasar.doma.internal.jdbc.mock.MockDataSource)1 Dept_ (org.seasar.doma.jdbc.criteria.entity.Dept_)1 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)1 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)1 Dialect (org.seasar.doma.jdbc.dialect.Dialect)1 H2Dialect (org.seasar.doma.jdbc.dialect.H2Dialect)1