/** * Allows the changing of the BatchWriter that this ObjectStoreWriter uses. * * @param batchWriter the new BatchWriter - use BatchWriterSimpleImpl for writers likely to see * small batches, and optimised (eg BatchWriterPostgresCopyImpl) implementations for bulk-write * writers. * @throws ObjectStoreException if something goes wrong */ public void setBatchWriter(BatchWriter batchWriter) throws ObjectStoreException { Connection c = null; try { c = getConnection(); // Must get connection - it is our concurrency control. batch.setBatchWriter(batchWriter); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
private Connection getConnection() throws SQLException { ObjectStoreWriterInterMineImpl uosw = (ObjectStoreWriterInterMineImpl) osw; return uosw.getDatabase().getConnection(); }
/** * {@inheritDoc} */ @Override public ObjectStoreWriterInterMineImpl getNewWriter() throws ObjectStoreException { return new ObjectStoreWriterInterMineImpl(this); }
/** * {@inheritDoc} */ @Override public void abortTransaction() throws ObjectStoreException { Connection c = null; try { c = getConnection(); abortTransactionWithConnection(c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void batchCommitTransaction() throws ObjectStoreException { Connection c = null; try { c = getConnection(); batchCommitTransactionWithConnection(c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void store(Object o) throws ObjectStoreException { Connection c = null; try { c = getConnection(); storeWithConnection(c, o); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
boolean wasInTransaction = isInTransactionWithConnection(c); if (!wasInTransaction) { beginTransactionWithConnection(c); if (!wasInTransaction) { try { commitTransactionWithConnection(c); } catch (ObjectStoreException e) { abortTransactionWithConnection(c); throw e;
boolean wasInTransaction = isInTransactionWithConnection(c); if (!wasInTransaction) { beginTransactionWithConnection(c); if (getMinBagTableSize() != -1) { createTempBagTables(c, query); flushOldTempBagTables(c); if (everOptimise()) { PrecomputedTable pt = (PrecomputedTable) goFasterMap.get(query); BestQuery bestQuery; registerStatement(s); try { String alias = query.getAliases().get(query.getSelect().get(0)); tablesAltered.add(INT_BAG_TABLE_NAME); } finally { deregisterStatement(s); if (!wasInTransaction) { try { commitTransactionWithConnection(c); } catch (ObjectStoreException e) { abortTransactionWithConnection(c); throw e;
/** * {@inheritDoc} */ @Override public void delete(InterMineObject o) throws ObjectStoreException { Connection c = null; try { c = getConnection(); deleteWithConnection(c, o); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
boolean wasInTransaction = isInTransactionWithConnection(c); if (!wasInTransaction) { beginTransactionWithConnection(c); boolean doDeletes = (o instanceof InterMineObject ? populateIds(c, (InterMineObject) o) : false); writePendingClobs(c, o); StringConstructor xml = null; String objectClass = null; TableInfo tableInfo = getTableInfo(tableMaster); Set<CollectionDescriptor> collections = tableToCollections.get(cld.getName()); if (collections == null) { writeCollections(c, o, collections); invalidateObjectById(((InterMineObject) o).getId()); if (!wasInTransaction) { try { commitTransactionWithConnection(c); } catch (ObjectStoreException e) { abortTransactionWithConnection(c); throw e;
/** * {@inheritDoc} * * This method is overridden in order to flush batches properly before the read. */ @Override public int count(Query q, Map<Object, Integer> sequence) throws ObjectStoreException { Connection c = null; try { c = getConnection(); Set<String> readTables = SqlGenerator.findTableNames(q, getSchema()); batch.flush(c, readTables); return countWithConnection(c, q, 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 flush batches properly before the read. */ @Override public List<ResultsRow<Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, Map<Object, Integer> sequence) throws ObjectStoreException { Connection c = null; try { c = getConnection(); Set<String> readTables = SqlGenerator.findTableNames(q, getSchema()); batch.flush(c, readTables); 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 flush matches properly before the read. */ @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(); String readTable = SqlGenerator.tableNameForId(clazz, getSchema()); batch.flush(c, Collections.singleton(readTable)); return internalGetObjectByIdWithConnection(c, id, clazz); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void addToBagFromQuery(ObjectStoreBag osb, Query query) throws ObjectStoreException { List<QuerySelectable> select = query.getSelect(); if (select.size() != 1) { throw new IllegalArgumentException("Query has incorrect number of SELECT elements."); } Class<?> type = select.get(0).getType(); if (!(Integer.class.equals(type) || InterMineObject.class.isAssignableFrom(type))) { throw new IllegalArgumentException("The type of the result colum (" + type.getName() + ") is not an Integer or InterMineObject"); } try { Connection c = null; try { c = getConnection(); Set<String> readTables = SqlGenerator.findTableNames(query, getSchema()); readTables.add(INT_BAG_TABLE_NAME); batch.flush(c, readTables); addToBagFromQueryWithConnection(c, osb, query); } finally { releaseConnection(c); } } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } }
public void run() { try { ObjectStoreWriterInterMineImpl w = (ObjectStoreWriterInterMineImpl)ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest"); Connection c = w.getConnection(); try { w.close(); fail("Expected an ObjectStoreException"); } catch (ObjectStoreException e) { Assert.assertEquals("Closed ObjectStoreWriter while it is being used. Note this writer will be automatically closed when the current operation finishes", e.getMessage()); } w.releaseConnection(c); signalFinished(null); } catch (Throwable e) { System.out.println("Error in ShutdownThread: " + e); signalFinished(e); } } }
/** * {@inheritDoc} */ @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { if (LoginTrackBinding.LOGINTRACKS.equals(qName)) { try { connection = ((ObjectStoreWriterInterMineImpl) osw).getConnection(); // Creating a login tracker will create an empty table if it doesn't exist LoginTracker.getInstance(connection, new LinkedList<Track>()); stm = connection.prepareStatement("INSERT INTO " + TrackerUtil.LOGIN_TRACKER_TABLE + " VALUES(?, ?)"); } catch (SQLException sqle) { throw new BuildException("Problem to retrieve the connection", sqle); } } if (LoginTrackBinding.LOGINTRACK.equals(qName)) { try { stm.setString(1, attrs.getValue("username")); stm.setTimestamp(2, Timestamp.valueOf(attrs.getValue("timestamp"))); stm.executeUpdate(); } catch (SQLException sqle) { throw new BuildException("problems during update", sqle); } } }
/** * {@inheritDoc} */ @Override public boolean isInTransaction() throws ObjectStoreException { Connection c = null; try { c = getConnection(); return isInTransactionWithConnection(c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void beginTransaction() throws ObjectStoreException { Connection c = null; try { c = getConnection(); beginTransactionWithConnection(c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void commitTransaction() throws ObjectStoreException { Connection c = null; try { c = getConnection(); commitTransactionWithConnection(c); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }
/** * {@inheritDoc} */ @Override public void addToCollection(Integer hasId, Class<?> clazz, String fieldName, Integer hadId) throws ObjectStoreException { Connection c = null; try { c = getConnection(); addToCollectionWithConnection(c, hasId, clazz, fieldName, hadId); } catch (SQLException e) { throw new ObjectStoreException("Could not get connection to database", e); } finally { releaseConnection(c); } }