List of usage examples for org.hibernate Session clear
void clear();
From source file:edu.scripps.fl.pubchem.app.curves.CommitCurveStage.java
License:Apache License
@Override public void doSave(Object obj) throws StageException { Session session = getSession(); session.save(obj);//from w w w.j a v a2 s. co m session.flush(); session.clear(); }
From source file:edu.scripps.fl.pubchem.PubChemFactory.java
License:Apache License
public void populateAssayResults(Session session, PCAssay assay, InputStream is) throws Exception { long counter = 0L; PCAssayColumn activeColumn = assay.getActiveColumn(); List<PCAssayColumn> testedCols = assay.getTestedColumns(); CsvReader reader = new CsvReader(new BufferedReader(new InputStreamReader(is)), ','); reader.readHeaders();// w w w . j av a2 s . c o m String[] headers = reader.getHeaders(); Transaction trx = session.beginTransaction(); while (reader.readRecord()) { String[] values = reader.getValues(); String[] sids = reader.get("PUBCHEM_SID").split("\\s*,\\s*"); if (sids.length > 1) { log.warn(String.format("AID %s has %s SIDS on a line", assay.getAID(), sids.length)); } for (String sid : sids) { PCAssayResult result = new PCAssayResult(); result.setSID(Long.parseLong(sid)); String cid = reader.get("PUBCHEM_CID"); if (!"".equals(cid)) result.setCID(Long.parseLong(cid)); result.setComments(reader.get("PUBCHEM_ASSAYDATA_COMMENT")); int outcome = Integer.parseInt(reader.get("PUBCHEM_ACTIVITY_OUTCOME")); result.setOutcome(getOutcome(outcome)); String score = reader.get("PUBCHEM_ACTIVITY_SCORE"); if (!"".equals(score)) result.setRankScore(Integer.parseInt(score)); result.setURL(reader.get("PUBCHEM_ACTIVITY_URL")); result.setXref(reader.get("PUBCHEM_EXT_DATASOURCE_REGID")); // if a dose response assay with a marked activeConcentration if ("confirmatory".equals(assay.getActivityOutcomeMethod()) && activeColumn != null) { String actConc = reader.get("" + activeColumn.getTID()); if (!"".equals(actConc)) { result.setPrimaryValue(Double.valueOf(actConc)); result.setPrimaryColumn(activeColumn); PCAssayColumn qualCol = assay.getQualifierColumn(); if (qualCol != null) { String qual = reader.get("" + qualCol.getTID()); // get(String) if (!"".equals(qual)) result.setQualifier(qual); } } } else if ("screening".equals(assay.getActivityOutcomeMethod()) && testedCols.size() > 0) { PCAssayColumn testedCol = testedCols.get(0); String value = reader.get("" + testedCol.getTID()); result.setPrimaryColumn(testedCol); if (!"".equals(value)) if ("float".equals(testedCol.getType()) || "int".equals(testedCol.getType())) result.setPrimaryValue(Double.parseDouble(value)); else result.setPrimaryValueAsString(value); } // put all testedConcentration columns into an ordered array. // Interested in numbers here only. result.getTestedValues().clear(); for (int ii = 0; ii < testedCols.size(); ii++) { String value = reader.get("" + testedCols.get(ii).getTID()); try { Double dbl = Double.parseDouble(value); result.getTestedValues().set(ii, dbl); } catch (NumberFormatException ex) { // if not a number then don't worry about it. } } List<String> list = result.getAllValues(); list.clear(); for (PCAssayColumn col : assay.getColumns()) { if (col.getTID() > 0) { // not the outcome and score String value = reader.get("" + col.getTID()); list.set(col.getTID() - 1, value); } } result.setAssay(assay); session.save(result); if (++counter % 100 == 0) { trx.commit(); session.clear(); // else huge build up of hibernate memory // cache trx = session.beginTransaction(); } if (counter % 10000 == 0) log.debug(String.format("AID %s: processed %s results", assay.getAID(), counter)); } } log.debug(String.format("Processed AID: %s, contained %s results", assay.getAID(), counter)); assay = (PCAssay) session.merge(assay); assay.setVersionChanged(false); session.save(assay); trx.commit(); }
From source file:edu.scripps.fl.pubchem.PubChemFactory.java
License:Apache License
public int populateRelations(Session session, Document document) throws IOException, DocumentException { String fromDb = document.selectSingleNode("/eLinkResult/LinkSet/DbFrom").getText(); String idStr = document.selectSingleNode("/eLinkResult/LinkSet/IdList/Id").getText(); Long id = Long.parseLong(idStr); List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb"); Transaction trx = session.beginTransaction(); int counter = 0; for (Node linkSetDb : linkSetDbs) { String toDb = linkSetDb.selectSingleNode("DbTo").getText(); String linkName = linkSetDb.selectSingleNode("LinkName").getText(); List<Node> ids = linkSetDb.selectNodes("Link/Id"); for (Node idNode : ids) { long relatedId = Long.parseLong(idNode.getText()); if (id == relatedId) continue; Relation relation = new Relation(); relation.setRelationName(linkName); relation.setFromDb(fromDb);//from w w w.j a v a 2 s . c o m relation.setFromId(id); relation.setToDb(toDb); relation.setToId(relatedId); session.save(relation); if (counter++ % 100 == 0) { trx.commit(); session.clear(); // cache grows hugely during very large // inserts trx = session.beginTransaction(); } } } trx.commit(); return counter; }
From source file:edu.utah.further.ds.impl.service.query.processor.PageFinalizerHibernateQp.java
License:Apache License
/** * @param request//from w w w. jav a 2s .c o m * @return * @see edu.utah.further.core.api.chain.RequestProcessor#process(edu.utah.further.core.api.chain.ChainRequest) */ @Override public boolean process(final ChainRequest request) { // Read inputs from chain request final QueryContext queryContext = request.getAttribute(QUERY_CONTEXT); final List<?> resultPage = request.getAttribute(QUERY_RESULT); final PagingLoopController controller = request.getAttribute(AttributeName.PAGING_LOOP_CONTROLLER); // Perform finalization logic // In the future pass only selected attributes to the delegate. For simplicity, // pass all of them for now. final QueryContext newQueryContext = getDelegate().finalizePage(queryContext, resultPage, controller); // Clear persistent session final SessionFactory sessionFactory = request.getAttribute(SESSION_FACTORY); final Session session = sessionFactory.getCurrentSession(); // Flush the current page's batch of reads, inserts and updates and release memory session.flush(); session.clear(); // Save results in the chain request request.setAttribute(QUERY_CONTEXT, newQueryContext); return false; }
From source file:edu.wustl.cab2b.server.queryengine.QueryOperations.java
License:BSD License
public void deleteQuery(Long id) { logger.info("id to delete:" + id); Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); try {/*from w w w . j a va 2 s . c o m*/ session.connection().createStatement() .execute("update query_abstract_query set created_by=-1 where identifier=" + id); } catch (Exception e) { logger.error(e); } tx.commit(); session.clear(); session.close(); EntityCache.getCache().refreshCache(); CategoryCache.getInstance().refreshCategoryCache(); UtilityOperations.refreshCache(); }
From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordManager.java
License:Open Source License
private static Void storeInTransaction(Session session, List<OperationalDataRecord> records, long timestamp) { int storedCount = 0; int batchSize = getConfiguredBatchSize(session); for (OperationalDataRecord record : records) { record.setMonitoringDataTs(timestamp); session.save(record);// w ww. j av a 2s .c om if (++storedCount % batchSize == 0) { session.flush(); session.clear(); } } return null; }
From source file:eionet.webq.dao.ProjectFileStorageImplTest.java
License:Mozilla Public License
@Test(expected = LazyInitializationException.class) public void allFilesQueryDoesNotReturnFileContent() throws Exception { addOneFile("fileName1"); Session currentSession = sessionFactory.getCurrentSession(); currentSession.clear(); Collection<ProjectFile> projectFiles = projectFileStorage.findAllFilesFor(projectEntry); assertThat(projectFiles.size(), equalTo(1)); ProjectFile file = projectFiles.iterator().next(); currentSession.evict(file);// w w w . j a v a 2 s .c o m file.getFileContent(); }
From source file:eionet.webq.dao.UserFileStorageImplTest.java
License:Mozilla Public License
@Test(expected = LazyInitializationException.class) public void filesContentIsFetchedLazily() throws Exception { storage.save(fileWithContentAndXmlSchema("test-content".getBytes()), userId); Session currentSession = sessionFactory.getCurrentSession(); currentSession.clear(); UserFile theOnlyFile = getFirstUploadedFileAndAssertThatItIsTheOnlyOneAvailableFor(userId); currentSession.evict(theOnlyFile);//from w ww. j a va 2 s . co m theOnlyFile.getContent();// content must be not initialized }
From source file:eionet.webq.dao.UserFileStorageImplTest.java
License:Mozilla Public License
@Test public void fileContentWillBeLoadedOnDemand() throws Exception { byte[] testContent = "aaaaa".getBytes(); storage.save(fileWithContentAndXmlSchema(testContent), userId); Session currentSession = sessionFactory.getCurrentSession(); currentSession.clear(); UserFile theOnlyFile = getFirstUploadedFileAndAssertThatItIsTheOnlyOneAvailableFor(userId); assertThat(theOnlyFile.getContent(), equalTo(testContent)); }
From source file:es.emergya.bbdd.dao.BandejaEntradaHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) public List<Inbox> getNotProcessed() { Session currentSession = getSession(); currentSession.clear(); return (List<Inbox>) getSession().createCriteria(Inbox.class).add(Restrictions.eq("procesado", false)) .addOrder(Order.asc("marcaTemporal")).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); }