本文整理汇总了Java中org.springframework.jdbc.support.DatabaseMetaDataCallback类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseMetaDataCallback类的具体用法?Java DatabaseMetaDataCallback怎么用?Java DatabaseMetaDataCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseMetaDataCallback类属于org.springframework.jdbc.support包,在下文中一共展示了DatabaseMetaDataCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDatabaseURLAndUserName
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* @return the current database url and user name (for a given Datasource)
* @throws RuntimeException when the database metadata cannot be retrieved
*/
public static String getDatabaseURLAndUserName(DataSource dataSource) {
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
String url = dbmd.getURL();
String userName = dbmd.getUserName();
StringBuilder s = new StringBuilder(url);
s.append(" (userName='");
s.append(userName);
s.append("')");
return s.toString();
}
};
try {
return (String) JdbcUtils.extractDatabaseMetaData(dataSource, callback);
} catch (Exception e) {
throw new RuntimeException("unable to read database metadata", e);
}
}
示例2: existsDatabase
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
public boolean existsDatabase(String databaseName) {
// get the list of all databases from the db server
List<String> dbNames;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
List<String> ret = new LinkedList<String>();
ResultSet rs = dbmd.getCatalogs();
while (rs.next()) {
ret.add(rs.getString(1));
}
return ret;
}
};
try {
dbNames = (List<String>) JdbcUtils.extractDatabaseMetaData(getDataSource(), callback);
} catch (Exception e) {
throw new RuntimeException("unable to read database metadata", e);
}
return dbNames.contains(databaseName);
}
示例3: testConnection
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@Override
public void testConnection(String url, String username, String password) throws Exception {
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setPoolName("easyrecPool");
config.addDataSourceProperty("url", url);
HikariDataSource ds = new HikariDataSource(config);
setDataSource(ds);
sqlScriptService.setDataSource(ds);
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(ds, callback);
}
示例4: createDB
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@Override
public void createDB() throws Exception {
HikariDataSource bds = (HikariDataSource) getDataSource();
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(bds, callback);
sqlScriptService.executeSqlScript(dbCreationFile.getInputStream());
}
示例5: tableNames
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
private String[] tableNames() {
if(tableNames == null) {
final ArrayList<String> tables = new ArrayList<>();
try {
JdbcUtils.extractDatabaseMetaData(datasource, new DatabaseMetaDataCallback() {
@Override
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, null, new String[]{"TABLE"});
while (rs.next()) {
String tableName = rs.getString(3);
if(!blacklist.contains(tableName)) {
tables.add(tableName);
}
}
return null;
}
});
} catch (Exception e) {
e.printStackTrace();
}
tableNames = tables.toArray(new String[tables.size()]);
}
return tableNames;
}
示例6: testConnection
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@Override
public void testConnection(String url, String username, String password) throws Exception {
BasicDataSource bds = (BasicDataSource) getDataSource();
bds.setUrl(url);
bds.setUsername(username);
bds.setPassword(password);
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(bds, callback);
}
示例7: createDB
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@Override
public void createDB() throws Exception {
BasicDataSource bds = (BasicDataSource) getDataSource();
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(bds, callback);
sqlScriptService.executeSqlScript(dbCreationFile.getInputStream());
}
示例8: createSanitizer
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
public static PostgresSanitizer createSanitizer(DataSource dataSource) {
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
@Override
public String processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
return dbmd.getIdentifierQuoteString();
}
};
try {
return new PostgresSanitizer(JdbcUtils.extractDatabaseMetaData(dataSource, callback).toString());
} catch (MetaDataAccessException e) {
throw RaptureExceptionFactory.create("Unable to get quote identifier: " + ExceptionToString.format(e));
}
}
示例9: existsTable
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* Checks if a given database table is found in the given <code>DataSource</code>.
*
* @param dataSource
* @param tableName
* @return true if table exists, false if not
*/
public static boolean existsTable(DataSource dataSource, final String tableName) {
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, tableName, null);
return rs.next();
}
};
try {
return (Boolean) JdbcUtils.extractDatabaseMetaData(dataSource, callback);
} catch (Exception e) {
throw new RuntimeException("unable to read database metadata", e);
}
}
示例10: checkVersion
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* This function returns the current version of easyrec,
* depending on the presence of a version table. If
* no version table is present return the inital version
*
*
*/
@Override
public Float checkVersion() throws Exception {
HikariDataSource bds = (HikariDataSource) getDataSource();
float tableCount;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, null, null);
float f = 0;
while (rs.next()) {
f++;
}
return f;
}
};
tableCount = (Float) JdbcUtils.extractDatabaseMetaData(bds, callback);
if (tableCount != 0) {
try {
return getJdbcTemplate().queryForObject("SELECT MAX(VERSION) FROM easyrec ", Float.class);
} catch (Exception e) {
// else return initial version 0.9
return INITIAL_VERSION;
}
} else {
return tableCount;
}
}
示例11: migrateDB
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
@Override
public void migrateDB() throws Exception {
BasicDataSource bds = (BasicDataSource) getDataSource();
boolean tablesOk = false;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "operator", null);
return rs.next();
}
};
tablesOk = (Boolean) JdbcUtils.extractDatabaseMetaData(bds, callback);
Float installedVersion = checkVersion();
for (String migrateFile : migrateFiles) {
logger.info("migrate File: " + migrateFile);
Float scriptVersion = Float.parseFloat(migrateFile.substring(migrateFile.lastIndexOf("_") + 1));
logger.info("scriptVersion: " + scriptVersion);
if (installedVersion < scriptVersion) {
File f = new File(dbMigrateFolder.getFile(), migrateFile + ".sql");
if (f.exists()) {
logger.info("Executing migrate script: " + f.getName());
sqlScriptService.executeSqlScript(new FileSystemResource(f).getInputStream());
}
}
}
if (installedVersion < 0.96f) {
update_0_96f();
// logs are not converted from ruleminerlog -> plugin_log
}
if (installedVersion < 0.98) {
update_0_98();
}
//updateVersion(); // done in migrate script!
}
示例12: checkVersion
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* This function returns the current version of easyrec,
* depending on the presence of a version table. If
* no version table is present return the inital version
*
* @return
*/
@Override
public Float checkVersion() throws Exception {
BasicDataSource bds = (BasicDataSource) getDataSource();
float tableCount;
DatabaseMetaDataCallback callback = new DatabaseMetaDataCallback() {
public Object processMetaData(DatabaseMetaData dbmd) throws SQLException, MetaDataAccessException {
ResultSet rs = dbmd.getTables(null, null, "%", null);
float f = 0;
while (rs.next()) {
f++;
}
return f;
}
};
tableCount = (Float) JdbcUtils.extractDatabaseMetaData(bds, callback);
if (tableCount != 0) {
try {
return getJdbcTemplate().queryForObject("SELECT MAX(VERSION) FROM easyrec ", Float.class);
} catch (Exception e) {
// else return initial version 0.9
return INITIAL_VERSION;
}
} else {
return tableCount;
}
}
示例13: createMetaDataProvider
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* 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);
}
}
示例14: createMetaDataProvider
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* 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);
}
}
示例15: createMetaDataProvider
import org.springframework.jdbc.support.DatabaseMetaDataCallback; //导入依赖的package包/类
/**
* 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);
}
}