List of usage examples for java.sql DatabaseMetaData storesUpperCaseIdentifiers
boolean storesUpperCaseIdentifiers() throws SQLException;
From source file:org.apache.jackrabbit.core.persistence.bundle.BundleDbPersistenceManager.java
/** * Checks if the database table exist.//from w ww . j a v a 2s . c om * * @return <code>true</code> if the tables exist; * <code>false</code> otherwise. * * @throws SQLException if a database error occurs. * @throws RepositoryException if a repository exception occurs. */ protected boolean checkTablesExist() throws SQLException, RepositoryException { DatabaseMetaData metaData = connectionManager.getConnection().getMetaData(); String tableName = schemaObjectPrefix + "BUNDLE"; if (metaData.storesLowerCaseIdentifiers()) { tableName = tableName.toLowerCase(); } else if (metaData.storesUpperCaseIdentifiers()) { tableName = tableName.toUpperCase(); } String userName = checkTablesWithUser() ? metaData.getUserName() : null; ResultSet rs = metaData.getTables(null, userName, tableName, null); try { return rs.next(); } finally { rs.close(); } }
From source file:org.apache.jackrabbit.core.persistence.db.DatabasePersistenceManager.java
/** * Checks if the required schema objects exist and creates them if they * don't exist yet./*w w w . ja v a2 s.co m*/ * * @throws Exception if an error occurs */ protected void checkSchema() throws Exception { DatabaseMetaData metaData = con.getMetaData(); String tableName = schemaObjectPrefix + "NODE"; 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 = getSchemaDDL(); 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); // execute sql stmt stmt.executeUpdate(sql); } // read next sql stmt sql = reader.readLine(); } // commit the changes con.commit(); } finally { IOUtils.closeQuietly(in); closeStatement(stmt); } } }
From source file:org.apache.jackrabbit.core.persistence.db.OraclePersistenceManager.java
/** * {@inheritDoc}//w w w.ja v a2 s . co 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 + "NODE"; 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 = getSchemaDDL(); 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(); } // commit the changes con.commit(); } finally { IOUtils.closeQuietly(in); closeStatement(stmt); } } }
From source file:org.apache.ode.bpel.extvar.jdbc.JdbcExternalVariableModule.java
public void configure(QName pid, String extVarId, Element config) throws ExternalVariableModuleException { EVarId evarId = new EVarId(pid, extVarId); DataSource ds = null;/*from ww w. ja v a 2 s. co m*/ Element jndiDs = DOMUtils.findChildByName(config, new QName(JDBC_NS, "datasource-jndi")); Element jndiRef = DOMUtils.findChildByName(config, new QName(JDBC_NS, "datasource-ref")); Element initMode = DOMUtils.findChildByName(config, new QName(JDBC_NS, "init-mode")); if (jndiRef != null) { String refname = jndiRef.getTextContent().trim(); ds = _dataSources.get(refname); if (ds == null) throw new ExternalVariableModuleException( "Data source reference \"" + refname + "\" not found for external variable " + evarId + "; make sure to register the data source with the engine!"); } else if (jndiDs != null) { String name = jndiDs.getTextContent().trim(); Object dsCandidate; InitialContext ctx; try { ctx = new InitialContext(); } catch (Exception ex) { throw new ExternalVariableModuleException( "Unable to access JNDI context for external variable " + evarId, ex); } try { dsCandidate = ctx.lookup(name); } catch (Exception ex) { throw new ExternalVariableModuleException("Lookup of data source for " + evarId + " failed.", ex); } finally { try { ctx.close(); } catch (NamingException e) { /* ignore */ } } if (dsCandidate == null) throw new ExternalVariableModuleException("Data source \"" + name + "\" not found in JNDI!"); if (!(dsCandidate instanceof DataSource)) throw new ExternalVariableModuleException( "JNDI object \"" + name + "\" does not implement javax.sql.DataSource"); ds = (DataSource) dsCandidate; } if (ds == null) { throw new ExternalVariableModuleException( "No valid data source configuration for JDBC external varible " + evarId); } Connection conn = null; DatabaseMetaData metaData; try { conn = ds.getConnection(); metaData = conn.getMetaData(); } catch (Exception ex) { try { if (conn != null) conn.close(); } catch (SQLException e) { // ignore } throw new ExternalVariableModuleException( "Unable to open database connection for external variable " + evarId, ex); } try { DbExternalVariable dbev = new DbExternalVariable(evarId, ds); if (initMode != null) try { dbev._initType = InitType.valueOf(initMode.getTextContent().trim()); } catch (Exception ex) { throw new ExternalVariableModuleException( "Invalid <init-mode> value: " + initMode.getTextContent().trim()); } Element tableName = DOMUtils.findChildByName(config, new QName(JDBC_NS, "table")); if (tableName == null || tableName.getTextContent().trim().equals("")) throw new ExternalVariableModuleException("Must specify <table> for external variable " + evarId); String table = tableName.getTextContent().trim(); String schema = null; if (table.indexOf('.') != -1) { schema = table.substring(0, table.indexOf('.')); table = table.substring(table.indexOf('.') + 1); } if (metaData.storesLowerCaseIdentifiers()) { table = table.toLowerCase(); if (schema != null) schema = table.toLowerCase(); } else if (metaData.storesUpperCaseIdentifiers()) { table = table.toUpperCase(); if (schema != null) schema = schema.toUpperCase(); } dbev.generatedKeys = metaData.supportsGetGeneratedKeys(); ResultSet tables = metaData.getTables(null, schema, table, null); if (tables.next()) { dbev.table = tables.getString("TABLE_NAME"); dbev.schema = tables.getString("TABLE_SCHEM"); } else throw new ExternalVariableModuleException("Table \"" + table + "\" not found in database."); tables.close(); List<Element> columns = DOMUtils.findChildrenByName(config, new QName(JDBC_NS, "column")); for (Element col : columns) { String name = col.getAttribute("name"); String colname = col.getAttribute("column-name"); String key = col.getAttribute("key"); String gentype = col.getAttribute("generator"); String expression = col.getAttribute("expression"); if (key == null || "".equals(key)) key = "no"; if (gentype == null || "".equals(gentype)) gentype = GenType.none.toString(); if (colname == null || "".equals(colname)) colname = name; if (name == null || "".equals(name)) throw new ExternalVariableModuleException( "External variable " + evarId + " <column> element must have \"name\" attribute. "); if (metaData.storesLowerCaseIdentifiers()) colname = colname.toLowerCase(); else if (metaData.storesUpperCaseIdentifiers()) colname = colname.toUpperCase(); GenType gtype; try { gtype = GenType.valueOf(gentype); } catch (Exception ex) { throw new ExternalVariableModuleException("External variable " + evarId + " column \"" + name + "\" generator type \"" + gentype + "\" is unknown."); } if (gtype == GenType.expression && (expression == null || "".equals(expression))) throw new ExternalVariableModuleException("External variable " + evarId + " column \"" + name + "\" used \"expression\" generator, but did not specify an expression"); Column c = dbev.new Column(name, colname, key.equalsIgnoreCase("yes"), gtype, expression); ResultSet cmd = metaData.getColumns(null, dbev.schema, dbev.table, colname); try { if (cmd.next()) { c.dataType = cmd.getInt("DATA_TYPE"); c.nullok = cmd.getInt("NULLABLE") != 0; } else throw new ExternalVariableModuleException("External variable " + evarId + " referenced " + "non-existant column \"" + colname + "\"!"); } finally { cmd.close(); } dbev.addColumn(c); } if (dbev.numColumns() == 0) throw new ExternalVariableModuleException( "External variable " + evarId + " did not have any <column> elements!"); _vars.put(evarId, dbev); } catch (SQLException se) { throw new ExternalVariableModuleException("SQL Error", se); } finally { try { conn.close(); } catch (SQLException e) { } } }
From source file:org.apache.openjpa.jdbc.sql.DBDictionaryFactory.java
/** * Return a string containing all the property values of the given * database metadata.// w w w .j a v a 2 s .c o m */ public static String toString(DatabaseMetaData meta) throws SQLException { String lineSep = J2DoPrivHelper.getLineSeparator(); StringBuilder buf = new StringBuilder(4096); try { buf.append("catalogSeparator: ").append(meta.getCatalogSeparator()).append(lineSep) .append("catalogTerm: ").append(meta.getCatalogTerm()).append(lineSep) .append("databaseProductName: ").append(meta.getDatabaseProductName()).append(lineSep) .append("databaseProductVersion: ").append(meta.getDatabaseProductVersion()).append(lineSep) .append("driverName: ").append(meta.getDriverName()).append(lineSep).append("driverVersion: ") .append(meta.getDriverVersion()).append(lineSep).append("extraNameCharacters: ") .append(meta.getExtraNameCharacters()).append(lineSep).append("identifierQuoteString: ") .append(meta.getIdentifierQuoteString()).append(lineSep).append("numericFunctions: ") .append(meta.getNumericFunctions()).append(lineSep).append("procedureTerm: ") .append(meta.getProcedureTerm()).append(lineSep).append("schemaTerm: ") .append(meta.getSchemaTerm()).append(lineSep).append("searchStringEscape: ") .append(meta.getSearchStringEscape()).append(lineSep).append("sqlKeywords: ") .append(meta.getSQLKeywords()).append(lineSep).append("stringFunctions: ") .append(meta.getStringFunctions()).append(lineSep).append("systemFunctions: ") .append(meta.getSystemFunctions()).append(lineSep).append("timeDateFunctions: ") .append(meta.getTimeDateFunctions()).append(lineSep).append("url: ").append(meta.getURL()) .append(lineSep).append("userName: ").append(meta.getUserName()).append(lineSep) .append("defaultTransactionIsolation: ").append(meta.getDefaultTransactionIsolation()) .append(lineSep).append("driverMajorVersion: ").append(meta.getDriverMajorVersion()) .append(lineSep).append("driverMinorVersion: ").append(meta.getDriverMinorVersion()) .append(lineSep).append("maxBinaryLiteralLength: ").append(meta.getMaxBinaryLiteralLength()) .append(lineSep).append("maxCatalogNameLength: ").append(meta.getMaxCatalogNameLength()) .append(lineSep).append("maxCharLiteralLength: ").append(meta.getMaxCharLiteralLength()) .append(lineSep).append("maxColumnNameLength: ").append(meta.getMaxColumnNameLength()) .append(lineSep).append("maxColumnsInGroupBy: ").append(meta.getMaxColumnsInGroupBy()) .append(lineSep).append("maxColumnsInIndex: ").append(meta.getMaxColumnsInIndex()) .append(lineSep).append("maxColumnsInOrderBy: ").append(meta.getMaxColumnsInOrderBy()) .append(lineSep).append("maxColumnsInSelect: ").append(meta.getMaxColumnsInSelect()) .append(lineSep).append("maxColumnsInTable: ").append(meta.getMaxColumnsInTable()) .append(lineSep).append("maxConnections: ").append(meta.getMaxConnections()).append(lineSep) .append("maxCursorNameLength: ").append(meta.getMaxCursorNameLength()).append(lineSep) .append("maxIndexLength: ").append(meta.getMaxIndexLength()).append(lineSep) .append("maxProcedureNameLength: ").append(meta.getMaxProcedureNameLength()).append(lineSep) .append("maxRowSize: ").append(meta.getMaxRowSize()).append(lineSep) .append("maxSchemaNameLength: ").append(meta.getMaxSchemaNameLength()).append(lineSep) .append("maxStatementLength: ").append(meta.getMaxStatementLength()).append(lineSep) .append("maxStatements: ").append(meta.getMaxStatements()).append(lineSep) .append("maxTableNameLength: ").append(meta.getMaxTableNameLength()).append(lineSep) .append("maxTablesInSelect: ").append(meta.getMaxTablesInSelect()).append(lineSep) .append("maxUserNameLength: ").append(meta.getMaxUserNameLength()).append(lineSep) .append("isCatalogAtStart: ").append(meta.isCatalogAtStart()).append(lineSep) .append("isReadOnly: ").append(meta.isReadOnly()).append(lineSep) .append("nullPlusNonNullIsNull: ").append(meta.nullPlusNonNullIsNull()).append(lineSep) .append("nullsAreSortedAtEnd: ").append(meta.nullsAreSortedAtEnd()).append(lineSep) .append("nullsAreSortedAtStart: ").append(meta.nullsAreSortedAtStart()).append(lineSep) .append("nullsAreSortedHigh: ").append(meta.nullsAreSortedHigh()).append(lineSep) .append("nullsAreSortedLow: ").append(meta.nullsAreSortedLow()).append(lineSep) .append("storesLowerCaseIdentifiers: ").append(meta.storesLowerCaseIdentifiers()) .append(lineSep).append("storesLowerCaseQuotedIdentifiers: ") .append(meta.storesLowerCaseQuotedIdentifiers()).append(lineSep) .append("storesMixedCaseIdentifiers: ").append(meta.storesMixedCaseIdentifiers()) .append(lineSep).append("storesMixedCaseQuotedIdentifiers: ") .append(meta.storesMixedCaseQuotedIdentifiers()).append(lineSep) .append("storesUpperCaseIdentifiers: ").append(meta.storesUpperCaseIdentifiers()) .append(lineSep).append("storesUpperCaseQuotedIdentifiers: ") .append(meta.storesUpperCaseQuotedIdentifiers()).append(lineSep) .append("supportsAlterTableWithAddColumn: ").append(meta.supportsAlterTableWithAddColumn()) .append(lineSep).append("supportsAlterTableWithDropColumn: ") .append(meta.supportsAlterTableWithDropColumn()).append(lineSep) .append("supportsANSI92EntryLevelSQL: ").append(meta.supportsANSI92EntryLevelSQL()) .append(lineSep).append("supportsANSI92FullSQL: ").append(meta.supportsANSI92FullSQL()) .append(lineSep).append("supportsANSI92IntermediateSQL: ") .append(meta.supportsANSI92IntermediateSQL()).append(lineSep) .append("supportsCatalogsInDataManipulation: ") .append(meta.supportsCatalogsInDataManipulation()).append(lineSep) .append("supportsCatalogsInIndexDefinitions: ") .append(meta.supportsCatalogsInIndexDefinitions()).append(lineSep) .append("supportsCatalogsInPrivilegeDefinitions: ") .append(meta.supportsCatalogsInPrivilegeDefinitions()).append(lineSep) .append("supportsCatalogsInProcedureCalls: ").append(meta.supportsCatalogsInProcedureCalls()) .append(lineSep).append("supportsCatalogsInTableDefinitions: ") .append(meta.supportsCatalogsInTableDefinitions()).append(lineSep) .append("supportsColumnAliasing: ").append(meta.supportsColumnAliasing()).append(lineSep) .append("supportsConvert: ").append(meta.supportsConvert()).append(lineSep) .append("supportsCoreSQLGrammar: ").append(meta.supportsCoreSQLGrammar()).append(lineSep) .append("supportsCorrelatedSubqueries: ").append(meta.supportsCorrelatedSubqueries()) .append(lineSep).append("supportsDataDefinitionAndDataManipulationTransactions: ") .append(meta.supportsDataDefinitionAndDataManipulationTransactions()).append(lineSep) .append("supportsDataManipulationTransactionsOnly: ") .append(meta.supportsDataManipulationTransactionsOnly()).append(lineSep) .append("supportsDifferentTableCorrelationNames: ") .append(meta.supportsDifferentTableCorrelationNames()).append(lineSep) .append("supportsExpressionsInOrderBy: ").append(meta.supportsExpressionsInOrderBy()) .append(lineSep).append("supportsExtendedSQLGrammar: ") .append(meta.supportsExtendedSQLGrammar()).append(lineSep).append("supportsFullOuterJoins: ") .append(meta.supportsFullOuterJoins()).append(lineSep).append("supportsGroupBy: ") .append(meta.supportsGroupBy()).append(lineSep).append("supportsGroupByBeyondSelect: ") .append(meta.supportsGroupByBeyondSelect()).append(lineSep).append("supportsGroupByUnrelated: ") .append(meta.supportsGroupByUnrelated()).append(lineSep) .append("supportsIntegrityEnhancementFacility: ") .append(meta.supportsIntegrityEnhancementFacility()).append(lineSep) .append("supportsLikeEscapeClause: ").append(meta.supportsLikeEscapeClause()).append(lineSep) .append("supportsLimitedOuterJoins: ").append(meta.supportsLimitedOuterJoins()).append(lineSep) .append("supportsMinimumSQLGrammar: ").append(meta.supportsMinimumSQLGrammar()).append(lineSep) .append("supportsMixedCaseIdentifiers: ").append(meta.supportsMixedCaseIdentifiers()) .append(lineSep).append("supportsMixedCaseQuotedIdentifiers: ") .append(meta.supportsMixedCaseQuotedIdentifiers()).append(lineSep) .append("supportsMultipleResultSets: ").append(meta.supportsMultipleResultSets()) .append(lineSep).append("supportsMultipleTransactions: ") .append(meta.supportsMultipleTransactions()).append(lineSep) .append("supportsNonNullableColumns: ").append(meta.supportsNonNullableColumns()) .append(lineSep).append("supportsOpenCursorsAcrossCommit: ") .append(meta.supportsOpenCursorsAcrossCommit()).append(lineSep) .append("supportsOpenCursorsAcrossRollback: ").append(meta.supportsOpenCursorsAcrossRollback()) .append(lineSep).append("supportsOpenStatementsAcrossCommit: ") .append(meta.supportsOpenStatementsAcrossCommit()).append(lineSep) .append("supportsOpenStatementsAcrossRollback: ") .append(meta.supportsOpenStatementsAcrossRollback()).append(lineSep) .append("supportsOrderByUnrelated: ").append(meta.supportsOrderByUnrelated()).append(lineSep) .append("supportsOuterJoins: ").append(meta.supportsOuterJoins()).append(lineSep) .append("supportsPositionedDelete: ").append(meta.supportsPositionedDelete()).append(lineSep) .append("supportsPositionedUpdate: ").append(meta.supportsPositionedUpdate()).append(lineSep) .append("supportsSchemasInDataManipulation: ").append(meta.supportsSchemasInDataManipulation()) .append(lineSep).append("supportsSchemasInIndexDefinitions: ") .append(meta.supportsSchemasInIndexDefinitions()).append(lineSep) .append("supportsSchemasInPrivilegeDefinitions: ") .append(meta.supportsSchemasInPrivilegeDefinitions()).append(lineSep) .append("supportsSchemasInProcedureCalls: ").append(meta.supportsSchemasInProcedureCalls()) .append(lineSep).append("supportsSchemasInTableDefinitions: ") .append(meta.supportsSchemasInTableDefinitions()).append(lineSep) .append("supportsSelectForUpdate: ").append(meta.supportsSelectForUpdate()).append(lineSep) .append("supportsStoredProcedures: ").append(meta.supportsStoredProcedures()).append(lineSep) .append("supportsSubqueriesInComparisons: ").append(meta.supportsSubqueriesInComparisons()) .append(lineSep).append("supportsSubqueriesInExists: ") .append(meta.supportsSubqueriesInExists()).append(lineSep).append("supportsSubqueriesInIns: ") .append(meta.supportsSubqueriesInIns()).append(lineSep) .append("supportsSubqueriesInQuantifieds: ").append(meta.supportsSubqueriesInQuantifieds()) .append(lineSep).append("supportsTableCorrelationNames: ") .append(meta.supportsTableCorrelationNames()).append(lineSep).append("supportsTransactions: ") .append(meta.supportsTransactions()).append(lineSep).append("supportsUnion: ") .append(meta.supportsUnion()).append(lineSep).append("supportsUnionAll: ") .append(meta.supportsUnionAll()).append(lineSep).append("usesLocalFilePerTable: ") .append(meta.usesLocalFilePerTable()).append(lineSep).append("usesLocalFiles: ") .append(meta.usesLocalFiles()).append(lineSep).append("allProceduresAreCallable: ") .append(meta.allProceduresAreCallable()).append(lineSep).append("allTablesAreSelectable: ") .append(meta.allTablesAreSelectable()).append(lineSep) .append("dataDefinitionCausesTransactionCommit: ") .append(meta.dataDefinitionCausesTransactionCommit()).append(lineSep) .append("dataDefinitionIgnoredInTransactions: ") .append(meta.dataDefinitionIgnoredInTransactions()).append(lineSep) .append("doesMaxRowSizeIncludeBlobs: ").append(meta.doesMaxRowSizeIncludeBlobs()) .append(lineSep).append("supportsBatchUpdates: ").append(meta.supportsBatchUpdates()); } catch (Throwable t) { // maybe abstract method error for jdbc 3 metadata method, or // other error buf.append(lineSep).append("Caught throwable: ").append(t); } return buf.toString(); }
From source file:org.artifactory.storage.db.util.DbUtils.java
public static boolean tableExists(DatabaseMetaData metaData, String tableName) throws SQLException { boolean schemaExists; if (metaData.storesLowerCaseIdentifiers()) { tableName = tableName.toLowerCase(); } else if (metaData.storesUpperCaseIdentifiers()) { tableName = tableName.toUpperCase(); }/*from ww w.j a v a2 s . c om*/ try (ResultSet rs = metaData.getTables(null, null, tableName, new String[] { "TABLE" })) { schemaExists = rs.next(); } return schemaExists; }
From source file:org.batoo.jpa.core.jdbc.adapter.JdbcAdaptor.java
private JdbcTable getTableMetadata(DataSourceImpl datasource, String catalog, String schema, String table) throws SQLException { final ConnectionImpl connection = datasource.getConnection(); ResultSet tables = null;/*www . j a va2s .c o m*/ try { final DatabaseMetaData dbMetadata = connection.getMetaData(); if (StringUtils.isBlank(catalog)) { catalog = null; } if (StringUtils.isBlank(schema)) { schema = null; } if (dbMetadata.storesUpperCaseIdentifiers()) { tables = dbMetadata.getTables(// BatooUtils.upper(catalog), // BatooUtils.upper(schema), // BatooUtils.upper(table), // JdbcAdaptor.TABLE_OR_VIEW); } else if (dbMetadata.storesLowerCaseIdentifiers()) { tables = dbMetadata.getTables(// BatooUtils.lower(catalog), // BatooUtils.lower(schema), // BatooUtils.lower(table), // JdbcAdaptor.TABLE_OR_VIEW); } else { tables = dbMetadata.getTables(catalog, schema, table, JdbcAdaptor.TABLE_OR_VIEW); } if (tables.next()) { final String tableName = tables.getString(JdbcAdaptor.TABLE_NAME); if (table.equalsIgnoreCase(tableName)) { return new JdbcTable(dbMetadata, tables); } } } finally { DbUtils.closeQuietly(connection); DbUtils.closeQuietly(tables); } return null; }
From source file:org.batoo.jpa.jdbc.adapter.JdbcAdaptor.java
private JdbcTable getTableMetadata(DataSource datasource, String catalog, String schema, String table) throws SQLException { final Connection connection = datasource.getConnection(); ResultSet tables = null;//from www. j a va 2s . c o m try { final DatabaseMetaData dbMetadata = connection.getMetaData(); if (StringUtils.isBlank(catalog)) { catalog = null; } if (StringUtils.isBlank(schema)) { schema = null; } if (dbMetadata.storesUpperCaseIdentifiers()) { tables = dbMetadata.getTables(// BatooUtils.upper(catalog), // BatooUtils.upper(schema), // BatooUtils.upper(table), // JdbcAdaptor.TABLE_OR_VIEW); } else if (dbMetadata.storesLowerCaseIdentifiers()) { tables = dbMetadata.getTables(// BatooUtils.lower(catalog), // BatooUtils.lower(schema), // BatooUtils.lower(table), // JdbcAdaptor.TABLE_OR_VIEW); } else { tables = dbMetadata.getTables(catalog, schema, table, JdbcAdaptor.TABLE_OR_VIEW); } if (tables.next()) { final String tableName = tables.getString(JdbcAdaptor.TABLE_NAME); if (table.equalsIgnoreCase(tableName)) { return new JdbcTable(dbMetadata, tables); } } } finally { DbUtils.closeQuietly(connection); DbUtils.closeQuietly(tables); } return null; }
From source file:org.culturegraph.mf.sql.util.JdbcUtil.java
public static ResultSet getTableMetadata(Connection jdbcConnection, String tableNamePattern, String schema, String catalog, boolean isQuoted) { ResultSet rs = null;/*w w w .ja v a 2 s . com*/ try { DatabaseMetaData meta = jdbcConnection.getMetaData(); if ((isQuoted && meta.storesMixedCaseQuotedIdentifiers())) { rs = meta.getTables(catalog, schema, tableNamePattern, TYPES); } else if ((isQuoted && meta.storesUpperCaseQuotedIdentifiers()) || (!isQuoted && meta.storesUpperCaseIdentifiers())) { rs = meta.getTables(StringHelper.toUpperCase(catalog), StringHelper.toUpperCase(schema), StringHelper.toUpperCase(tableNamePattern), TYPES); } else if ((isQuoted && meta.storesLowerCaseQuotedIdentifiers()) || (!isQuoted && meta.storesLowerCaseIdentifiers())) { rs = meta.getTables(StringHelper.toLowerCase(catalog), StringHelper.toLowerCase(schema), StringHelper.toLowerCase(tableNamePattern), TYPES); } else { rs = meta.getTables(catalog, schema, tableNamePattern, TYPES); } return rs; // while (rs.next()) { // String tableName = rs.getString("TABLE_NAME"); // System.out.println("table = " + tableName); // } } catch (SQLException sqlException) { sqlException.printStackTrace(); } finally { try { DbUtils.close(rs); } catch (SQLException e) { e.printStackTrace(); } } return null; }
From source file:org.dashbuilder.dataprovider.backend.sql.JDBCUtils.java
public static String fixCase(Connection connection, String id) { try {/*from ww w . java2 s . c o m*/ DatabaseMetaData meta = connection.getMetaData(); if (meta.storesLowerCaseIdentifiers()) { return changeCaseExcludeQuotes(id, false); } if (meta.storesUpperCaseIdentifiers()) { return changeCaseExcludeQuotes(id, true); } } catch (SQLException e) { e.printStackTrace(); } return id; }