Example usage for java.sql DatabaseMetaData storesUpperCaseIdentifiers

List of usage examples for java.sql DatabaseMetaData storesUpperCaseIdentifiers

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData storesUpperCaseIdentifiers.

Prototype

boolean storesUpperCaseIdentifiers() throws SQLException;

Source Link

Document

Retrieves whether this database treats mixed case unquoted SQL identifiers as case insensitive and stores them in upper case.

Usage

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   w  w w. j  a  v  a2s  . c  o m*/
            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.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  av a 2 s . c  om*/
 */
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

@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 w  w .  j  a  v a 2  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. ja v  a  2s.  co 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   www. j a  va2s  .  co 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  w  w  w.  ja va  2s .  c o  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.//from   www.  ja  v a  2s  .co 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 ww  .  ja v  a  2  s .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./*w  w w .  j a va2  s. c o 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);
        }
    }
}

From source file:org.apache.jackrabbit.core.fs.db.OracleFileSystem.java

/**
 * {@inheritDoc}/*w  w  w .  ja v  a2s. c o m*/
 * <p/>
 * Overridden in order to support multiple oracle schemas. Note that
 * schema names in Oracle correspond to the username of the connection.
 * See http://issues.apache.org/jira/browse/JCR-582
 *
 * @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();
    }
    String userName = metaData.getUserName();

    ResultSet rs = metaData.getTables(null, userName, tableName, null);
    boolean schemaExists;
    try {
        schemaExists = rs.next();
    } finally {
        rs.close();
    }

    if (!schemaExists) {
        // read ddl from resources
        InputStream in = OracleFileSystem.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 = Text.replace(sql, SCHEMA_OBJECT_PREFIX_VARIABLE, schemaObjectPrefix);

                    // set the tablespace if it is defined
                    String tspace;
                    if (tableSpace == null || "".equals(tableSpace)) {
                        tspace = "";
                    } else {
                        tspace = "tablespace " + tableSpace;
                    }
                    sql = Text.replace(sql, TABLE_SPACE_VARIABLE, tspace).trim();

                    // execute sql stmt
                    stmt.executeUpdate(sql);
                }
                // read next sql stmt
                sql = reader.readLine();
            }
        } finally {
            IOUtils.closeQuietly(in);
            closeStatement(stmt);
        }
    }
}