本文整理匯總了Java中org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData方法的典型用法代碼示例。如果您正苦於以下問題:Java JdbcUtils.extractDatabaseMetaData方法的具體用法?Java JdbcUtils.extractDatabaseMetaData怎麽用?Java JdbcUtils.extractDatabaseMetaData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.jdbc.support.JdbcUtils
的用法示例。
在下文中一共展示了JdbcUtils.extractDatabaseMetaData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDatabaseURLAndUserName
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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: isPopulatedDatabase
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的package包/類
/**
* Checks if this is a populated database.
*/
private boolean isPopulatedDatabase(DataSource dataSource)
{
if (dataSource == null)
{
LOG.warn("No datasource found");
return false;
}
try
{
return (boolean) JdbcUtils.extractDatabaseMetaData(dataSource, dbmd ->
{
ResultSet tables = dbmd.getTables(null, null, "MolgenisUser", new String[] { "TABLE" });
boolean resultRow = tables.first();
LOG.info("Table MolgenisUser {}found.", resultRow ? "" : "not ");
return resultRow;
});
}
catch (MetaDataAccessException e)
{
return false;
}
}
示例9: existsTable
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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.JdbcUtils; //導入方法依賴的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: getFieldMetaData
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的package包/類
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);
}
}
示例12: migrateDB
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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!
}
示例13: checkVersion
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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;
}
}
示例14: createMetaDataProvider
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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);
}
}
示例15: createMetaDataProvider
import org.springframework.jdbc.support.JdbcUtils; //導入方法依賴的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);
}
}