Java Code Examples for java.sql.DatabaseMetaData#supportsSchemasInTableDefinitions()
The following examples show how to use
java.sql.DatabaseMetaData#supportsSchemasInTableDefinitions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String defaultSchema) { fireConnectionStep(NbBundle.getMessage (ConnectAction.class, "ConnectionProgress_Schemas")); // NOI18N List<String> schemas = new ArrayList<String> (); try { DatabaseMetaData dbMetaData = dbcon.getJDBCConnection().getMetaData(); if (dbMetaData.supportsSchemasInTableDefinitions()) { ResultSet rs = dbMetaData.getSchemas(); if (rs != null) { while (rs.next()) { schemas.add(rs.getString(1).trim()); } } } } catch (SQLException exc) { String message = NbBundle.getMessage(ConnectAction.class, "ERR_UnableObtainSchemas", exc.getMessage()); // NOI18N DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE)); } return schemaPanel.setSchemas(schemas, defaultSchema); }
Example 2
Source File: ConnectUsingDriverAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String defaultSchema) { fireConnectionStep(NbBundle.getMessage (ConnectUsingDriverAction.class, "ConnectionProgress_Schemas")); // NOI18N List<String> schemas = new ArrayList<String>(); try { DatabaseMetaData dbMetaData = dbcon.getJDBCConnection().getMetaData(); if (dbMetaData.supportsSchemasInTableDefinitions()) { ResultSet rs = dbMetaData.getSchemas(); if (rs != null) { while (rs.next()) { schemas.add(rs.getString(1).trim()); } } } } catch (SQLException exc) { String message = NbBundle.getMessage(ConnectUsingDriverAction.class, "ERR_UnableObtainSchemas", exc.getMessage()); // NOI18N DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE)); } return schemaPanel.setSchemas(schemas, defaultSchema); }
Example 3
Source File: JdbcEnvironmentImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private NameQualifierSupport determineNameQualifierSupport(DatabaseMetaData databaseMetaData) throws SQLException { final boolean supportsCatalogs = databaseMetaData.supportsCatalogsInTableDefinitions(); final boolean supportsSchemas = databaseMetaData.supportsSchemasInTableDefinitions(); if ( supportsCatalogs && supportsSchemas ) { return NameQualifierSupport.BOTH; } else if ( supportsCatalogs ) { return NameQualifierSupport.CATALOG; } else if ( supportsSchemas ) { return NameQualifierSupport.SCHEMA; } else { return NameQualifierSupport.NONE; } }
Example 4
Source File: DatabaseUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
public String getSchemaName(DatabaseMetaData dbData) throws SQLException { if (!isLegacy && this.datasourceInfo.getUseSchemas() && dbData.supportsSchemasInTableDefinitions()) { if (UtilValidate.isNotEmpty(this.datasourceInfo.getSchemaName())) { if (dbData.storesLowerCaseIdentifiers()) { return this.datasourceInfo.getSchemaName().toLowerCase(); } else if (dbData.storesUpperCaseIdentifiers()) { return this.datasourceInfo.getSchemaName().toUpperCase(); } else { return this.datasourceInfo.getSchemaName(); } } else { return dbData.getUserName(); } } return null; }
Example 5
Source File: JdbcDataSourceDialog.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private String performQuerySchema( final Connection conn ) { String schema = null; try { final DatabaseMetaData data = conn.getMetaData(); final boolean isHsql = ( "HSQL Database Engine".equals( data.getDatabaseProductName() ) ); if ( data.supportsSchemasInTableDefinitions() ) { final LinkedMap schemas = new LinkedMap(); final ResultSet rs = data.getSchemas(); while ( rs.next() ) { final String schemaName = rs.getString( 1 ).trim(); if ( isHsql && "INFORMATION_SCHEMA".equals( schemaName ) ) { continue; } schemas.put( schemaName, Boolean.TRUE ); } rs.close(); // bring up schema selection dialog only if preferences is set final String[] schemasArray = (String[]) schemas.keys( new String[schemas.size()] ); if ( schemas.size() > 1 ) { final Preferences properties = Preferences.userRoot().node( "org/pentaho/reporting/ui/datasources/jdbc/Settings" ); // NON-NLS if ( properties.getBoolean( "show-schema-dialog", false ) ) { final SchemaSelectionDialog schemaSelectionDialog = new SchemaSelectionDialog( JdbcDataSourceDialog.this, schemasArray ); schema = schemaSelectionDialog.getSchema(); } } else if ( schemas.size() == 1 ) { // Usually PUBLIC schema schema = schemasArray[0]; } } } catch ( Exception ex ) { logger.warn( "Error on InvokeQueryDesignerAction.performQuerySchema()", ex ); } return schema; }
Example 6
Source File: ScriptRunner.java From sis with Apache License 2.0 | 4 votes |
/** * Creates a new runner which will execute the statements using the given connection. * * <p>Some {@code maxRowsPerInsert} parameter values of interest:</p> * <ul> * <li>A value of 0 means to create only the schemas without inserting any data in them.</li> * <li>A value of 1 means to use one separated {@code INSERT INTO} statement for each row, which may be slow.</li> * <li>A value of 100 is a value which have been found empirically as giving good results.</li> * <li>A value of {@link Integer#MAX_VALUE} means to not perform any attempt to limit the number of rows in an * {@code INSERT INTO} statement. Note that this causes {@link StackOverflowError} in some JDBC driver.</li> * </ul> * * @param connection the connection to the database. * @param maxRowsPerInsert maximum number of rows per {@code "INSERT INTO"} statement. * @throws SQLException if an error occurred while creating a SQL statement. */ public ScriptRunner(final Connection connection, final int maxRowsPerInsert) throws SQLException { ArgumentChecks.ensureNonNull("connection", connection); ArgumentChecks.ensurePositive("maxRowsPerInsert", maxRowsPerInsert); final DatabaseMetaData metadata = connection.getMetaData(); this.maxRowsPerInsert = maxRowsPerInsert; this.dialect = Dialect.guess(metadata); this.identifierQuote = metadata.getIdentifierQuoteString(); this.isSchemaSupported = metadata.supportsSchemasInTableDefinitions() && metadata.supportsSchemasInDataManipulation(); this.isCatalogSupported = metadata.supportsCatalogsInTableDefinitions() && metadata.supportsCatalogsInDataManipulation(); this.statement = connection.createStatement(); switch (dialect) { default: { isEnumTypeSupported = false; isGrantOnSchemaSupported = false; isGrantOnTableSupported = false; isCreateLanguageRequired = false; isCommentSupported = false; break; } case POSTGRESQL: { final int version = metadata.getDatabaseMajorVersion(); isEnumTypeSupported = (version == 8) ? metadata.getDatabaseMinorVersion() >= 4 : version >= 8; isGrantOnSchemaSupported = true; isGrantOnTableSupported = true; isCreateLanguageRequired = (version < 9); isCommentSupported = true; break; } case HSQL: { isEnumTypeSupported = false; isGrantOnSchemaSupported = false; isGrantOnTableSupported = false; isCreateLanguageRequired = false; isCommentSupported = false; /* * HSQLDB stores tables in memory by default. For storing the tables on files, we have to * use "CREATE CACHED TABLE" statement, which is HSQL-specific. For avoiding SQL dialect, * the following statement change the default setting on current connection. * * Reference: http://hsqldb.org/doc/guide/dbproperties-chapt.html#dpc_db_props_url */ statement.execute("SET DATABASE DEFAULT TABLE TYPE CACHED"); break; } } /* * Now build the list of statements to skip, depending of which features are supported by the database. * WARNING: do not use capturing group here, because some subclasses (e.g. EPSGInstaller) will use their * own capturing groups. A non-capturing group is declared by "(?:A|B)" instead than a plain "(A|B)". */ if (!isEnumTypeSupported) { addStatementToSkip("CREATE\\s+(?:TYPE|CAST)\\s+.*"); } if (!isGrantOnSchemaSupported || !isGrantOnTableSupported) { addStatementToSkip("GRANT\\s+\\w+\\s+ON\\s+"); if (isGrantOnSchemaSupported) { regexOfStmtToSkip.append("TABLE"); } else if (isGrantOnTableSupported) { regexOfStmtToSkip.append("SCHEMA"); } else { regexOfStmtToSkip.append("(?:TABLE|SCHEMA)"); } regexOfStmtToSkip.append("\\s+.*"); } if (!isCommentSupported) { addStatementToSkip("COMMENT\\s+ON\\s+.*"); } }