org.springframework.jdbc.support.MetaDataAccessException Java Examples
The following examples show how to use
org.springframework.jdbc.support.MetaDataAccessException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CasbinAutoConfiguration.java From casbin-spring-boot-starter with Apache License 2.0 | 7 votes |
/** * 获取当前使用数据库类型 */ private static String getDatabaseName(DataSource dataSource) { try { String productName = JdbcUtils. commonDatabaseName(JdbcUtils.extractDatabaseMetaData( dataSource, "getDatabaseProductName" ).toString()); DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName); if (databaseDriver == DatabaseDriver.UNKNOWN) { throw new IllegalStateException("Unable to detect database type"); } return databaseDriver.getId(); } catch (MetaDataAccessException ex) { throw new IllegalStateException("Unable to detect database type", ex); } }
Example #2
Source File: SqlPagingQueryProviderFactoryBean.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * 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); } provider.init(dataSource); return provider; }
Example #3
Source File: MolgenisVersionService.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private boolean versionTableExist() { try { return (boolean) JdbcUtils.extractDatabaseMetaData( dataSource, dbmd -> { ResultSet tables = dbmd.getTables(null, null, "Version", new String[] {"TABLE"}); return tables.first(); }); } catch (MetaDataAccessException e) { return false; } }
Example #4
Source File: ExecutionQueueRepositoryImpl.java From score with Apache License 2.0 | 5 votes |
private String getDatabaseProductName() { String dbms = ""; try { dbms = (String) JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName"); logger.info("Database product name: " + dbms); } catch (MetaDataAccessException e) { logger.warn("Database type could not be determined!", e); } return dbms; }
Example #5
Source File: BusinessObjectMetaDataDaoJdbc.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
public FieldMetaData getFieldMetaData(Class businessObjectClass, String propertyName) { try { return (FieldMetaData) JdbcUtils.extractDatabaseMetaData(getDataSource(), new FieldMetaDataImpl(businessObjectClass, propertyName)); } catch (MetaDataAccessException e) { throw new RuntimeException(new StringBuffer("BusinessObjectMetaDataDaoJdbc unable to getFieldMetaData for businessObjectClass ").append(businessObjectClass).append(" propertyName ").append(propertyName).toString(), e); } }
Example #6
Source File: JdbcHttpSessionConfiguration.java From spring-session with Apache License 2.0 | 5 votes |
private static boolean requiresTemporaryLob(DataSource dataSource) { try { String productName = JdbcUtils.extractDatabaseMetaData(dataSource, "getDatabaseProductName"); return "Oracle".equalsIgnoreCase(JdbcUtils.commonDatabaseName(productName)); } catch (MetaDataAccessException ex) { return false; } }
Example #7
Source File: TestDBUtils.java From spring-cloud-task with Apache License 2.0 | 5 votes |
/** * Creates a incrementer for the DataSource. * @param dataSource the datasource that the incrementer will use to record current * id. * @return a DataFieldMaxValueIncrementer object. */ public static DataFieldMaxValueIncrementer getIncrementer(DataSource dataSource) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory( dataSource); String databaseType = null; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } return incrementerFactory.getIncrementer(databaseType, "TASK_SEQ"); }
Example #8
Source File: TaskExecutionDaoFactoryBean.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private void buildTaskExecutionDao(DataSource dataSource) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory( dataSource); this.dao = new JdbcTaskExecutionDao(dataSource, this.tablePrefix); String databaseType; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } ((JdbcTaskExecutionDao) this.dao).setTaskIncrementer(incrementerFactory .getIncrementer(databaseType, this.tablePrefix + "SEQ")); }
Example #9
Source File: TaskRepositoryInitializer.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private String getDatabaseType(DataSource dataSource) { try { return JdbcUtils .commonDatabaseName(DatabaseType.fromMetaData(dataSource).toString()) .toLowerCase(); } catch (MetaDataAccessException ex) { throw new IllegalStateException("Unable to detect database type", ex); } }
Example #10
Source File: SqlPagingQueryProviderFactoryBean.java From spring-cloud-task with Apache License 2.0 | 5 votes |
/** * 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 = this.databaseType != null ? DatabaseType.valueOf(this.databaseType.toUpperCase()) : DatabaseType.fromMetaData(this.dataSource); } catch (MetaDataAccessException e) { throw new IllegalArgumentException( "Could not inspect meta data for database type. You have to supply it explicitly.", e); } AbstractSqlPagingQueryProvider provider = this.providers.get(type); Assert.state(provider != null, "Should not happen: missing PagingQueryProvider for DatabaseType=" + type); provider.setFromClause(this.fromClause); provider.setWhereClause(this.whereClause); provider.setSortKeys(this.sortKeys); if (StringUtils.hasText(this.selectClause)) { provider.setSelectClause(this.selectClause); } provider.init(this.dataSource); return provider; }
Example #11
Source File: JobDependencies.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Bean public DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao(DataSource dataSource) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); String databaseType; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } return new JdbcDataflowTaskExecutionMetadataDao(dataSource, incrementerFactory.getIncrementer(databaseType, "task_execution_metadata_seq")); }
Example #12
Source File: TaskServiceDependencies.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Bean public DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao(DataSource dataSource, ApplicationContext context) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); String databaseType; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } return new JdbcDataflowTaskExecutionMetadataDao(dataSource, incrementerFactory.getIncrementer(databaseType, "task_execution_metadata_seq")); }
Example #13
Source File: TestDependencies.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Bean public DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao(DataSource dataSource, ApplicationContext context) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); String databaseType; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } return new JdbcDataflowTaskExecutionMetadataDao(dataSource, incrementerFactory.getIncrementer(databaseType, "task_execution_metadata_seq")); }
Example #14
Source File: DataFlowServerConfiguration.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Bean DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao(DataSource dataSource) { DataFieldMaxValueIncrementerFactory incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); String databaseType; try { databaseType = DatabaseType.fromMetaData(dataSource).name(); } catch (MetaDataAccessException e) { throw new IllegalStateException(e); } return new JdbcDataflowTaskExecutionMetadataDao(dataSource, incrementerFactory.getIncrementer(databaseType, "task_execution_metadata_seq")); }
Example #15
Source File: DataFlowFlywayConfigurationCustomizer.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
private DatabaseDriver getDatabaseDriver(DataSource dataSource) { // copied from boot's flyway auto-config to get matching db vendor id try { String url = JdbcUtils.extractDatabaseMetaData(dataSource, "getURL"); return DatabaseDriver.fromJdbcUrl(url); } catch (MetaDataAccessException ex) { throw new IllegalStateException(ex); } }
Example #16
Source File: SqlPagingQueryProviderFactoryBean.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
/** * 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); } provider.init(dataSource); return provider; }
Example #17
Source File: DataflowRdbmsInitializer.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
private String getDatabaseType(DataSource dataSource) { try { return DatabaseType.fromMetaData(dataSource).toString().toLowerCase(); } catch (MetaDataAccessException ex) { throw new IllegalStateException("Unable to detect database type", ex); } }
Example #18
Source File: SkipperFlywayConfigurationCustomizer.java From spring-cloud-skipper with Apache License 2.0 | 5 votes |
private DatabaseDriver getDatabaseDriver(DataSource dataSource) { // copied from boot's flyway auto-config to get matching db vendor id try { String url = JdbcUtils.extractDatabaseMetaData(dataSource, "getURL"); return DatabaseDriver.fromJdbcUrl(url); } catch (MetaDataAccessException ex) { throw new IllegalStateException(ex); } }
Example #19
Source File: TableMetaDataProviderFactory.java From spring-analysis-note with MIT License | 4 votes |
/** * Create a {@link TableMetaDataProvider} based on the database meta-data. * @param dataSource used to retrieve meta-data * @param context the class that holds configuration and meta-data * @return instance of the TableMetaDataProvider implementation to be used */ public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) { try { return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleTableMetaDataProvider( databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } else if ("HSQL Database Engine".equals(databaseProductName)) { provider = new HsqlTableMetaDataProvider(databaseMetaData); } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database meta-data", ex); } }
Example #20
Source File: LocalDataSourceJobStore.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { // Absolutely needs thread-bound DataSource to initialize. this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource(); if (this.dataSource == null) { throw new SchedulerConfigException( "No local DataSource found for configuration - " + "'dataSource' property must be set on SchedulerFactoryBean"); } // Configure transactional connection settings for Quartz. setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName()); setDontSetAutoCommitFalse(true); // Register transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // Non-transactional DataSource is optional: fall back to default // DataSource if not explicitly specified. DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource(); final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource); // Configure non-transactional connection settings for Quartz. setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName()); // Register non-transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( NON_TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Always return a non-transactional Connection. return nonTxDataSourceToUse.getConnection(); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // No, if HSQL is the platform, we really don't want to use locks... try { String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString(); productName = JdbcUtils.commonDatabaseName(productName); if (productName != null && productName.toLowerCase().contains("hsql")) { setUseDBLocks(false); setLockHandler(new SimpleSemaphore()); } } catch (MetaDataAccessException ex) { logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken."); } super.initialize(loadHelper, signaler); }
Example #21
Source File: TableMetaDataProviderFactory.java From effectivejava with Apache License 2.0 | 4 votes |
/** * Create a TableMetaDataProvider based on the database metedata * @param dataSource used to retrieve metedata * @param context the class that holds configuration and metedata * @param nativeJdbcExtractor the NativeJdbcExtractor to be used * @return instance of the TableMetaDataProvider implementation to be used */ public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, final TableMetaDataContext context, final NativeJdbcExtractor nativeJdbcExtractor) { try { return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleTableMetaDataProvider(databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("HSQL Database Engine".equals(databaseProductName)) { provider = new HsqlTableMetaDataProvider(databaseMetaData); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (nativeJdbcExtractor != null) { provider.setNativeJdbcExtractor(nativeJdbcExtractor); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; } }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); } }
Example #22
Source File: CallMetaDataProviderFactory.java From effectivejava with Apache License 2.0 | 4 votes |
/** * Create a CallMetaDataProvider based on the database metadata * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the CallMetaDataProvider implementation to be used */ static public CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { return (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException, MetaDataAccessException { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessProcedureColumnMetaData = context.isAccessCallParameterMetaData(); if (context.isFunction()) { if (!supportedDatabaseProductsForFunctions.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for function calls " + "-- supported are: " + supportedDatabaseProductsForFunctions); } if (accessProcedureColumnMetaData) { logger.warn("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } else { if (!supportedDatabaseProductsForProcedures.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for procedure calls " + "-- supported are: " + supportedDatabaseProductsForProcedures); } if (accessProcedureColumnMetaData) { logger.warn("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } CallMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleCallMetaDataProvider(databaseMetaData); } else if ("DB2".equals(databaseProductName)) { provider = new Db2CallMetaDataProvider((databaseMetaData)); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyCallMetaDataProvider((databaseMetaData)); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresCallMetaDataProvider((databaseMetaData)); } else if ("Sybase".equals(databaseProductName)) { provider = new SybaseCallMetaDataProvider((databaseMetaData)); } else if ("Microsoft SQL Server".equals(databaseProductName)) { provider = new SqlServerCallMetaDataProvider((databaseMetaData)); } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } provider.initializeWithMetaData(databaseMetaData); if (accessProcedureColumnMetaData) { provider.initializeWithProcedureColumnMetaData( databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getProcedureName()); } return provider; } }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retreiving database metadata", ex); } }
Example #23
Source File: LocalDataSourceJobStore.java From spring-analysis-note with MIT License | 4 votes |
@Override public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { // Absolutely needs thread-bound DataSource to initialize. this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource(); if (this.dataSource == null) { throw new SchedulerConfigException("No local DataSource found for configuration - " + "'dataSource' property must be set on SchedulerFactoryBean"); } // Configure transactional connection settings for Quartz. setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName()); setDontSetAutoCommitFalse(true); // Register transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // Non-transactional DataSource is optional: fall back to default // DataSource if not explicitly specified. DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource(); final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource); // Configure non-transactional connection settings for Quartz. setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName()); // Register non-transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( NON_TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Always return a non-transactional Connection. return nonTxDataSourceToUse.getConnection(); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // No, if HSQL is the platform, we really don't want to use locks... try { String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName"); productName = JdbcUtils.commonDatabaseName(productName); if (productName != null && productName.toLowerCase().contains("hsql")) { setUseDBLocks(false); setLockHandler(new SimpleSemaphore()); } } catch (MetaDataAccessException ex) { logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken."); } super.initialize(loadHelper, signaler); }
Example #24
Source File: FieldMetaDataImpl.java From kfs with GNU Affero General Public License v3.0 | 4 votes |
public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException, MetaDataAccessException { Class workingBusinessObjectClass = businessObjectClass; String workingPropertyName = propertyName; while (workingPropertyName.contains(".")) { try { workingBusinessObjectClass = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass).getObjectReferenceDescriptorByName(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).getItemClass(); } catch (Exception e1) { LOG.debug(new StringBuffer("Unable to get property type via reference descriptor for property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" of BusinessObject class ").append(workingBusinessObjectClass).toString(), e1); try { workingBusinessObjectClass = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass).getCollectionDescriptorByName(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).getItemClass(); } catch (Exception e2) { LOG.debug(new StringBuffer("Unable to get property type via collection descriptor of property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" of BusinessObject class ").append(workingBusinessObjectClass).toString(), e2); BusinessObject businessObject = null; try { businessObject = (BusinessObject)workingBusinessObjectClass.newInstance(); } catch (Exception e3) { if (LOG.isDebugEnabled()) { LOG.debug("Unable to instantiate BusinessObject class " + workingBusinessObjectClass, e3); } return populateAndReturnNonPersistableInstance(); } try { workingBusinessObjectClass = PropertyUtils.getPropertyType(businessObject, workingPropertyName.substring(0, workingPropertyName.indexOf("."))); } catch (Exception e4) { LOG.debug(new StringBuffer("Unable to get type of property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" for BusinessObject class ").append(workingBusinessObjectClass).toString(), e4); return populateAndReturnNonPersistableInstance(); } } } if (workingBusinessObjectClass == null) { return populateAndReturnNonPersistableInstance(); } else { workingPropertyName = workingPropertyName.substring(workingPropertyName.indexOf(".") + 1); } } if (!PersistableBusinessObject.class.isAssignableFrom(workingBusinessObjectClass)) { return populateAndReturnNonPersistableInstance(); } ClassDescriptor classDescriptor = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass); if (classDescriptor == null) { return populateAndReturnNonPersistableInstance(); } tableName = classDescriptor.getFullTableName(); if (classDescriptor.getFieldDescriptorByName(workingPropertyName) == null) { return populateAndReturnNonPersistableInstance(); } columnName = classDescriptor.getFieldDescriptorByName(workingPropertyName).getColumnName(); ResultSet resultSet = databaseMetaData.getColumns(null, null, tableName, columnName); if (resultSet.next()) { dataType = resultSet.getString("TYPE_NAME"); length = resultSet.getInt("COLUMN_SIZE"); decimalPlaces = resultSet.getInt("DECIMAL_DIGITS"); encrypted = classDescriptor.getFieldDescriptorByName(workingPropertyName).getFieldConversion() instanceof OjbKualiEncryptDecryptFieldConversion; } resultSet.close(); return this; }
Example #25
Source File: CallMetaDataProviderFactory.java From java-technology-stack with MIT License | 4 votes |
/** * Create a {@link CallMetaDataProvider} based on the database meta-data. * @param dataSource the JDBC DataSource to use for retrieving meta-data * @param context the class that holds configuration and meta-data * @return instance of the CallMetaDataProvider implementation to be used */ public static CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { return (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessProcedureColumnMetaData = context.isAccessCallParameterMetaData(); if (context.isFunction()) { if (!supportedDatabaseProductsForFunctions.contains(databaseProductName)) { if (logger.isInfoEnabled()) { logger.info(databaseProductName + " is not one of the databases fully supported for function calls " + "-- supported are: " + supportedDatabaseProductsForFunctions); } if (accessProcedureColumnMetaData) { logger.info("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } else { if (!supportedDatabaseProductsForProcedures.contains(databaseProductName)) { if (logger.isInfoEnabled()) { logger.info(databaseProductName + " is not one of the databases fully supported for procedure calls " + "-- supported are: " + supportedDatabaseProductsForProcedures); } if (accessProcedureColumnMetaData) { logger.info("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } CallMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleCallMetaDataProvider(databaseMetaData); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresCallMetaDataProvider((databaseMetaData)); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyCallMetaDataProvider((databaseMetaData)); } else if ("DB2".equals(databaseProductName)) { provider = new Db2CallMetaDataProvider((databaseMetaData)); } else if ("HDB".equals(databaseProductName)) { provider = new HanaCallMetaDataProvider((databaseMetaData)); } else if ("Microsoft SQL Server".equals(databaseProductName)) { provider = new SqlServerCallMetaDataProvider((databaseMetaData)); } else if ("Sybase".equals(databaseProductName)) { provider = new SybaseCallMetaDataProvider((databaseMetaData)); } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } provider.initializeWithMetaData(databaseMetaData); if (accessProcedureColumnMetaData) { provider.initializeWithProcedureColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getProcedureName()); } return provider; }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database meta-data", ex); } }
Example #26
Source File: TableMetaDataProviderFactory.java From java-technology-stack with MIT License | 4 votes |
/** * Create a {@link TableMetaDataProvider} based on the database meta-data. * @param dataSource used to retrieve meta-data * @param context the class that holds configuration and meta-data * @return instance of the TableMetaDataProvider implementation to be used */ public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, TableMetaDataContext context) { try { return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, databaseMetaData -> { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleTableMetaDataProvider( databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } else if ("HSQL Database Engine".equals(databaseProductName)) { provider = new HsqlTableMetaDataProvider(databaseMetaData); } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database meta-data", ex); } }
Example #27
Source File: LocalDataSourceJobStore.java From java-technology-stack with MIT License | 4 votes |
@Override public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { // Absolutely needs thread-bound DataSource to initialize. this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource(); if (this.dataSource == null) { throw new SchedulerConfigException("No local DataSource found for configuration - " + "'dataSource' property must be set on SchedulerFactoryBean"); } // Configure transactional connection settings for Quartz. setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName()); setDontSetAutoCommitFalse(true); // Register transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // Non-transactional DataSource is optional: fall back to default // DataSource if not explicitly specified. DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource(); final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource); // Configure non-transactional connection settings for Quartz. setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName()); // Register non-transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( NON_TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Always return a non-transactional Connection. return nonTxDataSourceToUse.getConnection(); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // No, if HSQL is the platform, we really don't want to use locks... try { String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName"); productName = JdbcUtils.commonDatabaseName(productName); if (productName != null && productName.toLowerCase().contains("hsql")) { setUseDBLocks(false); setLockHandler(new SimpleSemaphore()); } } catch (MetaDataAccessException ex) { logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken."); } super.initialize(loadHelper, signaler); }
Example #28
Source File: LocalDataSourceJobStore.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { // Absolutely needs thread-bound DataSource to initialize. this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource(); if (this.dataSource == null) { throw new SchedulerConfigException( "No local DataSource found for configuration - " + "'dataSource' property must be set on SchedulerFactoryBean"); } // Configure transactional connection settings for Quartz. setDataSource(TX_DATA_SOURCE_PREFIX + getInstanceName()); setDontSetAutoCommitFalse(true); // Register transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // Non-transactional DataSource is optional: fall back to default // DataSource if not explicitly specified. DataSource nonTxDataSource = SchedulerFactoryBean.getConfigTimeNonTransactionalDataSource(); final DataSource nonTxDataSourceToUse = (nonTxDataSource != null ? nonTxDataSource : this.dataSource); // Configure non-transactional connection settings for Quartz. setNonManagedTXDataSource(NON_TX_DATA_SOURCE_PREFIX + getInstanceName()); // Register non-transactional ConnectionProvider for Quartz. DBConnectionManager.getInstance().addConnectionProvider( NON_TX_DATA_SOURCE_PREFIX + getInstanceName(), new ConnectionProvider() { @Override public Connection getConnection() throws SQLException { // Always return a non-transactional Connection. return nonTxDataSourceToUse.getConnection(); } @Override public void shutdown() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } /* Quartz 2.2 initialize method */ public void initialize() { // Do nothing - a Spring-managed DataSource has its own lifecycle. } } ); // No, if HSQL is the platform, we really don't want to use locks... try { String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName").toString(); productName = JdbcUtils.commonDatabaseName(productName); if (productName != null && productName.toLowerCase().contains("hsql")) { setUseDBLocks(false); setLockHandler(new SimpleSemaphore()); } } catch (MetaDataAccessException ex) { logWarnIfNonZero(1, "Could not detect database type. Assuming locks can be taken."); } super.initialize(loadHelper, signaler); }
Example #29
Source File: CallMetaDataProviderFactory.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Create a CallMetaDataProvider based on the database metadata * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @return instance of the CallMetaDataProvider implementation to be used */ static public CallMetaDataProvider createMetaDataProvider(DataSource dataSource, final CallMetaDataContext context) { try { return (CallMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException, MetaDataAccessException { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessProcedureColumnMetaData = context.isAccessCallParameterMetaData(); if (context.isFunction()) { if (!supportedDatabaseProductsForFunctions.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for function calls " + "-- supported are: " + supportedDatabaseProductsForFunctions); } if (accessProcedureColumnMetaData) { logger.warn("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } else { if (!supportedDatabaseProductsForProcedures.contains(databaseProductName)) { if (logger.isWarnEnabled()) { logger.warn(databaseProductName + " is not one of the databases fully supported for procedure calls " + "-- supported are: " + supportedDatabaseProductsForProcedures); } if (accessProcedureColumnMetaData) { logger.warn("Metadata processing disabled - you must specify all parameters explicitly"); accessProcedureColumnMetaData = false; } } } CallMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleCallMetaDataProvider(databaseMetaData); } else if ("DB2".equals(databaseProductName)) { provider = new Db2CallMetaDataProvider((databaseMetaData)); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyCallMetaDataProvider((databaseMetaData)); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresCallMetaDataProvider((databaseMetaData)); } else if ("Sybase".equals(databaseProductName)) { provider = new SybaseCallMetaDataProvider((databaseMetaData)); } else if ("Microsoft SQL Server".equals(databaseProductName)) { provider = new SqlServerCallMetaDataProvider((databaseMetaData)); } else if ("HDB".equals(databaseProductName)) { provider = new HanaCallMetaDataProvider((databaseMetaData)); } else { provider = new GenericCallMetaDataProvider(databaseMetaData); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getName()); } provider.initializeWithMetaData(databaseMetaData); if (accessProcedureColumnMetaData) { provider.initializeWithProcedureColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getProcedureName()); } return provider; } }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); } }
Example #30
Source File: TableMetaDataProviderFactory.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Create a TableMetaDataProvider based on the database metadata. * @param dataSource used to retrieve metadata * @param context the class that holds configuration and metadata * @param nativeJdbcExtractor the NativeJdbcExtractor to be used * @return instance of the TableMetaDataProvider implementation to be used */ public static TableMetaDataProvider createMetaDataProvider(DataSource dataSource, final TableMetaDataContext context, final NativeJdbcExtractor nativeJdbcExtractor) { try { return (TableMetaDataProvider) JdbcUtils.extractDatabaseMetaData(dataSource, new DatabaseMetaDataCallback() { @Override public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException { String databaseProductName = JdbcUtils.commonDatabaseName(databaseMetaData.getDatabaseProductName()); boolean accessTableColumnMetaData = context.isAccessTableColumnMetaData(); TableMetaDataProvider provider; if ("Oracle".equals(databaseProductName)) { provider = new OracleTableMetaDataProvider(databaseMetaData, context.isOverrideIncludeSynonymsDefault()); } else if ("HSQL Database Engine".equals(databaseProductName)) { provider = new HsqlTableMetaDataProvider(databaseMetaData); } else if ("PostgreSQL".equals(databaseProductName)) { provider = new PostgresTableMetaDataProvider(databaseMetaData); } else if ("Apache Derby".equals(databaseProductName)) { provider = new DerbyTableMetaDataProvider(databaseMetaData); } else { provider = new GenericTableMetaDataProvider(databaseMetaData); } if (nativeJdbcExtractor != null) { provider.setNativeJdbcExtractor(nativeJdbcExtractor); } if (logger.isDebugEnabled()) { logger.debug("Using " + provider.getClass().getSimpleName()); } provider.initializeWithMetaData(databaseMetaData); if (accessTableColumnMetaData) { provider.initializeWithTableColumnMetaData(databaseMetaData, context.getCatalogName(), context.getSchemaName(), context.getTableName()); } return provider; } }); } catch (MetaDataAccessException ex) { throw new DataAccessResourceFailureException("Error retrieving database metadata", ex); } }