本文整理汇总了Java中org.springframework.jdbc.support.MetaDataAccessException类的典型用法代码示例。如果您正苦于以下问题:Java MetaDataAccessException类的具体用法?Java MetaDataAccessException怎么用?Java MetaDataAccessException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MetaDataAccessException类属于org.springframework.jdbc.support包,在下文中一共展示了MetaDataAccessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的package包/类
/**
* 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;
}
示例2: getDatabaseURLAndUserName
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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);
}
}
示例3: existsDatabase
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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);
}
示例4: testConnection
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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);
}
示例5: createDB
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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());
}
示例6: tableNames
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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;
}
示例7: testConnection
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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);
}
示例8: createDB
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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());
}
示例9: isPopulatedDatabase
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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;
}
}
示例10: getDatabaseType
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的package包/类
private String getDatabaseType(DataSource dataSource) {
try {
return DatabaseType.fromMetaData(dataSource).toString().toLowerCase();
}
catch (MetaDataAccessException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
}
示例11: getDatabaseName
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的package包/类
private String getDatabaseName() {
try {
String databaseProductName = JdbcUtils
.extractDatabaseMetaData(this.dataSource, "getDatabaseProductName")
.toString();
return JdbcUtils.commonDatabaseName(databaseProductName).toLowerCase();
}
catch (MetaDataAccessException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:JdbcSessionDatabaseInitializer.java
示例12: getDatabaseType
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的package包/类
private String getDatabaseType() {
try {
return DatabaseType.fromMetaData(this.dataSource).toString().toLowerCase();
}
catch (MetaDataAccessException ex) {
throw new IllegalStateException("Unable to detect database type", ex);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:BatchDatabaseInitializer.java
示例13: createSanitizer
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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));
}
}
示例14: existsTable
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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);
}
}
示例15: checkVersion
import org.springframework.jdbc.support.MetaDataAccessException; //导入依赖的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;
}
}