List of usage examples for java.sql DatabaseMetaData storesLowerCaseIdentifiers
boolean storesLowerCaseIdentifiers() throws SQLException;
From source file:net.ontopia.topicmaps.cmdlineutils.rdbms.RDBMSIndexTool.java
public static void main(String[] argv) throws Exception { // Initialize logging CmdlineUtils.initializeLogging();//from w ww . j av a2s.c o m // Register logging options CmdlineOptions options = new CmdlineOptions("RDBMSIndexTool", argv); CmdlineUtils.registerLoggingOptions(options); // Parse command line options try { options.parse(); } catch (CmdlineOptions.OptionsException e) { System.err.println("Error: " + e.getMessage()); System.exit(1); } // Get command line arguments String[] args = options.getArguments(); if (args.length != 1) { usage(); System.exit(3); } // load database schema project ClassLoader cloader = RDBMSIndexTool.class.getClassLoader(); InputStream istream = cloader.getResourceAsStream("net/ontopia/topicmaps/impl/rdbms/config/schema.xml"); Project dbp = DatabaseProjectReader.loadProject(istream); // open database connection String propfile = args[0]; ConnectionFactoryIF cf = new DefaultConnectionFactory(PropertyUtils.loadProperties(new File(propfile)), true); Connection conn = cf.requestConnection(); try { DatabaseMetaData dbm = conn.getMetaData(); boolean downcase = dbm.storesLowerCaseIdentifiers(); Map extra_indexes = new TreeMap(); Map missing_indexes = new TreeMap(); Iterator tables = dbp.getTables().iterator(); while (tables.hasNext()) { Table table = (Table) tables.next(); String table_name = (downcase ? table.getName().toLowerCase() : table.getName()); //! System.out.println("T :" + table_name); // get primary keys from database Map pkeys = getPrimaryKeys(table_name, dbm); // get indexes from database Map indexes = getIndexes(table_name, dbm); Map dindexes = new HashMap(); if (table.getPrimaryKeys() != null) { String pkey = table_name + '(' + StringUtils.join(table.getPrimaryKeys(), ',') + ')'; if (!pkeys.containsKey(pkey)) System.out.println("PKM: " + pkey); } Iterator iter = table.getIndexes().iterator(); while (iter.hasNext()) { Index index = (Index) iter.next(); String i = table_name + '(' + StringUtils.join(index.getColumns(), ',') + ')'; String index_name = (downcase ? index.getName().toLowerCase() : index.getName()); dindexes.put(i, index_name); } Set extra = new HashSet(indexes.keySet()); extra.removeAll(dindexes.keySet()); extra.removeAll(pkeys.keySet()); if (!extra.isEmpty()) { Iterator i = extra.iterator(); while (i.hasNext()) { Object k = i.next(); extra_indexes.put(k, indexes.get(k)); } } Set missing = new HashSet(dindexes.keySet()); missing.addAll(pkeys.keySet()); missing.removeAll(indexes.keySet()); if (!missing.isEmpty()) { Iterator i = missing.iterator(); while (i.hasNext()) { Object k = i.next(); missing_indexes.put(k, dindexes.get(k)); } } } if (!extra_indexes.isEmpty()) System.out.println("/* --- Extra indexes ----------------------------------------- */"); Iterator eiter = extra_indexes.keySet().iterator(); while (eiter.hasNext()) { Object k = eiter.next(); System.out.println("drop index " + extra_indexes.get(k) + "; /* " + k + " */"); } if (!missing_indexes.isEmpty()) System.out.println("/* --- Missing indexes---------------------------------------- */"); Iterator miter = missing_indexes.keySet().iterator(); while (miter.hasNext()) { Object k = miter.next(); System.out.println("create index " + missing_indexes.get(k) + " on " + k + ";"); } } finally { conn.rollback(); conn.close(); } }
From source file:com.migratebird.database.IdentifierProcessorFactory.java
/** * Determines the case the database uses to store non-quoted identifiers. This will use the connections * database metadata to determine the correct case. * * @param customStoredIdentifierCase The stored case: possible values 'lower_case', 'upper_case', 'mixed_case' and 'auto' * @param dataSource The datas ource, not null * @return The stored case, not null/*from w w w . j a v a2 s .co m*/ */ protected StoredIdentifierCase determineStoredIdentifierCase(StoredIdentifierCase customStoredIdentifierCase, DataSource dataSource) { if (customStoredIdentifierCase != null) { return customStoredIdentifierCase; } Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData databaseMetaData = connection.getMetaData(); if (databaseMetaData.storesUpperCaseIdentifiers()) { return UPPER_CASE; } else if (databaseMetaData.storesLowerCaseIdentifiers()) { return LOWER_CASE; } else { return MIXED_CASE; } } catch (SQLException e) { throw new DatabaseException("Unable to determine stored identifier case.", e); } finally { closeQuietly(connection, null, null); } }
From source file:com.alibaba.otter.shared.common.utils.meta.DdlUtils.java
public static Table findTable(final JdbcTemplate jdbcTemplate, final String catalogName, final String schemaName, final String tableName, final DdlUtilsFilter filter) throws Exception { return (Table) jdbcTemplate.execute(new ConnectionCallback() { public Object doInConnection(Connection con) throws SQLException, DataAccessException { Table table = null;//from ww w.j a v a 2 s . c om DatabaseMetaDataWrapper metaData = new DatabaseMetaDataWrapper(); try { if (filter != null) { con = filter.filterConnection(con); Assert.notNull(con); } DatabaseMetaData databaseMetaData = con.getMetaData(); if (filter != null) { databaseMetaData = filter.filterDataBaseMetaData(jdbcTemplate, con, databaseMetaData); Assert.notNull(databaseMetaData); } metaData.setMetaData(databaseMetaData); metaData.setTableTypes(TableType.toStrings(SUPPORTED_TABLE_TYPES)); metaData.setCatalog(catalogName); metaData.setSchemaPattern(schemaName); String convertTableName = tableName; if (databaseMetaData.storesUpperCaseIdentifiers()) { metaData.setCatalog(catalogName.toUpperCase()); metaData.setSchemaPattern(schemaName.toUpperCase()); convertTableName = tableName.toUpperCase(); } if (databaseMetaData.storesLowerCaseIdentifiers()) { metaData.setCatalog(catalogName.toLowerCase()); metaData.setSchemaPattern(schemaName.toLowerCase()); convertTableName = tableName.toLowerCase(); } ResultSet tableData = null; try { tableData = metaData.getTables(convertTableName); while ((tableData != null) && tableData.next()) { Map<String, Object> values = readColumns(tableData, initColumnsForTable()); table = readTable(metaData, values); if (table.getName().equalsIgnoreCase(tableName)) { break; } } } finally { JdbcUtils.closeResultSet(tableData); } } catch (Exception e) { logger.error(e.getMessage(), e); } makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound(table); return table; } }); }
From source file:com.alibaba.otter.shared.common.utils.meta.DdlUtils.java
@SuppressWarnings("unchecked") public static List<Table> findTables(final JdbcTemplate jdbcTemplate, final String catalogName, final String schemaName, final String tableNamePattern, final DdlUtilsFilter filter, final DdlTableNameFilter tableNameFilter) throws Exception { return (List<Table>) jdbcTemplate.execute(new ConnectionCallback() { public Object doInConnection(Connection con) throws SQLException, DataAccessException { List<Table> tables = new ArrayList<Table>(); DatabaseMetaDataWrapper metaData = new DatabaseMetaDataWrapper(); try { if (filter != null) { con = filter.filterConnection(con); Assert.notNull(con); }/*from w ww .ja v a2 s. c o m*/ DatabaseMetaData databaseMetaData = con.getMetaData(); if (filter != null) { databaseMetaData = filter.filterDataBaseMetaData(jdbcTemplate, con, databaseMetaData); Assert.notNull(databaseMetaData); } metaData.setMetaData(databaseMetaData); metaData.setTableTypes(TableType.toStrings(SUPPORTED_TABLE_TYPES)); metaData.setCatalog(catalogName); metaData.setSchemaPattern(schemaName); String convertTableName = tableNamePattern; if (databaseMetaData.storesUpperCaseIdentifiers()) { metaData.setCatalog(catalogName.toUpperCase()); metaData.setSchemaPattern(schemaName.toUpperCase()); convertTableName = tableNamePattern.toUpperCase(); } if (databaseMetaData.storesLowerCaseIdentifiers()) { metaData.setCatalog(catalogName.toLowerCase()); metaData.setSchemaPattern(schemaName.toLowerCase()); convertTableName = tableNamePattern.toLowerCase(); } ResultSet tableData = null; try { tableData = metaData.getTables(convertTableName); while ((tableData != null) && tableData.next()) { Map<String, Object> values = readColumns(tableData, initColumnsForTable()); Table table = readTable(metaData, values); if ((tableNameFilter == null) || tableNameFilter.accept(catalogName, schemaName, table.getName())) { tables.add(table); } } } finally { JdbcUtils.closeResultSet(tableData); } } catch (Exception e) { logger.error(e.getMessage(), e); } for (Table table : tables) { makeAllColumnsPrimaryKeysIfNoPrimaryKeysFound(table); } return tables; } }); }
From source file:com.nextep.designer.sqlgen.mysql.impl.MySqlCapturer.java
/** * Builds the table map of new {@link IBasicTable} instances fetched from * the database and hashed by names/*from w ww . j av a 2 s.c o m*/ * * @param conn * {@link Connection} to the database * @param context * current {@link ICaptureContext} * @param monitor * current {@link IProgressMonitor} to report progress * @return a map of {@link IBasicTable} hashed by name * @throws SQLException */ private Map<String, IBasicTable> buildTablesMap(Connection conn, DatabaseMetaData md, ICaptureContext context, IProgressMonitor monitor) throws SQLException { final Map<String, IBasicTable> tablesMap = new HashMap<String, IBasicTable>(); ResultSet rset = null; Statement stmt = null; try { // TODO change location of caseSensitive... put quickly in // MergeStrategy MergeStrategy.setCaseSensitive(!md.storesLowerCaseIdentifiers() && !md.storesUpperCaseIdentifiers()); monitor.subTask(MySQLMessages.getString("capturer.mysql.capturingTables")); //$NON-NLS-1$ stmt = conn.createStatement(); rset = stmt.executeQuery( "select t.table_name, t.table_comment, t.engine, c.character_set_name, c.collation_name from " //$NON-NLS-1$ + "information_schema.tables t, information_schema.collations c where t.table_schema='" //$NON-NLS-1$ + context.getSchema() + "' and t.table_type='BASE TABLE' and " //$NON-NLS-1$ + "c.collation_name=t.table_collation order by t.table_name"); //$NON-NLS-1$ monitor.worked(1); // Fetching results and temporarily store them in the map while (rset.next()) { monitor.worked(10); final String tableName = rset.getString(1); final String tableComments = rset.getString(2); final String engine = rset.getString(3); final String charset = rset.getString(4); final String collation = rset.getString(5); IVersionable<?> v = VersionableFactory.createVersionable(IBasicTable.class, DBVendor.MYSQL); IMySQLTable t = (IMySQLTable) v.getVersionnedObject().getModel(); t.setName(tableName); t.setDescription(tableComments); t.setEngine(engine); t.setCharacterSet(charset); t.setCollation(collation); // Registering table tablesMap.put(tableName, t); } } finally { CaptureHelper.safeClose(rset, stmt); } return tablesMap; }
From source file:com.google.enterprise.connector.sharepoint.dao.UserDataStoreDAO.java
/** * Checks if all the required entities exist in the user data store DB. If * not, creates them. As a minimal check, this method only checks for the * existence of tables. Child of this class can extend this for various such * checks//from ww w . java 2 s.c o m * * @throws SharepointException */ private void confirmEntitiesExistence() throws SharepointException { DatabaseMetaData dbm = null; boolean tableFound = false; String tableName; String tablePattern; ResultSet rsTables = null; Statement statement = null; try { dbm = getConnection().getMetaData(); tableName = getQueryProvider().getUdsTableName(); // Specific to oracle data base to check required entities in user // data store data base. if (getQueryProvider().getDatabase().equalsIgnoreCase(SPConstants.SELECTED_DATABASE)) { statement = getConnection().createStatement(); String query = getSqlQuery(Query.UDS_CHECK_TABLES); rsTables = statement.executeQuery(query); while (rsTables.next()) { if (tableName.equalsIgnoreCase(rsTables.getString(1))) { tableFound = true; LOGGER.config("User data store table found with name : " + tableName); break; } } } else { if (dbm.storesUpperCaseIdentifiers()) { tablePattern = tableName.toUpperCase(); } else if (dbm.storesLowerCaseIdentifiers()) { tablePattern = tableName.toLowerCase(); } else { tablePattern = tableName; } tablePattern = tablePattern.replace("%", dbm.getSearchStringEscape() + "%"); tablePattern = tablePattern.replace("_", dbm.getSearchStringEscape() + "_"); rsTables = dbm.getTables(null, null, tablePattern, null); while (rsTables.next()) { if (tableName.equalsIgnoreCase(rsTables.getString(SPConstants.TABLE_NAME))) { tableFound = true; LOGGER.config( "User data store table found with name : " + rsTables.getString("TABLE_NAME")); break; } } } try { rsTables.close(); if (null != statement) { statement.close(); } } catch (SQLException e) { LOGGER.log(Level.WARNING, "Exception occurred while closing data base resources.", e); } if (!tableFound) { getSimpleJdbcTemplate().update(getSqlQuery(Query.UDS_CREATE_TABLE)); LOGGER.config( "Created user data store table with name : " + Query.UDS_CREATE_TABLE + " sucessfully"); getSimpleJdbcTemplate().update(getSqlQuery(Query.UDS_CREATE_INDEX)); LOGGER.config("Created user data store table index with name : " + Query.UDS_CREATE_INDEX + " sucessfully"); } } catch (Exception e) { LOGGER.log(Level.WARNING, "Exception occurred while getting the table information from the database metadata. ", e); } }
From source file:org.acmsl.queryj.tools.handlers.DatabaseMetaDataLoggingHandler.java
/** * Handles given information.//from www. j av a 2s. co m * @param metaData the database metadata. * @return <code>true</code> if the chain should be stopped. * @throws QueryJBuildException if the metadata cannot be logged. */ protected boolean handle(@NotNull final DatabaseMetaData metaData) throws QueryJBuildException { final boolean result = false; @Nullable Log t_Log = null; try { t_Log = UniqueLogFactory.getLog(DatabaseMetaDataLoggingHandler.class); if (t_Log != null) { t_Log.debug("Numeric functions:" + metaData.getNumericFunctions()); t_Log.debug("String functions:" + metaData.getStringFunctions()); t_Log.debug("System functions:" + metaData.getSystemFunctions()); t_Log.debug("Time functions:" + metaData.getTimeDateFunctions()); t_Log.debug("insertsAreDetected(TYPE_FORWARD_ONLY):" + metaData.insertsAreDetected(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("insertsAreDetected(TYPE_SCROLL_INSENSITIVE):" + metaData.insertsAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("insertsAreDetected(TYPE_SCROLL_SENS):" + metaData.insertsAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("isCatalogAtStart():" + metaData.isCatalogAtStart()); t_Log.debug("isReadOnly():" + metaData.isReadOnly()); /* * Fails for MySQL with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.locatorsUpdateCopy() t_Log.debug( "locatorsUpdateCopy():" + metaData.locatorsUpdateCopy()); */ t_Log.debug("nullPlusNonNullIsNull():" + metaData.nullPlusNonNullIsNull()); t_Log.debug("nullsAreSortedAtEnd():" + metaData.nullsAreSortedAtEnd()); t_Log.debug("nullsAreSortedAtStart():" + metaData.nullsAreSortedAtStart()); t_Log.debug("nullsAreSortedHigh():" + metaData.nullsAreSortedHigh()); t_Log.debug("nullsAreSortedLow():" + metaData.nullsAreSortedLow()); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.othersUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownInsertsAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENS):" + metaData.ownUpdatesAreVisible(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("storesLowerCaseIdentifiers():" + metaData.storesLowerCaseIdentifiers()); t_Log.debug("storesLowerCaseQuotedIdentifiers():" + metaData.storesLowerCaseQuotedIdentifiers()); t_Log.debug("storesMixedCaseIdentifiers():" + metaData.storesMixedCaseIdentifiers()); t_Log.debug("storesMixedCaseQuotedIdentifiers():" + metaData.storesMixedCaseQuotedIdentifiers()); t_Log.debug("storesUpperCaseIdentifiers():" + metaData.storesUpperCaseIdentifiers()); t_Log.debug("storesUpperCaseQuotedIdentifiers():" + metaData.storesUpperCaseQuotedIdentifiers()); t_Log.debug("supportsAlterTableWithAddColumn():" + metaData.supportsAlterTableWithAddColumn()); t_Log.debug("supportsAlterTableWithDropColumn():" + metaData.supportsAlterTableWithDropColumn()); t_Log.debug("supportsANSI92EntryLevelSQL():" + metaData.supportsANSI92EntryLevelSQL()); t_Log.debug("supportsANSI92FullSQL():" + metaData.supportsANSI92FullSQL()); t_Log.debug("supportsANSI92IntermediateSQL():" + metaData.supportsANSI92IntermediateSQL()); t_Log.debug("supportsBatchUpdates():" + metaData.supportsBatchUpdates()); t_Log.debug( "supportsCatalogsInDataManipulation():" + metaData.supportsCatalogsInDataManipulation()); t_Log.debug( "supportsCatalogsInIndexDefinitions():" + metaData.supportsCatalogsInIndexDefinitions()); t_Log.debug("supportsCatalogsInPrivilegeDefinitions():" + metaData.supportsCatalogsInPrivilegeDefinitions()); t_Log.debug("supportsCatalogsInProcedureCalls():" + metaData.supportsCatalogsInProcedureCalls()); t_Log.debug( "supportsCatalogsInTableDefinitions():" + metaData.supportsCatalogsInTableDefinitions()); t_Log.debug("supportsColumnAliasing():" + metaData.supportsColumnAliasing()); t_Log.debug("supportsConvert():" + metaData.supportsConvert()); t_Log.debug("supportsCoreSQLGrammar():" + metaData.supportsCoreSQLGrammar()); t_Log.debug("supportsCorrelatedSubqueries():" + metaData.supportsCorrelatedSubqueries()); t_Log.debug("supportsDataDefinitionAndDataManipulationTransactions():" + metaData.supportsDataDefinitionAndDataManipulationTransactions()); t_Log.debug("supportsDataManipulationTransactionsOnly():" + metaData.supportsDataManipulationTransactionsOnly()); t_Log.debug("supportsDifferentTableCorrelationNames():" + metaData.supportsDifferentTableCorrelationNames()); t_Log.debug("supportsExpressionsInOrderBy():" + metaData.supportsExpressionsInOrderBy()); t_Log.debug("supportsExtendedSQLGrammar():" + metaData.supportsExtendedSQLGrammar()); t_Log.debug("supportsFullOuterJoins():" + metaData.supportsFullOuterJoins()); String t_strSupportsGetGeneratedKeys = Boolean.FALSE.toString(); try { t_strSupportsGetGeneratedKeys = "" + metaData.supportsGetGeneratedKeys(); } catch (@NotNull final SQLException sqlException) { t_strSupportsGetGeneratedKeys += sqlException.getMessage(); } t_Log.debug("supportsGetGeneratedKeys():" + t_strSupportsGetGeneratedKeys); t_Log.debug("supportsGroupBy():" + metaData.supportsGroupBy()); t_Log.debug("supportsGroupByBeyondSelect():" + metaData.supportsGroupByBeyondSelect()); t_Log.debug("supportsGroupByUnrelated():" + metaData.supportsGroupByUnrelated()); t_Log.debug("supportsIntegrityEnhancementFacility():" + metaData.supportsIntegrityEnhancementFacility()); t_Log.debug("supportsLikeEscapeClause():" + metaData.supportsLikeEscapeClause()); t_Log.debug("supportsLimitedOuterJoins():" + metaData.supportsLimitedOuterJoins()); t_Log.debug("supportsMinimumSQLGrammar():" + metaData.supportsMinimumSQLGrammar()); t_Log.debug("supportsMixedCaseIdentifiers():" + metaData.supportsMixedCaseIdentifiers()); t_Log.debug( "supportsMixedCaseQuotedIdentifiers():" + metaData.supportsMixedCaseQuotedIdentifiers()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsMultipleOpenResults() t_Log.debug( "supportsMultipleOpenResults():" + metaData.supportsMultipleOpenResults()); */ t_Log.debug("supportsMultipleResultSets():" + metaData.supportsMultipleResultSets()); t_Log.debug("supportsMultipleTransactions():" + metaData.supportsMultipleTransactions()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsNamedParameters() t_Log.debug( "supportsNamedParameters():" + metaData.supportsNamedParameters()); */ t_Log.debug("supportsNonNullableColumns():" + metaData.supportsNonNullableColumns()); t_Log.debug("supportsOpenCursorsAcrossCommit():" + metaData.supportsOpenCursorsAcrossCommit()); t_Log.debug("supportsOpenCursorsAcrossRollback():" + metaData.supportsOpenCursorsAcrossRollback()); t_Log.debug( "supportsOpenStatementsAcrossCommit():" + metaData.supportsOpenStatementsAcrossCommit()); t_Log.debug("supportsOpenStatementsAcrossRollback():" + metaData.supportsOpenStatementsAcrossRollback()); t_Log.debug("supportsOrderByUnrelated():" + metaData.supportsOrderByUnrelated()); t_Log.debug("supportsOuterJoins():" + metaData.supportsOuterJoins()); t_Log.debug("supportsPositionedDelete():" + metaData.supportsPositionedDelete()); t_Log.debug("supportsPositionedUpdate():" + metaData.supportsPositionedUpdate()); t_Log.debug("supportsResultSetConcurrency(TYPE_FORWARD_ONLY,CONCUR_READ_ONLY):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_FORWARD_ONLY,CONCUR_UPDATABLE):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY):" + metaData.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_INSENSITIVE,CONCUR_UPDATABLE):" + metaData.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_SENSITIVE,CONCUR_READ_ONLY):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)); t_Log.debug("supportsResultSetConcurrency(TYPE_SCROLL_SENSITIVE,CONCUR_UPDATABLE):" + metaData .supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsResultSetHoldability() t_Log.debug( "supportsResultSetHoldability(" + "HOLD_CURSORS_OVER_COMMIT):" + metaData.supportsResultSetHoldability( ResultSet.HOLD_CURSORS_OVER_COMMIT)); t_Log.debug( "supportsResultSetHoldability(" + "CLOSE_CURSORS_AT_COMMIT):" + metaData.supportsResultSetHoldability( ResultSet.CLOSE_CURSORS_AT_COMMIT)); */ t_Log.debug("supportsResultSetType(TYPE_FORWARD_ONLY):" + metaData.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE):" + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("supportsResultSetType(TYPE_SCROLL_SENSITIVE):" + metaData.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsSavePoints() t_Log.debug( "supportsSavepoints():" + metaData.supportsSavepoints()); */ t_Log.debug("supportsSchemasInDataManipulation():" + metaData.supportsSchemasInDataManipulation()); t_Log.debug("supportsSchemasInIndexDefinitions():" + metaData.supportsSchemasInIndexDefinitions()); t_Log.debug("supportsSchemasInPrivilegeDefinitions():" + metaData.supportsSchemasInPrivilegeDefinitions()); t_Log.debug("supportsSchemasInProcedureCalls():" + metaData.supportsSchemasInProcedureCalls()); t_Log.debug("supportsSchemasInTableDefinitions():" + metaData.supportsSchemasInTableDefinitions()); t_Log.debug("supportsSelectForUpdate():" + metaData.supportsSelectForUpdate()); /* * Fails in MySQL 3.23.53 with a java.lang.AbstractMethodError * com.mysql.jdbc.jdbc2.DatabaseMetaData.supportsStatementPooling() t_Log.debug( "supportsStatementPooling():" + metaData.supportsStatementPooling()); */ t_Log.debug("supportsStoredProcedures():" + metaData.supportsStoredProcedures()); t_Log.debug("supportsSubqueriesInComparisons():" + metaData.supportsSubqueriesInComparisons()); t_Log.debug("supportsSubqueriesInExists():" + metaData.supportsSubqueriesInExists()); t_Log.debug("supportsSubqueriesInIns():" + metaData.supportsSubqueriesInIns()); t_Log.debug("supportsSubqueriesInQuantifieds():" + metaData.supportsSubqueriesInQuantifieds()); t_Log.debug("supportsTableCorrelationNames():" + metaData.supportsTableCorrelationNames()); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_NONE):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ)); t_Log.debug("supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE):" + metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)); t_Log.debug("supportsTransactions():" + metaData.supportsTransactions()); t_Log.debug("supportsUnion():" + metaData.supportsUnion()); t_Log.debug("supportsUnionAll():" + metaData.supportsUnionAll()); t_Log.debug("updatesAreDetected(TYPE_FORWARD_ONLY):" + metaData.updatesAreDetected(ResultSet.TYPE_FORWARD_ONLY)); t_Log.debug("updatesAreDetected(TYPE_SCROLL_INSENSITIVE):" + metaData.updatesAreDetected(ResultSet.TYPE_SCROLL_INSENSITIVE)); t_Log.debug("updatesAreDetected(" + "TYPE_SCROLL_SENS):" + metaData.updatesAreDetected(ResultSet.TYPE_SCROLL_SENSITIVE)); t_Log.debug("usesLocalFilePerTable():" + metaData.usesLocalFilePerTable()); t_Log.debug("usesLocalFiles():" + metaData.usesLocalFiles()); } } catch (@NotNull final SQLException sqlException) { t_Log.error("Database metadata request failed.", sqlException); } return result; }
From source file:org.acmsl.queryj.tools.handlers.DatabaseMetaDataRetrievalHandler.java
/** * Analyzes the database metadata.// w w w . j av a 2s . c o m * @param metaData such metadata. * @param parameters the command. */ protected void analyzeMetaData(@NotNull final DatabaseMetaData metaData, @NotNull final QueryJCommand parameters) { boolean t_bCaseSensitive = false; try { t_bCaseSensitive = metaData.storesLowerCaseIdentifiers() || metaData.storesLowerCaseQuotedIdentifiers() || metaData.storesMixedCaseIdentifiers() || metaData.storesMixedCaseQuotedIdentifiers() || metaData.storesUpperCaseIdentifiers() || metaData.storesUpperCaseQuotedIdentifiers(); } catch (@NotNull final SQLException cannotCheckCaseSensitivity) { @Nullable final Log t_Log = UniqueLogFactory.getLog(DatabaseMetaDataRetrievalHandler.class); if (t_Log != null) { t_Log.error("Cannot check whether the database engine is case sensitive or not.", cannotCheckCaseSensitivity); } } storeCaseSensitive(t_bCaseSensitive, parameters); }
From source file:org.apache.ambari.server.orm.DBAccessorImpl.java
private String convertObjectName(String objectName) throws SQLException { //tolerate null names for proper usage in filters if (objectName == null) { return null; }//from w w w. j a v a 2s.c om DatabaseMetaData metaData = getDatabaseMetaData(); if (metaData.storesLowerCaseIdentifiers()) { return objectName.toLowerCase(); } else if (metaData.storesUpperCaseIdentifiers()) { return objectName.toUpperCase(); } return objectName; }
From source file:org.apache.jackrabbit.core.fs.db.DatabaseFileSystem.java
/** * Checks if the required schema objects exist and creates them if they * don't exist yet./* www.j ava2 s .co m*/ * * @throws Exception if an error occurs */ protected void checkSchema() throws Exception { DatabaseMetaData metaData = con.getMetaData(); String tableName = schemaObjectPrefix + "FSENTRY"; if (metaData.storesLowerCaseIdentifiers()) { tableName = tableName.toLowerCase(); } else if (metaData.storesUpperCaseIdentifiers()) { tableName = tableName.toUpperCase(); } ResultSet rs = metaData.getTables(null, null, tableName, null); boolean schemaExists; try { schemaExists = rs.next(); } finally { rs.close(); } if (!schemaExists) { // read ddl from resources InputStream in = DatabaseFileSystem.class.getResourceAsStream(schema + ".ddl"); if (in == null) { String msg = "Configuration error: unknown schema '" + schema + "'"; log.debug(msg); throw new RepositoryException(msg); } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); Statement stmt = con.createStatement(); try { String sql = reader.readLine(); while (sql != null) { // Skip comments and empty lines if (!sql.startsWith("#") && sql.length() > 0) { // replace prefix variable sql = createSchemaSql(sql); stmt.executeUpdate(sql); } // read next sql stmt sql = reader.readLine(); } } finally { IOUtils.closeQuietly(in); closeStatement(stmt); } } }