List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:ctd.services.addReference.java
License:Apache License
/** * * @return message/*w w w . j a v a2 s. c o m*/ */ public String addReference() { String message = ""; //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Query q = session.createQuery("from Ticket where password='" + getPassword() + "'"); Ticket ticket = (Ticket) q.uniqueResult(); Iterator it1 = ticket.getStudySampleAssaies().iterator(); while (it1.hasNext()) { StudySampleAssay ssa = (StudySampleAssay) it1.next(); String name = ssa.getNameRawfile(); name = name.replace(".CEL", ""); if (name.equals(getName_RAWFILE())) { ssa.setXREF(getReference()); } } Transaction tr = session.beginTransaction(); session.saveOrUpdate(ticket); session.persist(ticket); tr.commit(); session.close(); sessionFactory.close(); message = getReference() + " is added."; return message; }
From source file:ctd.services.deleteData.java
License:Apache License
public String deleteData() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); DeleteDataResult ddr = new DeleteDataResult(); if (webservice_password.equals(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Query q = session.createQuery("from Ticket where password='" + getPassword() + "'"); Ticket ticket = (Ticket) q.uniqueResult(); //if password is incorrect, stop and give error message. if (ticket == null) { ddr.setErrorMessage("password from this ticket is not found in the database."); }//www. j a v a2 s . c o m //Delete, if ticket is retrieved. if (ticket != null) { //gather study_sampel_assay_ids to be deleted in the expression table Iterator it1 = ticket.getStudySampleAssaies().iterator(); while (it1.hasNext()) { StudySampleAssay ssa = (StudySampleAssay) it1.next(); Integer id = ssa.getId(); session.delete(ssa); } //Delete ticket and its connected samples Transaction tx = (Transaction) session.beginTransaction(); session.delete(ticket); tx.commit(); ddr.setMessage("Data from this ticket is deleted."); } session.close(); sessionFactory.close(); } if (webservice_password.equals(getWsPassword()) == false) { ddr.setErrorMessage("wrong password for using webservice, change the settings.properties file."); } //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } String text = trans.serializeToString(ddr); return text; }
From source file:ctd.services.getExperimentInfo.java
License:Apache License
public String getExperimentInfo() throws NoImplementationException, SerializerException { String message = ""; ArrayList<AssayInfo> array = new ArrayList<AssayInfo>(); //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Ticket ticket = null;/*from w w w. ja v a 2s . c o m*/ Query q1 = session.createQuery("from Ticket where password='" + getPassword() + "'"); ticket = (Ticket) q1.uniqueResult(); Iterator it1 = ticket.getStudySampleAssaies().iterator(); while (it1.hasNext()) { AssayInfo ai = new AssayInfo(); StudySampleAssay ssa = (StudySampleAssay) it1.next(); String x_ref_name = ssa.getXREF(); String raw_name = ssa.getNameRawfile(); Double avg = ssa.getAverage(); Double std = ssa.getStd(); ai.setAverage(avg); ai.setNameRawfile(raw_name); ai.setXREF(x_ref_name); ai.setStd(std); array.add(ai); } session.close(); sessionFactory.close(); //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToString(array); return message; }
From source file:ctd.services.getExpressionByProbeSetId.java
License:Apache License
public String getExpressionByProbeSetId() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String message = ""; ArrayList<ProbeSetExpressionInfo> pseia = new ArrayList<ProbeSetExpressionInfo>(); if (webservice_password.contains(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); String psi = getProbeSetId(); SQLQuery q = session.createSQLQuery( "Select chip.name,expression.expression,study_sample_assay.X_REF,study_sample_assay.average,study_sample_assay.std,ticket.password FROM chip,chip_annotation,expression,study_sample_assay,ticket WHERE chip.id=chip_annotation.chip_id AND probeset='" + psi// w w w .jav a 2 s .c om + "' AND chip_annotation.id=expression.chip_annotation_id AND expression.study_sample_assay_id=study_sample_assay.id AND study_sample_assay.ticket_id=ticket.id"); Iterator it1 = q.list().iterator(); while (it1.hasNext()) { ProbeSetExpressionInfo psei = new ProbeSetExpressionInfo(); Object[] data = (Object[]) it1.next(); String chip_name = (String) data[0]; Double log2value = (Double) data[1]; String local_accession = (String) data[2]; Double average = (Double) data[3]; Double std = (Double) data[4]; String password = (String) data[5]; psei.setChipName(chip_name); psei.setLog2Value(log2value); psei.setLocalAccession(local_accession); psei.setSTD(std); psei.setAverage(average); psei.setTicketPassword(password); pseia.add(psei); } session.close(); sessionFactory.close(); } //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToString(pseia); return message; }
From source file:ctd.services.getExpressionByProbeSetId.java
License:Apache License
public ArrayList<ProbeSetExpressionInfo> getExpressionByProbeSetIdInternal() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String message = ""; ArrayList<ProbeSetExpressionInfo> pseia = new ArrayList<ProbeSetExpressionInfo>(); if (webservice_password.contains(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); String psi = getProbeSetId(); SQLQuery q = session.createSQLQuery( "Select chip.name,expression.expression,study_sample_assay.X_REF,study_sample_assay.average,study_sample_assay.std,ticket.password,ticket.title,ticket.id,study_sample_assay.group_name FROM chip,chip_annotation,expression,study_sample_assay,ticket WHERE chip.id=chip_annotation.chip_id AND probeset='" + psi// ww w . j a va 2 s . co m + "' AND chip_annotation.id=expression.chip_annotation_id AND expression.study_sample_assay_id=study_sample_assay.id AND study_sample_assay.ticket_id=ticket.id ORDER BY study_sample_assay.ticket_id,study_sample_assay.group_name ASC"); Iterator it1 = q.list().iterator(); while (it1.hasNext()) { ProbeSetExpressionInfo psei = new ProbeSetExpressionInfo(); Object[] data = (Object[]) it1.next(); String chip_name = (String) data[0]; Double log2value = (Double) data[1]; String local_accession = (String) data[2]; Double average = (Double) data[3]; Double std = (Double) data[4]; String password = (String) data[5]; String title = (String) data[6]; Integer ticket_id = (Integer) data[7]; String group_name = (String) data[8]; psei.setChipName(chip_name); psei.setLog2Value(log2value); psei.setLocalAccession(local_accession); psei.setSTD(std); psei.setAverage(average); psei.setTicketPassword(password); psei.setTitle(title); psei.setGroupName(group_name); psei.setTicketId(ticket_id); pseia.add(psei); } session.close(); sessionFactory.close(); } return pseia; }
From source file:ctd.services.getJsonExperimentInfo.java
License:Apache License
public String getJsonExperimentInfo() throws NoImplementationException, SerializerException { String message = ""; ArrayList<AssayInfo> array = new ArrayList<AssayInfo>(); //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Ticket ticket = null;/*from w w w . ja v a2s .c om*/ Query q1 = session.createQuery("from Ticket where password='" + getTicketPassword() + "'"); ticket = (Ticket) q1.uniqueResult(); Iterator it1 = ticket.getStudySampleAssaies().iterator(); while (it1.hasNext()) { AssayInfo ai = new AssayInfo(); StudySampleAssay ssa = (StudySampleAssay) it1.next(); String x_ref_name = ssa.getXREF(); String raw_name = ssa.getNameRawfile(); Double avg = ssa.getAverage(); Double std = ssa.getStd(); ai.setAverage(avg); ai.setNameRawfile(raw_name); ai.setXREF(x_ref_name); ai.setStd(std); array.add(ai); } session.close(); sessionFactory.close(); //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToJsonString(array); return message; }
From source file:ctd.services.getJsonExpressionByProbeSetId.java
License:Apache License
public String getExpressionByProbeSetId() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String message = ""; ArrayList<ProbeSetExpressionInfo> pseia = new ArrayList<ProbeSetExpressionInfo>(); if (webservice_password.contains(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); String psi = getProbeSetId(); SQLQuery q = session.createSQLQuery( "Select chip.name,expression.expression,study_sample_assay.X_REF,study_sample_assay.average,study_sample_assay.std,ticket.password FROM chip,chip_annotation,expression,study_sample_assay,ticket WHERE chip.id=chip_annotation.chip_id AND probeset='" + psi/*from w ww.java 2s. co m*/ + "' AND chip_annotation.id=expression.chip_annotation_id AND expression.study_sample_assay_id=study_sample_assay.id AND study_sample_assay.ticket_id=ticket.id"); Iterator it1 = q.list().iterator(); while (it1.hasNext()) { ProbeSetExpressionInfo psei = new ProbeSetExpressionInfo(); Object[] data = (Object[]) it1.next(); String chip_name = (String) data[0]; Double log2value = (Double) data[1]; String local_accession = (String) data[2]; Double average = (Double) data[3]; Double std = (Double) data[4]; String password = (String) data[5]; psei.setChipName(chip_name); psei.setLog2Value(log2value); psei.setLocalAccession(local_accession); psei.setSTD(std); psei.setAverage(average); psei.setTicketPassword(password); pseia.add(psei); } session.close(); sessionFactory.close(); } //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToJsonString(pseia); return message; }
From source file:ctd.services.getJsonExpressionByProbeSetId.java
License:Apache License
public ArrayList<ProbeSetExpressionInfo> getExpressionByProbeSetIdInternal() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String message = ""; ArrayList<ProbeSetExpressionInfo> pseia = new ArrayList<ProbeSetExpressionInfo>(); if (webservice_password.contains(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); String psi = getProbeSetId(); SQLQuery q = session.createSQLQuery( "Select chip.name,expression.expression,study_sample_assay.X_REF,study_sample_assay.average,study_sample_assay.std,ticket.password FROM chip,chip_annotation,expression,study_sample_assay,ticket WHERE chip.id=chip_annotation.chip_id AND probeset='" + psi/*from w w w. jav a2 s .co m*/ + "' AND chip_annotation.id=expression.chip_annotation_id AND expression.study_sample_assay_id=study_sample_assay.id AND study_sample_assay.ticket_id=ticket.id ORDER BY study_sample_assay.X_REF ASC"); Iterator it1 = q.list().iterator(); while (it1.hasNext()) { ProbeSetExpressionInfo psei = new ProbeSetExpressionInfo(); Object[] data = (Object[]) it1.next(); String chip_name = (String) data[0]; Double log2value = (Double) data[1]; String local_accession = (String) data[2]; Double average = (Double) data[3]; Double std = (Double) data[4]; String password = (String) data[5]; psei.setChipName(chip_name); psei.setLog2Value(log2value); psei.setLocalAccession(local_accession); psei.setSTD(std); psei.setAverage(average); psei.setTicketPassword(password); pseia.add(psei); } session.close(); sessionFactory.close(); } return pseia; }
From source file:ctd.services.getJsonTicket.java
License:Apache License
public String getTicket() throws SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String ftp_folder = res.getString("ws.ftp_folder"); String prefix_ctd_reference = res.getString("ws.prefix_ticket_reference"); String prefix_ftp_subfolder = res.getString("ws.prefix_ftp_subfolders"); String ftp_username = res.getString("ws.ftp_username"); String group = res.getString("ws.group"); String hostname = res.getString("ws.hostname"); TicketClient ticket_client = new TicketClient(); String new_folder = ""; String message = ""; String password_client = getWsPassword(); if (webservice_password.equals(password_client)) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); Transaction tr = session.beginTransaction(); Integer id = 1;/*from w ww . jav a 2 s . c o m*/ SQLQuery q1 = session.createSQLQuery("Select MAX(id) FROM ticket"); Iterator it1 = q1.list().iterator(); while (it1.hasNext()) { id = (Integer) it1.next(); if (id != null) { id++; } if (id == null) { id = 1; } } ///Get unique password for processing the submitted celfiles UUID uuid = null; ///check if this uuid is not allready used in this database Boolean check = true; while (check) { uuid = UUID.randomUUID(); Query q2 = session.createQuery("from Ticket where password='" + uuid.toString() + "'"); if (q2.list().isEmpty()) { check = false; } } //String db_password = password_client+"_"+webservice_password;//uuid.toString(); String db_password = uuid.toString(); //ctd reference id String ctd_ref = prefix_ctd_reference + String.valueOf(id); //ctd ftp subfolder String ctd_ftp_folder = prefix_ftp_subfolder + String.valueOf(id); //create subdir new_folder = ftp_folder + ctd_ftp_folder; boolean success = (new File(new_folder)).mkdir(); //change owner from root to cleandata for this new directory //Adjust permissions String command1 = "chown " + ftp_username + " " + new_folder; String command4 = "chgrp " + group + " " + new_folder; String command2 = "chmod 700 " + new_folder; String command3 = "chmod +t " + new_folder; Process child; try { child = Runtime.getRuntime().exec(command1); child = Runtime.getRuntime().exec(command4); child = Runtime.getRuntime().exec(command2); child = Runtime.getRuntime().exec(command3); } catch (IOException ex) { Logger.getLogger(getJsonTicket.class.getName()).log(Level.SEVERE, null, ex); } //location ftp folder String link = "sftp://" + ftp_username + "@" + hostname + ":" + new_folder + "/"; ticket_client.setLocationFTPFolder(link); Ticket ticket = new Ticket(); ticket.setFolder(ctd_ftp_folder); ticket.setPassword(db_password); ticket.setCtdRef(ctd_ref); ticket.setClosed("no"); ticket_client.setCtdRef(ctd_ref); ticket_client.setFolder(ctd_ftp_folder); ticket_client.setPassword(db_password); session.save(ticket); session.persist(ticket); tr.commit(); session.close(); sessionFactory.close(); session = null; sessionFactory = null; } //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getJsonTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToJsonString(ticket_client); return message; }
From source file:ctd.services.getMeasurementDataProbeset.java
License:Apache License
public String getMeasurementDataProbeset() throws NoImplementationException, SerializerException { //init parameters ResourceBundle res = ResourceBundle.getBundle("settings"); String webservice_password = res.getString("ws.password"); String message = ""; ArrayList<ProbeSetExpressionInfo> pseia = new ArrayList<ProbeSetExpressionInfo>(); if (webservice_password.contains(getWsPassword())) { //open hibernate connection SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); String psi = getMeasurementToken(); SQLQuery q = session.createSQLQuery( "Select chip.name,expression.expression,study_sample_assay.X_REF,study_sample_assay.average,study_sample_assay.std,ticket.password FROM chip,chip_annotation,expression,study_sample_assay,ticket WHERE chip.id=chip_annotation.chip_id AND probeset='" + psi// www.j av a2 s . c o m + "' AND chip_annotation.id=expression.chip_annotation_id AND expression.study_sample_assay_id=study_sample_assay.id AND study_sample_assay.ticket_id=ticket.id"); Iterator it1 = q.list().iterator(); while (it1.hasNext()) { ProbeSetExpressionInfo psei = new ProbeSetExpressionInfo(); Object[] data = (Object[]) it1.next(); String chip_name = (String) data[0]; Double log2value = (Double) data[1]; String local_accession = (String) data[2]; Double average = (Double) data[3]; Double std = (Double) data[4]; String password = (String) data[5]; psei.setChipName(chip_name); psei.setLog2Value(log2value); psei.setLocalAccession(local_accession); psei.setSTD(std); psei.setAverage(average); psei.setTicketPassword(password); pseia.add(psei); } session.close(); sessionFactory.close(); } //////////////////// //SKARINGA ObjectTransformer trans = null; try { trans = ObjectTransformerFactory.getInstance().getImplementation(); } catch (NoImplementationException ex) { Logger.getLogger(getTicket.class.getName()).log(Level.SEVERE, null, ex); } message = trans.serializeToJsonString(pseia); return message; }