当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseMetaDataCallback类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:24,代码来源:DaoUtils.java

示例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);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:23,代码来源:DBRootDAOMysqlImpl.java

示例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);
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:27,代码来源:LoaderDAOMysqlImpl.java

示例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());
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:17,代码来源:LoaderDAOMysqlImpl.java

示例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;
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:26,代码来源:AbstractPersistenceTest.java

示例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);
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:20,代码来源:LoaderDAOMysqlImpl.java

示例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());
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:17,代码来源:LoaderDAOMysqlImpl.java

示例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));
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:14,代码来源:ConnectionCacheLoader.java

示例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);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:21,代码来源:DaoUtils.java

示例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;
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:38,代码来源:LoaderDAOMysqlImpl.java

示例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!
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:41,代码来源:LoaderDAOMysqlImpl.java

示例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;
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:38,代码来源:LoaderDAOMysqlImpl.java

示例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);
	}

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:78,代码来源:CallMetaDataProviderFactory.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:TableMetaDataProviderFactory.java

示例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);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:80,代码来源:CallMetaDataProviderFactory.java


注:本文中的org.springframework.jdbc.support.DatabaseMetaDataCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。