@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incrementer = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }
type = databaseType != null ? DatabaseType.valueOf(databaseType.toUpperCase()) : DatabaseType .fromMetaData(dataSource);
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); if (jdbcOperations == null) { jdbcOperations = new JdbcTemplate(dataSource); } if (incrementerFactory == null) { incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); } if (databaseType == null) { databaseType = DatabaseType.fromMetaData(dataSource).name(); logger.info("No database type set, using meta data indicating: " + databaseType); } if (lobHandler == null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) { lobHandler = new DefaultLobHandler(); } if(serializer == null) { Jackson2ExecutionContextStringSerializer defaultSerializer = new Jackson2ExecutionContextStringSerializer(); serializer = defaultSerializer; } Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); if(lobType != null) { Assert.isTrue(isValidTypes(lobType), "lobType must be a value from the java.sql.Types class"); } super.afterPropertiesSet(); }
@Autowired public void setDataSource(DataSource dataSource) throws Exception { this.dataSource = dataSource; this.jdbcTemplate = new JdbcTemplate(dataSource); databaseType = DatabaseType.fromMetaData(dataSource); }
private int determineClobTypeToUse(String databaseType) throws Exception { if(lobType != null) { return lobType; } else { if (SYBASE == DatabaseType.valueOf(databaseType.toUpperCase())) { return Types.LONGVARCHAR; } else { return Types.CLOB; } } }
@Override protected void initialize() throws DataAccessException { super.initialize(); if (enabled) { String platform; try { platform = DatabaseType.fromMetaData(dataSource).toString().toLowerCase(); if ("hsql".equals(platform)) platform = "hsqldb"; if ("postgres".equals(platform)) platform = "postgresql"; ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(resourceLoader.getResource(REGISTRY_SCHEMA_LOCATION.replace("@@platform@@", platform))); populator.setContinueOnError(true); DatabasePopulatorUtils.execute(populator, dataSource); } catch (MetaDataAccessException e) { // @PostConstruct is not supposed to throw checked exceptions throw new DataRetrievalFailureException("Could not retrieve ", e); } } } }
databaseProductName = JdbcUtils.commonDatabaseName(databaseProductName); return fromProductName(databaseProductName);
@Test public void testH2() throws Exception { DataSource dataSource = DatabaseTypeTestUtils.getDataSource(org.h2.Driver.class, "jdbc:h2:file:./build/data/sample"); assertEquals(DatabaseType.H2, DatabaseType.fromMetaData(dataSource)); dataSource.getConnection(); }
@Override public DataFieldMaxValueIncrementer getIncrementer(String incrementerType, String incrementerName) { DatabaseType databaseType = DatabaseType.valueOf(incrementerType.toUpperCase());
@Test(expected = IllegalArgumentException.class) public void testInvalidProductName() { fromProductName("bad product name"); }
@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incrementer = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }
public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); jdbcTemplate = new SimpleJdbcTemplate(dataSource); if (incrementerFactory == null) { incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); } if (databaseType == null) { databaseType = DatabaseType.fromMetaData(dataSource).name(); logger.info("No database type set, using meta data indicating: " + databaseType); } if (lobHandler == null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) { lobHandler = new OracleLobHandler(); } Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); super.afterPropertiesSet(); }
@Test public void testFromMetaDataForDB2ZOS() throws Exception { DataSource oldDs = DatabaseTypeTestUtils.getMockDataSource("DB2", "DSN08015"); assertEquals(DB2ZOS, DatabaseType.fromMetaData(oldDs)); DataSource newDs = DatabaseTypeTestUtils.getMockDataSource("DB2 for DB2 UDB for z/OS", "DSN08015"); assertEquals(DB2ZOS, DatabaseType.fromMetaData(newDs)); }
type = databaseType != null ? DatabaseType.valueOf(databaseType.toUpperCase()) : DatabaseType .fromMetaData(dataSource);
private int determineClobTypeToUse(String databaseType) { if (DatabaseType.SYBASE == DatabaseType.valueOf(databaseType.toUpperCase())) { return Types.LONGVARCHAR; } else { return Types.CLOB; } }
@Test public void testFromProductName() { assertEquals(DERBY, fromProductName("Apache Derby")); assertEquals(DB2, fromProductName("DB2")); assertEquals(DB2VSE, fromProductName("DB2VSE")); assertEquals(DB2ZOS, fromProductName("DB2ZOS")); assertEquals(DB2AS400, fromProductName("DB2AS400")); assertEquals(HSQL, fromProductName("HSQL Database Engine")); assertEquals(SQLSERVER, fromProductName("Microsoft SQL Server")); assertEquals(MYSQL, fromProductName("MySQL")); assertEquals(ORACLE, fromProductName("Oracle")); assertEquals(POSTGRES, fromProductName("PostgreSQL")); assertEquals(SYBASE, fromProductName("Sybase")); assertEquals(SQLITE, fromProductName("SQLite")); }
@Override public void afterPropertiesSet() throws Exception { DataFieldMaxValueIncrementerFactory factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); this.incremeter = factory.getIncrementer(DatabaseType.fromMetaData(dataSource).name(), tablePrefix + "JOB_SEQ"); }