Java Code Examples for org.hsqldb.jdbc.JDBCConnection

The following examples show how to use org.hsqldb.jdbc.JDBCConnection. These examples are extracted from open source projects. 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 Project: evosql   Source File: JDBCXAConnectionWrapper.java    License: Apache License 2.0 6 votes vote down vote up
public JDBCXAConnectionWrapper(JDBCXAResource xaResource,
                               JDBCXAConnection xaConnection,
                               JDBCConnection databaseConnection)
                               throws SQLException {
    // todo: Review JDBCXADataSource and this class.
    //       Under current implementation, because we do not pass a
    //       JDBCXAConnection instance to the constructor to pick
    //       up the connectionClosed event listener callback, calling
    //       close() on this wrapper connection does not reset the
    //       physical connection or set the inUse flag to false until
    //       the vending JDBCXAConnection itself is closed, which marks
    //       the end of its useful life.
    //
    //       In other words, due to this current implementation detail,
    //       JDBCXADataSource cannot cooperate with a pooling implementation
    //       to reuse physical connections.
    //       fixed - the event listener works
    super(databaseConnection, xaConnection);

    xaResource.setConnection(this);

    this.xaResource = xaResource;
}
 
Example 2
Source Project: evosql   Source File: JDBCXADataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
     * Get new XAConnection connection, to be managed by a connection manager.
     */
    public XAConnection getXAConnection() throws SQLException {

        // Comment out before public release:
/*
        System.err.print("Executing " + getClass().getName()
                         + ".getXAConnection()...");
*/

        // Use JDBCDriver directly so there is no need to register with DriverManager
        JDBCConnection connection =
            (JDBCConnection) JDBCDriver.getConnection(url, connectionProps);
        JDBCXAConnection xaConnection = new JDBCXAConnection(this, connection);

        return xaConnection;
    }
 
Example 3
Source Project: raccoon4   Source File: DatabaseManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Called by DAOs to get a connection object
 * 
 * @return a connection connection from the pool. The connection should be
 *         returned using disconnect() after doing it's unit of work.
 */
public Connection connect() {
	if (pool.isEmpty()) {
		try {
			// Speedhack: The proper way of creating a connection is by looking it
			// up via JDBC url. However, that's time consuming and we need the
			// connection ASAP.
			return new JDBCConnection(props);
		}
		catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
	}
	return pool.pop();
}
 
Example 4
Source Project: evosql   Source File: TestJavaFunctions.java    License: Apache License 2.0 5 votes vote down vote up
public static ResultSet getCustomResult(Connection connection, long start,
        long end) throws SQLException {

    Result result = newTwoColumnResult();

    if (end < start) {
        long temp = start;

        start = end;
        end   = temp;
    }

    if (end > 1000) {
        throw org.hsqldb.jdbc.JDBCUtil.invalidArgument(
            "value larger than 100");
    }

    if (end > start + 100) {
        end = start + 100;
    }

    for (long i = start; i < end; i++) {
        Object[] row = new Object[2];

        row[0] = Long.valueOf(i);
        row[1] = new BinaryData(BigInteger.valueOf(i).toByteArray(),
                                false);

        result.navigator.add(row);
    }

    result.navigator.reset();

    return new JDBCResultSet((JDBCConnection) connection, null, result,
                             result.metaData);
}
 
Example 5
Source Project: raccoon4   Source File: DatabaseManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a new manager.
 * 
 * @param databaseDir
 *          directory to keep the files in.
 * @throws SQLException
 *           if the DAO table cannot be initialized.
 */
public DatabaseManager(File databaseDir) throws SQLException {
	pool = new Stack<Connection>();
	props = new HsqlProperties();
	props.setProperty("connection_type", "file:");
	props.setProperty("database",
			new File(databaseDir, DBNAME).getAbsolutePath());
	daos = new HashMap<Class<?>, Object>();
	daoversions = new HashMap<String, Integer>();

	Connection c = new JDBCConnection(props);
	Statement st = null;
	ResultSet res = null;
	try {
		// Load the DAO version table
		st = c.createStatement();
		st.execute("CREATE TABLE IF NOT EXISTS versions (dao VARCHAR(255), version INT)");
		st.close();

		st = c.createStatement();
		st.execute("SELECT dao, version FROM versions");
		res = st.getResultSet();
		while (res.next()) {
			daoversions.put(res.getString(1), res.getInt(2));
		}
	}
	finally {
		if (res != null) {
			res.close();
		}
		if (st != null) {
			st.close();
		}
		pool.push(c);
	}
}
 
Example 6
Source Project: tomee   Source File: DataSourceDefinitionGlobalJPATest.java    License: Apache License 2.0 5 votes vote down vote up
private void check(final DataSource ds, final String name) throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    // the first "cast part" is not important, we just want to check the jdbc url is ok
    assertThat(ds, instanceOf(BasicManagedDataSource.class));
    final BasicManagedDataSource dbcp = (BasicManagedDataSource) ds;
    final Connection connection = dbcp.getConnection();
    assertThat(connection, instanceOf(ManagedConnection.class));
    final ManagedConnection mc = (ManagedConnection) connection;
    final Method getInnermostDelegateInternal = DelegatingConnection.class.getDeclaredMethod("getInnermostDelegateInternal");
    getInnermostDelegateInternal.setAccessible(true);
    final Connection delegate = (Connection) getInnermostDelegateInternal.invoke(mc);
    assertThat(delegate, instanceOf(JDBCConnection.class));
    final Method getURL = JDBCConnection.class.getDeclaredMethod("getURL");
    getURL.setAccessible(true);
    assertEquals("jdbc:hsqldb:mem:" + name, getURL.invoke(delegate));
}
 
Example 7
Source Project: tomee   Source File: DataSourceDefinitionJndiTest.java    License: Apache License 2.0 5 votes vote down vote up
private void check(final DataSource ds, final String name) throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    // the first "cast part" is not important, we just want to check the jdbc url is ok
    assertThat(ds, instanceOf(DbcpManagedDataSource.class));
    final DbcpManagedDataSource dbcp = (DbcpManagedDataSource) ds;
    final Connection connection = dbcp.getConnection();
    assertThat(connection, instanceOf(ManagedConnection.class));
    final ManagedConnection mc = (ManagedConnection) connection;
    final Method getInnermostDelegateInternal = DelegatingConnection.class.getDeclaredMethod("getInnermostDelegateInternal");
    getInnermostDelegateInternal.setAccessible(true);
    final Connection delegate = (Connection) getInnermostDelegateInternal.invoke(mc);
    assertThat(delegate, instanceOf(JDBCConnection.class));
    final Method getURL = JDBCConnection.class.getDeclaredMethod("getURL");
    getURL.setAccessible(true);
    assertEquals("jdbc:hsqldb:mem:" + name, getURL.invoke(delegate));
}
 
Example 8
@Test
public void testMetadataForClassHierarchy() {
  new MockUp<JDBCConnection>() {
    @Mock
    public DatabaseMetaData getMetaData() throws SQLException {
      return new CustomDatabaseMetadata(
          (JDBCConnection) sqlLine.getConnection());
    }
  };

  try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
    SqlLine.Status status =
        begin(sqlLine, os, false, "-e", "!set maxwidth 80");
    assertThat(status, equalTo(SqlLine.Status.OK));
    DispatchCallback dc = new DispatchCallback();
    sqlLine.runCommands(dc, "!connect "
        + ConnectionSpec.HSQLDB.url + " \""
        + ConnectionSpec.HSQLDB.username + "\" \""
        + ConnectionSpec.HSQLDB.password + "\"");
    os.reset();
    sqlLine.runCommands(dc, "!tables");
    String output = os.toString("UTF8");
    assertThat(output,
        allOf(containsString("TABLE_CAT"),
            not(containsString("No such method \"getTables\""))));
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Source Project: evosql   Source File: Session.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the external JDBC connection
 */
public JDBCConnection getJDBCConnection() {
    return extConnection;
}
 
Example 10
Source Project: evosql   Source File: Session.java    License: Apache License 2.0 4 votes vote down vote up
public void setJDBCConnection(JDBCConnection connection) {
    extConnection = connection;
}
 
Example 11
Source Project: evosql   Source File: JDBCXAResource.java    License: Apache License 2.0 4 votes vote down vote up
JDBCConnection getConnection() {
    return this.connection;
}
 
Example 12
Source Project: evosql   Source File: JDBCXAResource.java    License: Apache License 2.0 4 votes vote down vote up
void setConnection(JDBCConnection userConnection) {
    connection = userConnection;
}
 
Example 13
Source Project: evosql   Source File: JDBCXAConnection.java    License: Apache License 2.0 4 votes vote down vote up
public JDBCXAConnection(JDBCXADataSource dataSource, JDBCConnection connection) {

        super(connection);
        xaResource = new JDBCXAResource(dataSource, connection);
    }
 
Example 14
Source Project: evosql   Source File: JDBCPooledConnection.java    License: Apache License 2.0 4 votes vote down vote up
public JDBCPooledConnection(JDBCConnection connection) {
    this.connection = connection;
}
 
Example 15
Source Project: evosql   Source File: ClientConnection.java    License: Apache License 2.0 4 votes vote down vote up
public JDBCConnection getJDBCConnection() {
    return connection;
}
 
Example 16
Source Project: evosql   Source File: ClientConnection.java    License: Apache License 2.0 4 votes vote down vote up
public void setJDBCConnection(JDBCConnection connection) {
    this.connection = connection;
}
 
Example 17
Source Project: mybaties   Source File: PooledDataSourceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void ShouldReturnRealConnection() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  Connection c = ds.getConnection();
  JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
}
 
Example 18
Source Project: mybatis   Source File: PooledDataSourceTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void ShouldReturnRealConnection() throws Exception {
  PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
  Connection c = ds.getConnection();
  JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
}
 
Example 19
Source Project: evosql   Source File: JDBCPooledDataSource.java    License: Apache License 2.0 3 votes vote down vote up
public PooledConnection getPooledConnection() throws SQLException {

        JDBCConnection connection =
            (JDBCConnection) JDBCDriver.getConnection(url, connectionProps);

        return new JDBCPooledConnection(connection);
    }
 
Example 20
Source Project: evosql   Source File: JDBCPooledDataSource.java    License: Apache License 2.0 3 votes vote down vote up
public PooledConnection getPooledConnection(String user,
        String password) throws SQLException {

    Properties props = new Properties();

    props.setProperty("user", user);
    props.setProperty("password", password);

    JDBCConnection connection =
        (JDBCConnection) JDBCDriver.getConnection(url, props);

    return new JDBCPooledConnection(connection);
}
 
Example 21
Source Project: evosql   Source File: JDBCPooledConnection.java    License: Apache License 2.0 3 votes vote down vote up
synchronized public Connection getConnection() throws SQLException {

        if (isInUse) {
            throw new SQLException("Connection in use");
        }

        isInUse = true;

        userConnection = new JDBCConnection(connection, this);

        return userConnection;
    }
 
Example 22
Source Project: evosql   Source File: TestPeriodPredicates.java    License: Apache License 2.0 3 votes vote down vote up
protected void setUp() throws Exception {

        super.setUp();

        conn    = super.newConnection();
        session = (Session) ((JDBCConnection) conn).getSession();
    }
 
Example 23
Source Project: evosql   Source File: JDBCXAResource.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a resource using the given data source and connection.
 *
 * @param xaDataSource JDBCXADataSource
 * @param connection A non-wrapped JDBCConnection which we need in order to
 *   do real (non-wrapped) commits, rollbacks, etc. This is not for the end
 *   user. We need the real thing.
 */
public JDBCXAResource(JDBCXADataSource xaDataSource,
                      JDBCConnection connection) {
    this.connection   = connection;
    this.xaDataSource = xaDataSource;
}
 
Example 24
Source Project: evosql   Source File: SessionInterface.java    License: Apache License 2.0 votes vote down vote up
JDBCConnection getJDBCConnection(); 
Example 25
Source Project: evosql   Source File: SessionInterface.java    License: Apache License 2.0 votes vote down vote up
void setJDBCConnection(JDBCConnection connection);