Java Code Examples for org.springframework.jdbc.support.DatabaseMetaDataCallback

The following examples show how to use org.springframework.jdbc.support.DatabaseMetaDataCallback. These examples are extracted from open source projects. 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
/**
 * 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 2
/**
 * 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);
	}
}
 
Example 3
/**
 * 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 4
/**
 * 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 5
Source Project: effectivejava   Source File: CallMetaDataProviderFactory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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 6
/**
 * 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);
	}
}