Search in sources :

Example 31 with User

use of org.h2.engine.User in project h2database by h2database.

the class JdbcDatabaseMetaData method getUDTs.

/**
 * Gets the list of user-defined data types.
 * This call returns an empty result set.
 *
 * <ol>
 * <li>TYPE_CAT (String) catalog</li>
 * <li>TYPE_SCHEM (String) schema</li>
 * <li>TYPE_NAME (String) type name</li>
 * <li>CLASS_NAME (String) Java class</li>
 * <li>DATA_TYPE (short) SQL Type - see also java.sql.Types</li>
 * <li>REMARKS (String) description</li>
 * <li>BASE_TYPE (short) base type - see also java.sql.Types</li>
 * </ol>
 *
 * @param catalog ignored
 * @param schemaPattern ignored
 * @param typeNamePattern ignored
 * @param types ignored
 * @return an empty result set
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getUDTs(" + quote(catalog) + ", " + quote(schemaPattern) + ", " + quote(typeNamePattern) + ", " + quoteIntArray(types) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "CAST(NULL AS VARCHAR) TYPE_CAT, " + "CAST(NULL AS VARCHAR) TYPE_SCHEM, " + "CAST(NULL AS VARCHAR) TYPE_NAME, " + "CAST(NULL AS VARCHAR) CLASS_NAME, " + "CAST(NULL AS SMALLINT) DATA_TYPE, " + "CAST(NULL AS VARCHAR) REMARKS, " + "CAST(NULL AS SMALLINT) BASE_TYPE " + "FROM DUAL WHERE FALSE");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 32 with User

use of org.h2.engine.User in project h2database by h2database.

the class JdbcDataSource method getJdbcConnection.

private JdbcConnection getJdbcConnection(String user, char[] password) throws SQLException {
    if (isDebugEnabled()) {
        debugCode("getJdbcConnection(" + quote(user) + ", new char[0]);");
    }
    Properties info = new Properties();
    info.setProperty("user", user);
    info.put("password", password);
    Connection conn = Driver.load().connect(url, info);
    if (conn == null) {
        throw new SQLException("No suitable driver found for " + url, "08001", 8001);
    } else if (!(conn instanceof JdbcConnection)) {
        throw new SQLException("Connecting with old version is not supported: " + url, "08001", 8001);
    }
    return (JdbcConnection) conn;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) JdbcConnection(org.h2.jdbc.JdbcConnection) JdbcConnection(org.h2.jdbc.JdbcConnection) Properties(java.util.Properties)

Example 33 with User

use of org.h2.engine.User in project h2database by h2database.

the class TestConnectionPool method testShutdown.

private void testShutdown() throws SQLException {
    String url = getURL("connectionPool2", true), user = getUser();
    String password = getPassword();
    JdbcConnectionPool cp = JdbcConnectionPool.create(url, user, password);
    StringWriter w = new StringWriter();
    cp.setLogWriter(new PrintWriter(w));
    Connection conn1 = cp.getConnection();
    Connection conn2 = cp.getConnection();
    conn1.close();
    conn2.createStatement().execute("shutdown immediately");
    cp.dispose();
    assertTrue(w.toString().length() > 0);
    cp.dispose();
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) StringWriter(java.io.StringWriter) Connection(java.sql.Connection) PrintWriter(java.io.PrintWriter)

Example 34 with User

use of org.h2.engine.User in project h2database by h2database.

the class TestConnectionPool method testUncommittedTransaction.

private void testUncommittedTransaction() throws SQLException {
    String url = getURL("connectionPool", true), user = getUser();
    String password = getPassword();
    JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
    assertEquals(30, man.getLoginTimeout());
    man.setLoginTimeout(1);
    assertEquals(1, man.getLoginTimeout());
    man.setLoginTimeout(0);
    assertEquals(30, man.getLoginTimeout());
    assertEquals(10, man.getMaxConnections());
    PrintWriter old = man.getLogWriter();
    PrintWriter pw = new PrintWriter(new StringWriter());
    man.setLogWriter(pw);
    assertTrue(pw == man.getLogWriter());
    man.setLogWriter(old);
    Connection conn1 = man.getConnection();
    assertTrue(conn1.getAutoCommit());
    conn1.setAutoCommit(false);
    conn1.close();
    assertTrue(conn1.isClosed());
    Connection conn2 = man.getConnection();
    assertTrue(conn2.getAutoCommit());
    conn2.close();
    man.dispose();
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) StringWriter(java.io.StringWriter) Connection(java.sql.Connection) PrintWriter(java.io.PrintWriter)

Example 35 with User

use of org.h2.engine.User in project h2database by h2database.

the class TestConnectionPool method testPerformance.

private void testPerformance() throws SQLException {
    String url = getURL("connectionPool", true), user = getUser();
    String password = getPassword();
    JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
    Connection conn = man.getConnection();
    int len = 1000;
    long time = System.nanoTime();
    for (int i = 0; i < len; i++) {
        man.getConnection().close();
    }
    man.dispose();
    trace((int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time));
    time = System.nanoTime();
    for (int i = 0; i < len; i++) {
        DriverManager.getConnection(url, user, password).close();
    }
    trace((int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time));
    conn.close();
}
Also used : JdbcConnectionPool(org.h2.jdbcx.JdbcConnectionPool) Connection(java.sql.Connection)

Aggregations

Connection (java.sql.Connection)36 SQLException (java.sql.SQLException)21 PreparedStatement (java.sql.PreparedStatement)17 Statement (java.sql.Statement)17 ResultSet (java.sql.ResultSet)16 Server (org.h2.tools.Server)15 DbException (org.h2.message.DbException)14 Column (org.h2.table.Column)12 ValueString (org.h2.value.ValueString)12 Properties (java.util.Properties)10 Database (org.h2.engine.Database)10 Schema (org.h2.schema.Schema)8 IOException (java.io.IOException)7 User (org.h2.engine.User)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 SimpleResultSet (org.h2.tools.SimpleResultSet)7 Value (org.h2.value.Value)7 PrintStream (java.io.PrintStream)6 Timestamp (java.sql.Timestamp)6 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)6