public void optimize() throws DaoException { // Hack: wrap the datasource in a WpDataSource to access the helper method. // We don't close the WpDataSource because it doesn't own the connection. WpDataSource src = new WpDataSource(store.getDataSource()); src.optimize(SPATIAL_DB_NAME); }
/** * 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); } } }
/** * Executes a sql resource on the classpath * @param name Resource path - e.g. "/db/local-page.schema.sql" * @throws DaoException */ public void executeSqlResource(String name) throws DaoException { wpDs.executeSqlResource(name); }
/** * Optimizes the performance of the database for some table. * On postgres this translates to vacuum analyze. * On h2 it does nothing. */ public void optimize(Table table) throws DaoException { optimize(table.getName()); }
throw new DaoException(e); script = translateSqlScript(script); Connection conn=null; try { conn = getConnection(); for (String s : script.split(";")) { if (s.replaceAll(";", "").trim().isEmpty()) { rollbackQuietly(conn); LOG.error("error executing: " + script, 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);
public DSLContext getJooq() throws DaoException { try { return DSL.using(getConnection(), dialect, settings); } 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()); } }
public static WpDataSource getWpDataSource(File file) throws IOException, ClassNotFoundException, DaoException { return new WpDataSource(getDataSource(file)); }
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); } }
protected void freeJooq(DSLContext context) { wpDs.freeJooq(context); }
protected DSLContext getJooq() throws DaoException { return wpDs.getJooq(); }
/** * Rollback the current transaction. * If a SQLException occurs while rolling back, it logs the error and returns false, * but does not rethrow the exception. * * @param context */ public static boolean rollbackQuietly(DSLContext context) { if (context == null) { return false; } return WpDataSource.rollbackQuietly(getConnection(context)); }
@Override public void endLoad() throws DaoException { if (labelLoader != null) labelLoader.endLoad(); if (descLoader != null) descLoader.endLoad(); if (aliasLoader != null) aliasLoader.endLoad(); labelLoader = null; descLoader = null; aliasLoader = null; super.endLoad(); if (cache != null) { cache.put("wikidata-properties", properties); } wpDs.optimize(WIKIDATA_ENTITY_LABELS); wpDs.optimize(WIKIDATA_ENTITY_ALIASES); wpDs.optimize(WIKIDATA_ENTITY_DESCRIPTIONS); wpDs.optimize(WIKIDATA_STATEMENT); }
private void insertBatches() throws DaoException, SQLException, InterruptedException { boolean finished = false; Connection cnx = ds.getConnection(); if (isPostGisLoader){ try {
public static WpDataSource getWpDataSource() throws IOException, ClassNotFoundException, DaoException { return new WpDataSource(getDataSource()); }
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); } }
public void optimize() throws DaoException { // Hack: wrap the datasource in a WpDataSource to access the helper method. // We don't close the WpDataSource because it doesn't own the connection. WpDataSource src = new WpDataSource(store.getDataSource()); src.optimize(SPATIAL_DB_NAME); }
@Override public void endLoad() throws DaoException { if (labelLoader != null) labelLoader.endLoad(); if (descLoader != null) descLoader.endLoad(); if (aliasLoader != null) aliasLoader.endLoad(); labelLoader = null; descLoader = null; aliasLoader = null; super.endLoad(); if (cache != null) { cache.put("wikidata-properties", properties); } wpDs.optimize(WIKIDATA_ENTITY_LABELS); wpDs.optimize(WIKIDATA_ENTITY_ALIASES); wpDs.optimize(WIKIDATA_ENTITY_DESCRIPTIONS); wpDs.optimize(WIKIDATA_STATEMENT); }
/** * 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); } } } }
@Override public boolean runDiagnostic(PrintWriter writer) { Config config = null; try { config = env.getConfigurator().getConfig(WpDataSource.class, null); } catch (ConfigurationException e) { throw new IllegalStateException(e); } boolean passed = true; try { WpDataSource ds = env.getConfigurator().get(WpDataSource.class); ds.getConnection().close(); writer.write("Connection to database succeeded. Active configuration:\n"); } catch (Exception e) { writer.write("Connection to database FAILED! Active configuration:\n"); passed = false; } for (Map.Entry<String, ConfigValue > entry : config.entrySet()) { writer.write("\t" + entry.getKey() + ": " + entry.getValue().render() + "\n"); } return passed; } }
return new WpDataSource(ds); } catch (ClassNotFoundException e) { throw new ConfigurationException(e);