List of usage examples for org.hibernate Session persist
void persist(Object object);
From source file:es.uvigo.ei.sing.gc.view.models.committee.dataset.DataSetViewModel.java
License:Open Source License
public void setDataSet(DataSetMetaData dataSet) { final Committee committee = this.getCommittee(); final Integer dataSetId = dataSet.getId(); if (!dataSet.equals(committee.getDataSet())) { this.dataLostNotification("Data Set Selection", "Data set changing will provoke data deletion (gene set, classifiers, etc.). Do you wish to continue?", CommitteeStatus.RANKED_GENES, CommitteeStatus.DATA_SET, new Runnable() { public void run() { final Session session = HibernateUtil.currentSession(); final Committee committee = DataSetViewModel.this.getCommittee(); final DataSetMetaData dataSet = (DataSetMetaData) session.get(DataSetMetaData.class, dataSetId); committee.setDataSet(dataSet); committee.setName(dataSet.getName()); session.persist(committee); DataSetViewModel.this.updateExecutions(); BindUtils.postNotifyChange(null, null, DataSetViewModel.this, CommitteeViewModel.DATA_SET_STEP); }/*from www . j a v a 2 s . c o m*/ }); } }
From source file:es.uvigo.ei.sing.gc.view.models.committee.enrichment.GeneEnrichmentSubtask.java
License:Open Source License
@Override public Set<GeneSetMetaData> call() throws Exception { if (this.aborted) throw new AbortException(); final ArrayOfString result = GeneEnrichmentSubtask.enrich("Homo sapiens (human)", geneList); if (this.aborted) throw new AbortException(); final List<GeneSetMetaData> geneSets = new ArrayList<GeneSetMetaData>(); int missingCount = 0; for (String data : result.getString()) { final String[] split = data.split(";"); final String sourceId = split[0]; final String sourceName = SOURCE_TRANSLATION.containsKey(sourceId) ? SOURCE_TRANSLATION.get(sourceId) : sourceId;/*from w w w . ja v a2 s. c o m*/ final String id = split[1]; final String name = split[2].equals("-.") ? "[" + sourceId + "-" + ++missingCount + "]" : split[2]; final String[] genes = split[3].split(","); final String pvalueString = split[4].replace(",", "."); final double pvalue = Double.parseDouble(pvalueString); final GeneSetMetaData gs = new GeneSetMetaData(); gs.setSource(sourceName); gs.setGeneSetId(id); gs.setName(name); gs.setPValue(pvalue); gs.changeGenes(new HashSet<String>(Arrays.asList(genes))); geneSets.add(gs); } if (this.aborted) throw new AbortException(); final Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); final Committee committee = (Committee) session.get(Committee.class, committeeId); for (GeneSetMetaData geneSet : geneSets) { session.persist(geneSet); } session.flush(); committee.getGeneSets().addAll(geneSets); session.update(committee); session.getTransaction().commit(); session.close(); return committee.getGeneSets(); }
From source file:es.uvigo.ei.sing.gc.view.models.committee.evaluation.EvaluationViewModel.java
License:Open Source License
@Init @Override/*from w w w . java 2s . c o m*/ public void init() { super.init(); this.currentPerformanceFunction = PerformanceFunction.KAPPA; this.currentClass = PerformanceFunction.ALL_CLASSES_LABEL; final Committee committee = this.getCommittee(false); final ExperimentMetaData experiment = committee.getExperiment(); if (experiment == null) { final Session session = HibernateUtil.currentSession(); final ExperimentMetaData newExperiment = new ExperimentMetaData( this.getUserId() + " - " + UUID.randomUUID().toString(), committee); session.persist(newExperiment); session.flush(); committee.setExperiment(newExperiment); session.update(committee); } else if (experiment.getStatus() == ExperimentStatus.Finished && experiment.hasExpertResults() && !experiment.hasAnyExpertSelected()) { Clients.showNotification("Select the experts of your committee clicking on their performance", Clients.NOTIFICATION_TYPE_INFO, null, "middle_center", 0); } StatusViewModel.changeInitialStatus("Execute the evaluation of the classifiers using selected gene sets"); }
From source file:es.uvigo.ei.sing.gc.view.models.committee.evaluation.ExpertEvaluationSubtask.java
License:Open Source License
private void storeResult(ExpertResult result, Integer experimentId) throws StorageException { synchronized (ExpertEvaluationSubtask.class) { boolean done = false; int tries = 0; do {//from ww w.j av a 2 s . co m Session session = null; Transaction transaction = null; ExperimentMetaData experiment = null; try { this.checkAbort(); session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); this.checkAbort(); experiment = (ExperimentMetaData) session.load(ExperimentMetaData.class, experimentId); for (SampleClassification sample : result.getSamples()) { session.persist(sample); } this.checkAbort(); session.flush(); session.persist(result); this.checkAbort(); session.flush(); experiment.getResults().add(result); this.checkAbort(); session.update(experiment); transaction.commit(); done = true; } catch (Exception e) { try { if (transaction != null) transaction.rollback(); } catch (Exception ex) { ex.printStackTrace(); } result.setId(null); for (SampleClassification sample : result.getSamples()) { sample.setId(null); } if (experiment != null) experiment.getResults().remove(result); if (this.aborted) return; e.printStackTrace(); } finally { try { if (session != null && session.isOpen()) session.close(); } catch (Exception e) { e.printStackTrace(); } } } while (!done && ++tries < ExpertEvaluationSubtask.MAX_TRIES); if (!done) { final String message = "Evaluation result could not be stored: " + result.toString(); System.err.println(message); throw new StorageException(message); } } }
From source file:es.uvigo.ei.sing.gc.view.models.committee.geneset.GeneSetViewModel.java
License:Open Source License
@Init @Override// ww w .j a va 2 s . co m public void init() { super.init(); this.geneURL = "/loading.zul"; this.geneURLVisible = false; final Committee committee = this.getCommittee(false); // Refreshed in init if (!committee.hasGeneSelection()) { final Session session = HibernateUtil.currentSession(); final GeneSelectionMetaData geneSelection = GeneSelectionType.getDefault().buildGeneSelection(); committee.setGeneSelection(geneSelection); session.persist(geneSelection); session.flush(); session.update(geneSelection); } StatusViewModel.changeInitialStatus("Select the best genes using a feature selection algorithm"); }
From source file:es.uvigo.ei.sing.gc.view.models.committee.geneset.SelectGenesSubtask.java
License:Open Source License
@Override public Set<RankedGene> call() throws Exception { try {//w w w. j ava 2 s.c om if (this.aborted) throw new AbortException(); final FeatureSelectionResults fsResults = fs.obtainFeatureSelection(); final List<Variable> selectedVariables = fsResults.getSelectedVariables(); final List<Double> ranking = fsResults.getRanking(); final Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); final Set<RankedGene> genes = new HashSet<RankedGene>(); int i = 0; for (Variable selectedVariable : selectedVariables) { if (this.aborted) throw new AbortException(); final RankedGene gene = new RankedGene(i + 1, selectedVariable.getName(), ranking.get(i++)); session.persist(gene); session.flush(); genes.add(gene); } if (this.aborted) throw new AbortException(); final Committee committee = (Committee) session.get(Committee.class, committeeId); committee.getRankedGenes().clear(); committee.getRankedGenes().addAll(genes); session.update(committee); session.getTransaction().commit(); session.close(); return committee.getRankedGenes(); } catch (Exception e) { e.printStackTrace(); throw e; } }
From source file:es.uvigo.ei.sing.gc.view.models.committee.summary.SummaryViewModel.java
License:Open Source License
@Command("saveAndFinish") public void saveAndFinish() throws Exception { final Committee committee = this.getCommittee(); if (committee.isFinished()) { throw new IllegalStateException("Committee is already completed"); } else {/*from ww w . j av a 2s . com*/ final Session session = HibernateUtil.currentSession(); Committee sameName = (Committee) session.createCriteria(Committee.class).setMaxResults(1) .add(Restrictions.eq("user", committee.getUser())) .add(Restrictions.eq("name", committee.getName())) .add(Restrictions.not(Restrictions.eq("id", committee.getId()))).uniqueResult(); if (sameName == null) { committee.setFinished(true); session.persist(committee); Executions.sendRedirect("/home.zul"); } else { Messagebox.show( "There is another committee with the same name. Please, change the name in order to continue.", "Invalid Name", Messagebox.OK, Messagebox.ERROR); } } }
From source file:es.uvigo.ei.sing.gc.view.models.datasets.UploadDataSubTask.java
License:Open Source License
@Override public DataSetMetaData call() throws Exception { Transaction transaction = null;//from www . j ava 2 s . c o m Session session = null; DataSetMetaData dataSet = null; try { if (this.aborted) throw new AbortException(); final Data data = ZKUtils.loadDataFromMedia(this.media); if (this.aborted) throw new AbortException(); session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); final User user = ZKUtils.hLoad(User.class, this.userId, session); dataSet = user.addDataSet(data); session.persist(user); if (this.aborted) throw new AbortException(); session.flush(); transaction.commit(); return dataSet; } catch (Throwable e) { e.printStackTrace(); if (transaction != null) try { transaction.rollback(); } catch (HibernateException he) { } if (dataSet != null && dataSet.hasFile()) { new File(dataSet.getFileName()).delete(); } if (e instanceof Exception) { throw (Exception) e; } else { throw new Exception(e); } } finally { if (session.isOpen()) try { session.close(); } catch (HibernateException e) { } } }
From source file:es.uvigo.ei.sing.gc.view.models.PasswordRecoveryViewModel.java
License:Open Source License
@Command public void changePassword() { if (this.isPasswordOk()) { final Session session = HibernateUtil.currentSession(); final User user = ZKUtils.hLoad(User.class, this.email, session); user.setPassword(DigestUtils.md5Hex(this.newPassword)); session.persist(user); session.flush();/*from w ww .ja va2 s . com*/ Messagebox.show("Password successfully changed. Press 'Ok' to go to the login page.", "Password Changed", Messagebox.OK, Messagebox.INFORMATION, new EventListener<Event>() { @Override public void onEvent(Event event) throws Exception { Executions.sendRedirect("index.zul"); } }); } }
From source file:eu.trentorise.opendata.ckanalyze.managers.PersistencyManager.java
License:Open Source License
public static void insert(Object o) { Session ss = PersistencyManager.getSessionFactory().openSession(); ss.beginTransaction();//ww w . j a v a 2 s . c om ss.persist(o); ss.getTransaction().commit(); ss.close(); }