Search in sources :

Example 1 with IConnectionProperties

use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.

the class FBConnectionTest method testCharacterSetJavaNoWarning.

/**
 * Test if explicitly specifying a connection character set does not add a warning (or exception) on the connection.
 */
@Test
public void testCharacterSetJavaNoWarning() throws Exception {
    Properties props = getDefaultPropertiesForConnection();
    props.remove("lc_ctype");
    props.setProperty("charSet", "Cp1254");
    try (Connection con = DriverManager.getConnection(getUrl(), props)) {
        SQLWarning warnings = con.getWarnings();
        assertNull("Expected no warning when specifying connection character set", warnings);
        IConnectionProperties connectionProperties = con.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
        assertEquals("Unexpected connection encoding", "WIN1254", connectionProperties.getEncoding());
    }
}
Also used : FBManagedConnection(org.firebirdsql.jaybird.xca.FBManagedConnection) JaybirdSystemProperties(org.firebirdsql.gds.JaybirdSystemProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Test(org.junit.Test)

Example 2 with IConnectionProperties

use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.

the class FBConnectionTest method testCharacterSetFirebirdNoWarning.

/**
 * Test if explicitly specifying a connection character set does not add a warning (or exception) on the connection.
 */
@Test
public void testCharacterSetFirebirdNoWarning() throws Exception {
    Properties props = getDefaultPropertiesForConnection();
    props.setProperty("lc_ctype", "WIN1252");
    try (Connection con = DriverManager.getConnection(getUrl(), props)) {
        SQLWarning warnings = con.getWarnings();
        assertNull("Expected no warning when specifying connection character set", warnings);
        IConnectionProperties connectionProperties = con.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
        assertEquals("Unexpected connection encoding", "WIN1252", connectionProperties.getEncoding());
    }
}
Also used : FBManagedConnection(org.firebirdsql.jaybird.xca.FBManagedConnection) JaybirdSystemProperties(org.firebirdsql.gds.JaybirdSystemProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Test(org.junit.Test)

Example 3 with IConnectionProperties

use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.

the class FBManager method dropDatabase.

@Override
public synchronized void dropDatabase(String fileName, String user, String password) throws Exception {
    checkStarted();
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        FbDatabase db = dbFactory.connect(connectionProperties);
        db.attach();
        db.dropDatabase();
    } catch (Exception e) {
        log.error("Exception dropping database", e);
        throw e;
    }
}
Also used : FbDatabase(org.firebirdsql.gds.ng.FbDatabase) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) SQLException(java.sql.SQLException)

Example 4 with IConnectionProperties

use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.

the class FBManager method isDatabaseExists.

@Override
public synchronized boolean isDatabaseExists(String fileName, String user, String password) throws Exception {
    checkStarted();
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        FbDatabase db = dbFactory.connect(connectionProperties);
        db.attach();
        db.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : FbDatabase(org.firebirdsql.gds.ng.FbDatabase) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) SQLException(java.sql.SQLException)

Example 5 with IConnectionProperties

use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.

the class FBManager method createDatabase.

// Meaningful management methods
@Override
public synchronized void createDatabase(String fileName, String user, String password) throws Exception {
    checkStarted();
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        FbDatabase db = dbFactory.connect(connectionProperties);
        db.attach();
        // otherwise exit, database already exists
        if (forceCreate)
            db.dropDatabase();
        else {
            db.close();
            // database exists, don't wipe it out.
            return;
        }
    } catch (SQLException e) {
    // we ignore it
    }
    try {
        IConnectionProperties connectionProperties = createDefaultConnectionProperties(user, password);
        connectionProperties.setDatabaseName(fileName);
        connectionProperties.setSqlDialect(dialect);
        if (getPageSize() != -1) {
            connectionProperties.setIntProperty("page_size", getPageSize());
        }
        if (getDefaultCharacterSet() != null) {
            connectionProperties.setProperty("set_db_charset", getDefaultCharacterSet());
        }
        if (forceWrite != null) {
            connectionProperties.setBooleanProperty("force_write", forceWrite);
        }
        try (FbDatabase db = dbFactory.connect(connectionProperties)) {
            db.createDatabase();
        }
    } catch (Exception e) {
        log.error("Exception creating database", e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) SQLException(java.sql.SQLException)

Aggregations

IConnectionProperties (org.firebirdsql.gds.ng.IConnectionProperties)7 Properties (java.util.Properties)4 FBTestProperties (org.firebirdsql.common.FBTestProperties)4 JaybirdSystemProperties (org.firebirdsql.gds.JaybirdSystemProperties)4 FBManagedConnection (org.firebirdsql.jaybird.xca.FBManagedConnection)4 Test (org.junit.Test)4 SQLException (java.sql.SQLException)3 FbDatabase (org.firebirdsql.gds.ng.FbDatabase)3