/** * Get a {@link PagingQueryProvider} instance using the provided properties and appropriate for * the given database type. * * @see FactoryBean#getObject() */ @Override public PagingQueryProvider getObject() throws Exception { DatabaseType type; try { type = databaseType != null ? DatabaseType.valueOf(databaseType.toUpperCase()) : DatabaseType.fromMetaData(dataSource); } catch (MetaDataAccessException e) { throw new IllegalArgumentException( "Could not inspect meta data for database type. You have to supply it explicitly.", e); } AbstractSqlPagingQueryProvider provider = providers.get(type); Assert.state( provider != null, "Should not happen: missing PagingQueryProvider for DatabaseType=" + type); provider.setFromClause(fromClause); provider.setWhereClause(whereClause); provider.setSortKeys(sortKeys); if (StringUtils.hasText(selectClause)) { provider.setSelectClause(selectClause); } if (StringUtils.hasText(groupClause)) { provider.setGroupClause(groupClause); } provider.init(dataSource); return provider; }
@PostConstruct protected void initialize() throws Exception { String platform = DatabaseType.fromMetaData(this.dataSource).toString().toLowerCase(); if ("hsql".equals(platform)) { platform = "hsqldb"; } ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript( this.resourceLoader.getResource(this.schemaLocation.replace("@@platform@@", platform))); populator.setContinueOnError(true); DatabasePopulatorUtils.execute(populator, this.dataSource); }
static { nameMap = new HashMap<String, DatabaseType>(); for (DatabaseType type : values()) { nameMap.put(type.getProductName(), type); } }