Java Code Examples for java.sql.Connection.getCatalog()

The following are Jave code examples for showing how to use getCatalog() of the java.sql.Connection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenDiabetes   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.toString());
            }
        }
    }
 
Example 2
Project: sstore-soft   File: ConnectionDefaults.java   View Source Code Vote up 5 votes
public ConnectionDefaults(Connection connection) throws SQLException {

        this.holdability          = connection.getHoldability();
        this.transactionIsolation = connection.getTransactionIsolation();
        this.isAutoCommit         = connection.getAutoCommit();
        this.isReadOnly           = connection.isReadOnly();
        this.catalog              = connection.getCatalog();
    }
 
Example 3
Project: sstore-soft   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.getMessage());
            }
        }
    }
 
Example 4
Project: ralasafe   File: DBUtil.java   View Source Code Vote up 5 votes
public static String getDefaultSchema(Connection conn) throws SQLException {
	String productName = getDatabaseProductName(conn);
	if (productName.equals(MYSQL) || productName.equals(SQLSERVER)) {
		return conn.getCatalog();
	} else {
		DatabaseMetaData metaData = conn.getMetaData();
		return metaData.getUserName();
	}
}
 
Example 5
Project: s-store   File: ConnectionDefaults.java   View Source Code Vote up 5 votes
public ConnectionDefaults(Connection connection) throws SQLException {

        this.holdability          = connection.getHoldability();
        this.transactionIsolation = connection.getTransactionIsolation();
        this.isAutoCommit         = connection.getAutoCommit();
        this.isReadOnly           = connection.isReadOnly();
        this.catalog              = connection.getCatalog();
    }
 
Example 6
Project: s-store   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.getMessage());
            }
        }
    }
 
Example 7
Project: dev-courses   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.toString());
            }
        }
    }
 
Example 8
Project: parabuild-ci   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.getMessage());
            }
        }
    }
 
Example 9
Project: parabuild-ci   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.getMessage());
            }
        }
    }
 
Example 10
Project: bdf2   File: DbJdbcUtils.java   View Source Code Vote up 5 votes
public static String getDefaultTableSchema(Connection conn) throws SQLException {
	String name = conn.getCatalog();
	if (conn.getMetaData().getURL().toLowerCase().contains("oracle")) {
		name = conn.getMetaData().getUserName();
	} else if (conn.getMetaData().getURL().toLowerCase().contains("sqlserver")) {
		name = null;
	}
	return name;
}
 
Example 11
Project: parabuild-ci   File: TransferDb.java   View Source Code Vote up 5 votes
TransferDb(Connection c, Traceable t) throws DataAccessPointException {

        super(t);

        conn = c;

        if (c != null) {
            String productLowerName;

            try {
                meta              = c.getMetaData();
                databaseToConvert = c.getCatalog();
                productLowerName  = meta.getDatabaseProductName();

                if (productLowerName == null) {
                    productLowerName = "";
                } else {
                    productLowerName = productLowerName.toLowerCase();
                }

                helper = HelperFactory.getHelper(productLowerName);

                helper.set(this, t, meta.getIdentifierQuoteString());
            } catch (SQLException e) {
                throw new DataAccessPointException(e.getMessage());
            }
        }
    }
 
Example 12
Project: calcite-avatica   File: RemoteMetaTest.java   View Source Code Vote up 5 votes
@Test public void testRemoteConnectionProperties() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    String id = conn.id;
    final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap;
    assertFalse("remote connection map should start ignorant", m.containsKey(id));
    // force creating a connection object on the remote side.
    try (final Statement stmt = conn.createStatement()) {
      assertTrue("creating a statement starts a local object.", m.containsKey(id));
      assertTrue(stmt.execute("select count(1) from EMP"));
    }
    Connection remoteConn = getConnection(FullyRemoteJdbcMetaFactory.getInstance(), id);
    final boolean defaultRO = remoteConn.isReadOnly();
    final boolean defaultAutoCommit = remoteConn.getAutoCommit();
    final String defaultCatalog = remoteConn.getCatalog();
    final String defaultSchema = remoteConn.getSchema();
    conn.setReadOnly(!defaultRO);
    assertTrue("local changes dirty local state", m.get(id).isDirty());
    assertEquals("remote connection has not been touched", defaultRO, remoteConn.isReadOnly());
    conn.setAutoCommit(!defaultAutoCommit);
    assertEquals("remote connection has not been touched",
        defaultAutoCommit, remoteConn.getAutoCommit());

    // further interaction with the connection will force a sync
    try (final Statement stmt = conn.createStatement()) {
      assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit());
      assertFalse("local values should be clean", m.get(id).isDirty());
    }
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 13
Project: calcite-avatica   File: AlternatingRemoteMetaTest.java   View Source Code Vote up 5 votes
@Test public void testRemoteConnectionProperties() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
    String id = conn.id;
    final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap;
    assertFalse("remote connection map should start ignorant", m.containsKey(id));
    // force creating a connection object on the remote side.
    try (final Statement stmt = conn.createStatement()) {
      assertTrue("creating a statement starts a local object.", m.containsKey(id));
      assertTrue(stmt.execute("select count(1) from EMP"));
    }
    Connection remoteConn = getConnection(FullyRemoteJdbcMetaFactory.getInstance(), id);
    final boolean defaultRO = remoteConn.isReadOnly();
    final boolean defaultAutoCommit = remoteConn.getAutoCommit();
    final String defaultCatalog = remoteConn.getCatalog();
    final String defaultSchema = remoteConn.getSchema();
    conn.setReadOnly(!defaultRO);
    assertTrue("local changes dirty local state", m.get(id).isDirty());
    assertEquals("remote connection has not been touched", defaultRO, remoteConn.isReadOnly());
    conn.setAutoCommit(!defaultAutoCommit);
    assertEquals("remote connection has not been touched",
        defaultAutoCommit, remoteConn.getAutoCommit());

    // further interaction with the connection will force a sync
    try (final Statement stmt = conn.createStatement()) {
      assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit());
      assertFalse("local values should be clean", m.get(id).isDirty());
    }
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
Example 14
Project: the-vigilantes   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#15570 - ReplicationConnection incorrectly copies state,
 * doesn't transfer connection context correctly when transitioning between
 * the same read-only states.
 * 
 * (note, this test will fail if the test user doesn't have permission to
 * "USE 'mysql'".
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug15570() throws Exception {
    Connection replConn = null;

    try {
        replConn = getMasterSlaveReplicationConnection();

        int masterConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        replConn.setReadOnly(false);

        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));

        String currentCatalog = replConn.getCatalog();

        replConn.setCatalog(currentCatalog);
        assertEquals(currentCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);

        int slaveConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        // The following test is okay for now, as the chance of MySQL wrapping the connection id counter during our testsuite is very small.
        // As per Bug#21286268 fix a Replication connection first initializes the Slaves sub-connection, then the Masters.
        assertTrue("Master id " + masterConnectionId + " is not newer than slave id " + slaveConnectionId, masterConnectionId > slaveConnectionId);

        assertEquals(currentCatalog, replConn.getCatalog());

        String newCatalog = "mysql";

        replConn.setCatalog(newCatalog);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(false);
        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));
    } finally {
        if (replConn != null) {
            replConn.close();
        }
    }
}
 
Example 15
Project: OpenVertretung   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#15570 - ReplicationConnection incorrectly copies state,
 * doesn't transfer connection context correctly when transitioning between
 * the same read-only states.
 * 
 * (note, this test will fail if the test user doesn't have permission to
 * "USE 'mysql'".
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug15570() throws Exception {
    Connection replConn = null;

    try {
        replConn = getMasterSlaveReplicationConnection();

        int masterConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        replConn.setReadOnly(false);

        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));

        String currentCatalog = replConn.getCatalog();

        replConn.setCatalog(currentCatalog);
        assertEquals(currentCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);

        int slaveConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        // The following test is okay for now, as the chance of MySQL wrapping the connection id counter during our testsuite is very small.
        // As per Bug#21286268 fix a Replication connection first initializes the Slaves sub-connection, then the Masters.
        assertTrue("Master id " + masterConnectionId + " is not newer than slave id " + slaveConnectionId, masterConnectionId > slaveConnectionId);

        assertEquals(currentCatalog, replConn.getCatalog());

        String newCatalog = "mysql";

        replConn.setCatalog(newCatalog);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(false);
        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));
    } finally {
        if (replConn != null) {
            replConn.close();
        }
    }
}
 
Example 16
Project: ProyectoPacientes   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#15570 - ReplicationConnection incorrectly copies state,
 * doesn't transfer connection context correctly when transitioning between
 * the same read-only states.
 * 
 * (note, this test will fail if the test user doesn't have permission to
 * "USE 'mysql'".
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug15570() throws Exception {
    Connection replConn = null;

    try {
        replConn = getMasterSlaveReplicationConnection();

        int masterConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        replConn.setReadOnly(false);

        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));

        String currentCatalog = replConn.getCatalog();

        replConn.setCatalog(currentCatalog);
        assertEquals(currentCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);

        int slaveConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        // The following test is okay for now, as the chance of MySQL wrapping the connection id counter during our testsuite is very small.
        // As per Bug#21286268 fix a Replication connection first initializes the Slaves sub-connection, then the Masters.
        assertTrue("Master id " + masterConnectionId + " is not newer than slave id " + slaveConnectionId, masterConnectionId > slaveConnectionId);

        assertEquals(currentCatalog, replConn.getCatalog());

        String newCatalog = "mysql";

        replConn.setCatalog(newCatalog);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(false);
        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));
    } finally {
        if (replConn != null) {
            replConn.close();
        }
    }
}
 
Example 17
Project: rdbms-to-graphql   File: DatabaseAnalyzer.java   View Source Code Vote up 4 votes
public DatabaseAnalyzer(Connection connection, String schema, TypeMap typeMap) throws SQLException {
  this.databaseMetadata = connection.getMetaData();
  this.schema = schema;
  this.catalog = connection.getCatalog();
  this.typeMap = typeMap;
}
 
Example 18
Project: BibliotecaPS   File: ConnectionRegressionTest.java   View Source Code Vote up 4 votes
/**
 * Tests fix for BUG#15570 - ReplicationConnection incorrectly copies state,
 * doesn't transfer connection context correctly when transitioning between
 * the same read-only states.
 * 
 * (note, this test will fail if the test user doesn't have permission to
 * "USE 'mysql'".
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug15570() throws Exception {
    Connection replConn = null;

    try {
        replConn = getMasterSlaveReplicationConnection();

        int masterConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        replConn.setReadOnly(false);

        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));

        String currentCatalog = replConn.getCatalog();

        replConn.setCatalog(currentCatalog);
        assertEquals(currentCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);

        int slaveConnectionId = Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString());

        // The following test is okay for now, as the chance of MySQL wrapping the connection id counter during our testsuite is very small.
        // As per Bug#21286268 fix a Replication connection first initializes the Slaves sub-connection, then the Masters.
        assertTrue("Master id " + masterConnectionId + " is not newer than slave id " + slaveConnectionId, masterConnectionId > slaveConnectionId);

        assertEquals(currentCatalog, replConn.getCatalog());

        String newCatalog = "mysql";

        replConn.setCatalog(newCatalog);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(true);
        assertEquals(newCatalog, replConn.getCatalog());

        replConn.setReadOnly(false);
        assertEquals(masterConnectionId, Integer.parseInt(getSingleIndexedValueWithQuery(replConn, 1, "SELECT CONNECTION_ID()").toString()));
    } finally {
        if (replConn != null) {
            replConn.close();
        }
    }
}
 
Example 19
Project: calcite-avatica   File: ConnectionPropertiesImpl.java   View Source Code Vote up 4 votes
public ConnectionPropertiesImpl(Connection conn) throws SQLException {
  this(conn.getAutoCommit(), conn.isReadOnly(), conn.getTransactionIsolation(),
      conn.getCatalog(), conn.getSchema());
}
 
Example 20
Project: cereebro   File: DataSourceRelationshipDetector.java   View Source Code Vote up 3 votes
/**
 * Extract a DataSource name, using a default one if necessary.
 * 
 * @param connection
 *            JDBC DataSource Connection.
 * @return a non-null DataSource name.
 * @throws SQLException
 *             if something goes wrong while extracting component info.
 */
protected String extractName(Connection connection) throws SQLException {
    String name = connection.getSchema();
    if (name == null) {
        name = connection.getCatalog();
    }
    return Optional.ofNullable(name).orElse(defaultName);
}