/** * {@inheritDoc} */ public int count(Query q, Map<Object, Integer> sequence) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return countWithConnection(c, q, sequence); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ public int count(Query q, Map<Object, Integer> sequence) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return countWithConnection(c, q, sequence); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ public ResultsInfo estimate(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return estimateWithConnection(c, q); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ public ResultsInfo estimate(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return estimateWithConnection(c, q); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Creates a temporary bag table for the given BagConstraint. * * @param bagConstraint a BagConstraint * @throws ObjectStoreException if an error occurs */ public void createTempBagTable(ConstraintWithBag bagConstraint) throws ObjectStoreException { Connection c = null; try { c = getConnection(); createTempBagTable(c, bagConstraint, false, null); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Creates a temporary bag table for the given BagConstraint. * * @param bagConstraint a BagConstraint * @throws ObjectStoreException if an error occurs */ public void createTempBagTable(ConstraintWithBag bagConstraint) throws ObjectStoreException { Connection c = null; try { c = getConnection(); createTempBagTable(c, bagConstraint, false, null); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Generate sql from a Query * * @param q the Query * @return an SQL String * @throws ObjectStoreException if something goes wrong */ public String generateSql(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return generateSql(c, q, 0, Integer.MAX_VALUE); } catch (SQLException e) { throw new ObjectStoreException("Failed to get connection", e); } finally { releaseConnection(c); } }
/** * Gets an ID number which is unique in the database. * * @return an Integer * @throws ObjectStoreException if a problem occurs */ public Integer getSerial() throws ObjectStoreException { try { Connection c = null; try { c = getConnection(); return getSerialWithConnection(c); } finally { releaseConnection(c); } } catch (SQLException e) { throw new ObjectStoreException("Error generating serial number", e); } }
/** * Makes a certain Query go faster, using extra resources. The user should release * the resources later by calling releaseGoFaster on the same Query. Failure to release * resources may result in an overall degradation in performance. * * @param q the Query to speed up * @throws ObjectStoreException if something is wrong */ public void goFaster(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); goFasterWithConnection(q, c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Generate sql from a Query * * @param q the Query * @return an SQL String * @throws ObjectStoreException if something goes wrong */ public String generateSql(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return generateSql(c, q, 0, Integer.MAX_VALUE); } catch (SQLException e) { throw new ObjectStoreException("Failed to get connection", e); } finally { releaseConnection(c); } }
/** * Makes a certain Query go faster, using extra resources. The user should release * the resources later by calling releaseGoFaster on the same Query. Failure to release * resources may result in an overall degradation in performance. * * @param q the Query to speed up * @throws ObjectStoreException if something is wrong */ public void goFaster(Query q) throws ObjectStoreException { Connection c = null; try { c = getConnection(); goFasterWithConnection(q, c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Checks if a query is precomputed or not for the given type * * @param query the query * @param type the type * @return true if and only if the given query is (already) precomputed * @throws ObjectStoreException if the is a database problem */ public boolean isPrecomputed(Query query, String type) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return isPrecomputedWithConnection(c, query, type); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Checks if a query is precomputed or not for the given type * * @param query the query * @param type the type * @return true if and only if the given query is (already) precomputed * @throws ObjectStoreException if the is a database problem */ public boolean isPrecomputed(Query query, String type) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return isPrecomputedWithConnection(c, query, type); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * Gets an ID number which is unique in the database. * * @return an Integer * @throws ObjectStoreException if a problem occurs */ public Integer getSerial() throws ObjectStoreException { try { Connection c = null; try { c = getConnection(); return getSerialWithConnection(c); } finally { releaseConnection(c); } } catch (SQLException e) { throw new ObjectStoreException("Error generating serial number", e); } }
/** * Creates precomputed tables for the given query. * * @param q the Query for which to create the precomputed tables * @param indexes a Collection of QueryNodes for which to create indexes * @param allFields true if all fields of QueryClasses in the SELECT list should be included in * the precomputed table's SELECT list. If the indexes parameter is null, then indexes will * be created for every field as well * @param category a String describing the category of the precomputed tables * @return the names of the new precomputed tables * @throws ObjectStoreException if anything goes wrong */ public List<String> precompute(Query q, Collection<? extends QueryNode> indexes, boolean allFields, String category) throws ObjectStoreException { Connection c = null; try { c = getConnection(); return precomputeWithConnection(c, q, indexes, allFields, category); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ public List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, Map<Object, Integer> sequence) throws ObjectStoreException { Constraint where = q.getConstraint(); // we know there will be no results if we ORing or NANDing over an empty constraint set if (where instanceof ConstraintSet) { ConstraintSet where2 = (ConstraintSet) where; if (where2.getConstraints().isEmpty() && (ConstraintOp.NAND.equals(where2.getOp()) || ConstraintOp.OR.equals(where2.getOp()))) { return Collections.emptyList(); } } Connection c = null; try { c = getConnection(); return executeWithConnection(c, q, start, limit, optimise, explain, sequence); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} * * This method is overridden in order to improve the performance of the operation - this * implementation does not bother with the EXPLAIN call to the underlying SQL database. */ @Override protected InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { if (schema.isFlatMode(clazz)) { return super.internalGetObjectById(id, clazz); } Connection c = null; try { c = getConnection(); return internalGetObjectByIdWithConnection(c, id, clazz); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} * * This method is overridden in order to improve the performance of the operation - this * implementation does not bother with the EXPLAIN call to the underlying SQL database. */ @Override protected InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { if (schema.isFlatMode(clazz)) { return super.internalGetObjectById(id, clazz); } Connection c = null; try { c = getConnection(); return internalGetObjectByIdWithConnection(c, id, clazz); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
@Test public void testCancelMethods2() throws Exception { Object id = "flibble2"; Connection c = ((ObjectStoreInterMineImpl) os).getConnection(); try { Statement s = c.createStatement(); ((ObjectStoreInterMineImpl) os).registerRequestId(id); ((ObjectStoreInterMineImpl) os).registerStatement(s); ((ObjectStoreInterMineImpl) os).cancelRequest(id); ((ObjectStoreInterMineImpl) os).deregisterStatement(s); ((ObjectStoreInterMineImpl) os).deregisterRequestId(id); try { s.executeQuery("SELECT 1"); } catch (SQLException e) { e.printStackTrace(System.out); } } finally { ((ObjectStoreInterMineImpl) os).releaseConnection(c); } }
@Test public void testCancelMethods1() throws Exception { Object id = "flibble1"; Connection c = ((ObjectStoreInterMineImpl) os).getConnection(); try { Statement s = c.createStatement(); ((ObjectStoreInterMineImpl) os).registerRequestId(id); ((ObjectStoreInterMineImpl) os).registerStatement(s); ((ObjectStoreInterMineImpl) os).deregisterStatement(s); ((ObjectStoreInterMineImpl) os).deregisterRequestId(id); } finally { ((ObjectStoreInterMineImpl) os).releaseConnection(c); } }