org.hsqldb.jdbc.JDBCConnection Java Examples

The following examples show how to use org.hsqldb.jdbc.JDBCConnection. 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: JDBCXAConnectionWrapper.java    From evosql with 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 File: DatabaseManager.java    From raccoon4 with 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 #3
Source File: JDBCXADataSource.java    From evosql with 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 #4
Source File: SqlLineArgsTest.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #5
Source File: DataSourceDefinitionJndiTest.java    From tomee with 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 #6
Source File: DataSourceDefinitionGlobalJPATest.java    From tomee with 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 File: DatabaseManager.java    From raccoon4 with 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 #8
Source File: TestJavaFunctions.java    From evosql with 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 #9
Source File: Session.java    From evosql with Apache License 2.0 4 votes vote down vote up
public void setJDBCConnection(JDBCConnection connection) {
    extConnection = connection;
}
 
Example #10
Source File: PooledDataSourceTest.java    From mybatis with 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 #11
Source File: PooledDataSourceTest.java    From mybaties with 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 #12
Source File: ClientConnection.java    From evosql with Apache License 2.0 4 votes vote down vote up
public void setJDBCConnection(JDBCConnection connection) {
    this.connection = connection;
}
 
Example #13
Source File: ClientConnection.java    From evosql with Apache License 2.0 4 votes vote down vote up
public JDBCConnection getJDBCConnection() {
    return connection;
}
 
Example #14
Source File: JDBCPooledConnection.java    From evosql with Apache License 2.0 4 votes vote down vote up
public JDBCPooledConnection(JDBCConnection connection) {
    this.connection = connection;
}
 
Example #15
Source File: JDBCXAConnection.java    From evosql with Apache License 2.0 4 votes vote down vote up
public JDBCXAConnection(JDBCXADataSource dataSource, JDBCConnection connection) {

        super(connection);
        xaResource = new JDBCXAResource(dataSource, connection);
    }
 
Example #16
Source File: JDBCXAResource.java    From evosql with Apache License 2.0 4 votes vote down vote up
void setConnection(JDBCConnection userConnection) {
    connection = userConnection;
}
 
Example #17
Source File: JDBCXAResource.java    From evosql with Apache License 2.0 4 votes vote down vote up
JDBCConnection getConnection() {
    return this.connection;
}
 
Example #18
Source File: Session.java    From evosql with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the external JDBC connection
 */
public JDBCConnection getJDBCConnection() {
    return extConnection;
}
 
Example #19
Source File: JDBCPooledConnection.java    From evosql with 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 #20
Source File: TestPeriodPredicates.java    From evosql with 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 #21
Source File: JDBCPooledDataSource.java    From evosql with 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 #22
Source File: JDBCPooledDataSource.java    From evosql with 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 #23
Source File: JDBCXAResource.java    From evosql with 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 File: SessionInterface.java    From evosql with Apache License 2.0 votes vote down vote up
void setJDBCConnection(JDBCConnection connection); 
Example #25
Source File: SessionInterface.java    From evosql with Apache License 2.0 votes vote down vote up
JDBCConnection getJDBCConnection();