public void freeJooq(DSLContext context) { Connection conn = JooqUtils.getConnection(context); if (conn != null) { try { if (!conn.getAutoCommit()) { conn.commit(); } } catch (SQLException e) { throw new RuntimeException(e); } closeQuietly(conn); } }
/** * In general, open connections are reclaimed and harmless */ public void close() throws IOException { if (dialect == SQLDialect.H2) { Statement stm = null; Connection cnx = null; try { cnx = getConnection(); stm = cnx.createStatement(); stm.execute("SHUTDOWN;"); stm.close(); } catch (SQLException e) { throw new IOException(e); } finally { closeQuietly(cnx); } } }
/** * Optimizes the performance of the database. * On postgres this translates to vacuum analyze. * On h2 it does nothing. */ public void optimize() throws DaoException { if (dialect == SQLDialect.POSTGRES) { Connection conn=null; try { conn = getConnection(); conn.setAutoCommit(true); Statement st = conn.createStatement(); st.execute("VACUUM ANALYZE VERBOSE;"); st.close(); } catch (SQLException e) { throw new DaoException(e); } finally { if (conn != null) { try { conn.setAutoCommit(true); } catch (Exception e) {} closeQuietly(conn); } } } }
/** * Optimizes the performance of the database for some table. * On postgres this translates to vacuum analyze. * On h2 it does nothing. */ public void optimize(String table) throws DaoException { if (dialect == SQLDialect.POSTGRES) { Connection conn=null; try { conn = getConnection(); conn.setAutoCommit(true); Statement st = conn.createStatement(); st.execute("VACUUM ANALYZE " + table); st.close(); } catch (SQLException e) { throw new DaoException(e); } finally { if (conn != null) { try { conn.setAutoCommit(true); } catch (Exception e) {} closeQuietly(conn); } } } }
throw new DaoException("SQL Dao Failed. Check if the table exists / if the desired information has been parsed and stored in the database\n" + e.toString()); } finally { closeQuietly(conn);
public WpDataSource(DataSource dataSource) throws DaoException { this.settings = new Settings(); this.dataSource = dataSource; Connection conn = null; try { conn = dataSource.getConnection(); this.dialect = JooqUtils.dialect(conn); } catch (SQLException e) { throw new DaoException("SQL Dao Failed. Check if the table exists / if the desired information has been parsed and stored in the database\n" + e.toString()); } finally { closeQuietly(conn); } // Postgres uses a lowercase "public" main schema if (this.dialect == SQLDialect.POSTGRES) { settings.setRenderNameStyle(RenderNameStyle.LOWER); } }