Refine search
connectionPool = JdbcConnectionPool.create(databaseUrl, NF_USERNAME_PASSWORD, NF_USERNAME_PASSWORD); connectionPool.setMaxConnections(MAX_CONNECTIONS); try { connection = connectionPool.getConnection(); connection.setAutoCommit(false); statement = connection.createStatement(); rs = connection.getMetaData().getTables(null, null, "KEY", null); if (!rs.next()) { statement.execute(CREATE_KEY_TABLE);
public void shutdown() { // shutdown the connection pool if (connectionPool != null) { try { connectionPool.dispose(); } catch (Exception e) { logger.warn("Unable to dispose of connection pool: " + e.getMessage()); if (logger.isDebugEnabled()) { logger.warn(StringUtils.EMPTY, e); } } } }
/** * Constructs a new connection pool. * * @param dataSource the data source to create connections * @return the connection pool */ public static JdbcConnectionPool create(ConnectionPoolDataSource dataSource) { return new JdbcConnectionPool(dataSource); }
/** * @return Connection pool */ static JdbcConnectionPool createDataSource(int port) { JdbcConnectionPool pool = JdbcConnectionPool.create("jdbc:h2:tcp://localhost:" + port + "/mem:TestDb;LOCK_MODE=0", "sa", ""); pool.setMaxConnections(Integer.getInteger("H2_JDBC_CONNECTIONS", 100)); return pool; }
public void writeHead(Id id) throws Exception { Connection con = cp.getConnection(); try { PreparedStatement stmt = con.prepareStatement("update HEAD set ID=?"); stmt.setBytes(1, id.getBytes()); stmt.execute(); stmt.close(); } finally { con.close(); } }
@Override public void deleteJob(String jobFullName) { LOGGER.log(Level.FINER, "deleteJob({0})", new Object[]{jobFullName}); try (Connection cnn = jdbcConnectionPool.getConnection()) { cnn.setAutoCommit(false); try (PreparedStatement stmt = cnn.prepareStatement("DELETE FROM JENKINS_JOB WHERE FULL_NAME = ? AND JENKINS_MASTER_ID = ?")) { stmt.setString(1, jobFullName); stmt.setLong(2, getJenkinsMasterPrimaryKey(cnn)); int count = stmt.executeUpdate(); LOGGER.log(Level.FINE, "deleteJob({0}): {1}", new Object[]{jobFullName, count}); } cnn.commit(); } catch (SQLException e) { throw new RuntimeSqlException(e); } }
String sql = "update publishers set rtData=? where id=?"; JdbcConnectionPool pool = (JdbcConnectionPool)Common.databaseProxy.getDataSource(); Connection conn = pool.getConnection(); conn.setAutoCommit(true); PreparedStatement ps = conn.prepareStatement(sql); ps.executeUpdate(); ps.close(); conn.close(); return id; }else {
public void initialize(File homeDir) throws Exception { File dbDir = new File(homeDir, "db"); if (!dbDir.exists()) { dbDir.mkdirs(); } Driver.load(); String url = "jdbc:h2:" + dbDir.getCanonicalPath() + "/revs"; if (FAST) { url += ";log=0;undo_log=0"; } cp = JdbcConnectionPool.create(url, "sa", ""); cp.setMaxConnections(40); Connection con = cp.getConnection(); try { Statement stmt = con.createStatement(); stmt.execute("create table if not exists REVS(ID binary primary key, DATA binary, TIME timestamp)"); stmt.execute("create table if not exists NODES(ID binary primary key, DATA binary, TIME timestamp)"); stmt.execute("create table if not exists HEAD(ID binary) as select null"); stmt.execute("create sequence if not exists DATASTORE_ID"); /* DbBlobStore store = new DbBlobStore(); store.setConnectionPool(cp); blobStore = store; */ } finally { con.close(); } }
@Override public void cleanup() { try (Connection cnn = jdbcConnectionPool.getConnection()) { cnn.setAutoCommit(false); String sql = "DELETE FROM MAVEN_ARTIFACT WHERE ID NOT IN (SELECT DISTINCT ARTIFACT_ID FROM MAVEN_DEPENDENCY UNION SELECT DISTINCT ARTIFACT_ID FROM GENERATED_MAVEN_ARTIFACT)"; try (Statement stmt = cnn.createStatement()) { int count = stmt.executeUpdate(sql); LOGGER.log(Level.FINE, "cleanup(): {0}", new Object[]{count}); } cnn.commit(); } catch (SQLException e) { throw new RuntimeSqlException(e); } }
public void saveSentences(int docKey, List<String> sentences) { try (Connection connection = connectionPool.getConnection()) { String sql = "INSERT INTO SENTENCE_TABLE " + "(DOC_KEY, CONTENT)" + " VALUES (?,?)"; PreparedStatement employeeStmt = connection.prepareStatement(sql); for (String sentence : sentences) { if (sentence.length() >= 512) { continue; } employeeStmt.setInt(1, docKey); employeeStmt.setString(2, sentence); employeeStmt.addBatch(); } employeeStmt.executeBatch(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
public void generateTables() throws SQLException, IOException { String query = Resources.toString( Resources.getResource("corpus/corpus-schema.sql"), StandardCharsets.UTF_8); try (Connection connection = connectionPool.getConnection()) { Statement s = connection.createStatement(); s.execute(query); } }
@Override public void init(Map<String, String> args) throws SQLException { jdbcConnectionPool = JdbcConnectionPool.create(args.get("url"), args.getOrDefault("user", ""), args.getOrDefault("password", "")); try (Connection conn = jdbcConnectionPool.getConnection(); Statement stmt = conn.createStatement()) { stmt.execute("CREATE TABLE IF NOT EXISTS MQ_MSG(ADDR VARCHAR(1024),MSG_ID VARCHAR(32),MSG TEXT,CREATED_TIME TIMESTAMP ,PRIMARY KEY(MSG_ID))"); } }
@Override protected DataSource createDataSource() { return JdbcConnectionPool.create("jdbc:h2:mem:" + UUID.randomUUID(), "", ""); } }
/** * @return New {@link Connection} from {@link #dataSrc} * @throws SQLException if failed */ private Connection connection() throws SQLException { return dataSrc.getConnection(); }
/** * Closes all unused pooled connections. * Exceptions while closing are written to the log stream (if set). */ public synchronized void dispose() { if (isDisposed) { return; } isDisposed = true; for (PooledConnection aList : recycledConnections) { closeConnection(aList); } }
private synchronized void recycleConnection(PooledConnection pc) { if (isDisposed) { disposeConnection(pc); return; } if (activeConnections <= 0) { throw new AssertionError(); } activeConnections--; if (activeConnections < maxConnections) { recycledConnections.push(pc); } else { closeConnection(pc); } notifyAll(); }
private Id readHead() throws Exception { Connection con = cp.getConnection(); try { PreparedStatement stmt = con.prepareStatement("select * from HEAD"); ResultSet rs = stmt.executeQuery(); byte[] rawId = null; if (rs.next()) { rawId = rs.getBytes(1); } stmt.close(); return rawId == null ? null : new Id(rawId); } finally { con.close(); } }
@Override public void renameJob(String oldFullName, String newFullName) { LOGGER.log(Level.FINER, "renameJob({0}, {1})", new Object[]{oldFullName, newFullName}); try (Connection cnn = jdbcConnectionPool.getConnection()) { cnn.setAutoCommit(false); try (PreparedStatement stmt = cnn.prepareStatement("UPDATE JENKINS_JOB SET FULL_NAME = ? WHERE FULL_NAME = ? AND JENKINS_MASTER_ID = ?")) { stmt.setString(1, newFullName); stmt.setString(2, oldFullName); stmt.setLong(3, getJenkinsMasterPrimaryKey(cnn)); int count = stmt.executeUpdate(); LOGGER.log(Level.FINE, "renameJob({0}, {1}): {2}", new Object[]{oldFullName, newFullName, count}); } cnn.commit(); } catch (SQLException e) { throw new RuntimeSqlException(e); } }
final JdbcConnectionPool pool = JdbcConnectionPool.create(url, user, password); pool.setMaxConnections(maxPoolConnections); Connection con = null; con = pool.getConnection(); } finally { if (con != null) { con.close();