List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:module.script.pro12.CreatePro12.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public CreatePro12() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); // MongoDatabase db = mongoClient.getDatabase("geo"); MongoCollection<Document> collectionSeries = db.getCollection("series"); Date submissionDate = null;//from w w w .j ava 2 s . c o m try { submissionDate = dateFormat.parse("2010-01-01"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<String> platforms = new ArrayList<String>(); platforms.add("GPL570"); Document docSeries = new Document(); docSeries.append("_id", "PRO12").append("title", "Project 12: Reference tissues and cell lines") .append("platforms", platforms).append("submission_date", submissionDate) .append("last_update", submissionDate).append("import_date", new Date()); System.out.println(docSeries); collectionSeries.insertOne(docSeries); if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.pro12.TransferPro12.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public TransferPro12() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); String sql = "select id_sample from epimed_prod.om_sample join epimed_prod.om_sample_series using (id_sample) " + "join epimed_prod.om_series using (id_series) where id_series='PRO12'"; List<String> list = session.createSQLQuery(sql).list(); Document pro12 = new Document(); pro12.append("series", "PRO12"); for (String gsmNumber : list) { Document doc = collection.find(Filters.eq("_id", gsmNumber)).first(); System.out.println("-----------------------------"); System.out.println(gsmNumber + " " + doc); if (doc != null) { // Update Mongo document collection.updateOne(Filters.eq("_id", gsmNumber), new Document("$push", pro12)); }//w w w . ja v a2 s. c o m } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.proallchen.CreateProallChen.java
License:Open Source License
public CreateProallChen() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); // MongoDatabase db = mongoClient.getDatabase("geo"); MongoCollection<Document> collectionSeries = db.getCollection("series"); Date submissionDate = null;// w w w . ja va 2 s. c o m try { submissionDate = dateFormat.parse("2016-05-13"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // List<String> platforms = new ArrayList<String>(); // platforms.add("GPL570"); Document docSeries = new Document(); docSeries.append("_id", "PROALL_CHEN") .append("title", "Genomic Profiling of Adult and Pediatric B-cell Acute Lymphoblastic Leukemia") .append("platforms", null).append("submission_date", submissionDate) .append("last_update", submissionDate).append("import_date", new Date()); System.out.println(docSeries); collectionSeries.insertOne(docSeries); if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.probcp.ImportSamplesProbcp.java
License:Open Source License
public ImportSamplesProbcp() { // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionSamples = db.getCollection("samples"); // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); String[] studies = { "tya16", "law15" }; List<String> series = new ArrayList<String>(); for (int l = 0; l < studies.length; l++) { String idStudy = studies[l]; String studyName = idStudy.toUpperCase(); series.clear();/*from www.j a va 2 s. co m*/ series.add(studyName); series.add("PROBCP"); String sql = "select * from st_bcp." + idStudy + "_sample order by id_sample"; List<Object> listSamples = session.createSQLQuery(sql).list(); for (int i = 0; i < listSamples.size(); i++) { Object[] lineSample = (Object[]) listSamples.get(i); String idSample = (String) lineSample[0]; String clinicalClassification = (String) lineSample[1]; String tnmStage = (String) lineSample[2]; Integer grade = (Integer) lineSample[3]; String type = (String) lineSample[4]; System.out.println(Arrays.toString(lineSample)); // ===== Collection method ==== String collectionMethod = "biopsy"; if (idStudy.equals("law15") && !idSample.startsWith("Tumor")) { collectionMethod = "cell line"; } // ==== Topology ==== ClTopology topology = session.get(ClTopology.class, "C50.9"); // === Morphology === ClMorphology morphology = session.get(ClMorphology.class, "8010/3"); // carcinoma ClMorphology idc = session.get(ClMorphology.class, "8500/3"); // inf. duct. carcinoma ClMorphology lo = session.get(ClMorphology.class, "8520/3"); // lobular carcinoma ClMorphology ac = session.get(ClMorphology.class, "8140/3"); // adenocarcinoma if (type != null && (type.contains("IDC") || type.contains("DC") || type.contains("ductal"))) { morphology = idc; } if (type != null && type.contains("Lo")) { morphology = lo; } if (type != null && (type.contains("AC") || type.contains("adeno"))) { morphology = ac; } // ===== Sample Document ===== Document docSample = new Document(); docSample.append("_id", studyName + "_" + idSample).append("main_gse_number", studyName) .append("series", series).append("organism", "Homo sapiens") .append("submission_date", today).append("last_update", today).append("import_date", today) .append("analyzed", true); // ===== Mandatory parameters ===== Document expGroup = this.generateExpGroup(idSample, studyName, tnmStage, grade, type, collectionMethod, topology, morphology); docSample.append("exp_group", expGroup); // ===== Supplementary parameters ===== Document parameters = this.generateParameters(idSample); docSample.append("parameters", parameters); parameters.append("clinical_classification", clinicalClassification); parameters.append("tnm_stage", tnmStage); parameters.append("grade", grade); parameters.append("type", type); // === Append parameters to document === docSample.append("parameters", parameters); // === Save === collectionSamples.insertOne(docSample); System.out.println(docSample); } } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.probcp.UpdateSamplesProbcp.java
License:Open Source License
public UpdateSamplesProbcp() { // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionSamples = db.getCollection("samples"); // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); String[] studies = { "tya16" }; List<String> series = new ArrayList<String>(); for (int l = 0; l < studies.length; l++) { String idStudy = studies[l]; String studyName = idStudy.toUpperCase(); series.clear();// w ww . j a va 2s . c o m series.add(studyName); series.add("PROBCP"); String sql = "select * from st_bcp." + idStudy + "_sample order by id_sample"; List<Object> listSamples = session.createSQLQuery(sql).list(); for (int i = 0; i < listSamples.size(); i++) { Object[] lineSample = (Object[]) listSamples.get(i); String idSample = (String) lineSample[0]; String clinicalClassification = (String) lineSample[1]; String tnmStage = (String) lineSample[2]; Integer grade = (Integer) lineSample[3]; String type = (String) lineSample[4]; System.out.println(Arrays.toString(lineSample)); String id = studyName + "_" + idSample; Document docSample = collectionSamples.find(Filters.eq("_id", id)).first(); Document expgroup = (Document) docSample.get("exp_group"); expgroup.append("tnm_grade", grade); expgroup.append("tnm_stage", null); docSample.append("exp_group", expgroup); UpdateResult updateResult = collectionSamples.updateOne(Filters.eq("_id", id), new Document("$set", docSample)); System.out.println(docSample); } } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.TransferBrbAnnotations.java
License:Open Source License
@SuppressWarnings({ "unused", "unchecked" }) public TransferBrbAnnotations() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); String sql = "select id_sample, main_gse_number, string_agg(id_substance, ', ') as list_substances from epimed_prod.om_sample " + "join epimed_prod.cl_biopatho using (id_biopatho) join epimed_prod.cl_patient using (id_patient) join epimed_prod.cl_exposure using (id_patient) " + "where exposed=true group by id_sample"; List<Object> list = session.createSQLQuery(sql).setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(); for (Object item : list) { Map<String, Object> map = (HashMap<String, Object>) item; String gsmNumber = (String) map.get("id_sample"); String gseNumber = (String) map.get("main_gse_number"); System.out.println("-----------------------------"); System.out.println(gseNumber + " " + gsmNumber); Document doc = collection.find(Filters.eq("_id", gsmNumber)).first(); if (doc != null) { Document expGroup = (Document) doc.get("exp_group"); expGroup.put("exposure", map.get("list_substances")); System.out.println(expGroup); // Update Mongo document doc.put("exp_group", expGroup); doc.put("analyzed", true); UpdateResult updateResult = collection.updateOne(Filters.eq("_id", gsmNumber), new Document("$set", doc)); }//from w w w .j a va2 s . c om } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.TransferBrbHistologyCodes.java
License:Open Source License
@SuppressWarnings({ "unused", "unchecked" }) public TransferBrbHistologyCodes() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); String sql = "select id_sample, main_gse_number, index_histology_code, histology_code, ordered_histology_code from db_brb_lung.view_exp_group"; List<Object> list = session.createSQLQuery(sql).setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(); for (Object item : list) { Map<String, Object> map = (HashMap<String, Object>) item; String gsmNumber = (String) map.get("id_sample"); String gseNumber = (String) map.get("main_gse_number"); System.out.println("-----------------------------"); System.out.println(gseNumber + " " + gsmNumber); Document doc = collection.find(Filters.eq("_id", gsmNumber)).first(); if (doc != null) { Document expGroup = (Document) doc.get("exp_group"); expGroup.put("index_histology_code", map.get("index_histology_code")); expGroup.put("histology_code", map.get("histology_code")); expGroup.put("ordered_histology_code", map.get("ordered_histology_code")); System.out.println(expGroup); // Update Mongo document doc.put("exp_group", expGroup); doc.put("analyzed", true); UpdateResult updateResult = collection.updateOne(Filters.eq("_id", gsmNumber), new Document("$set", doc)); }//from ww w . j a v a 2s . c o m } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.TransferExposure.java
License:Open Source License
@SuppressWarnings({ "unused", "unchecked" }) public TransferExposure() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); String sql = "select id_sample, main_gse_number, string_agg(id_substance, ', ') as list_substances from epimed_prod.om_sample " + "join epimed_prod.cl_biopatho using (id_biopatho) join epimed_prod.cl_patient using (id_patient) join epimed_prod.cl_exposure using (id_patient) " + "where exposed=true group by id_sample"; List<Object> list = session.createSQLQuery(sql).setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(); for (Object item : list) { Map<String, Object> map = (HashMap<String, Object>) item; String gsmNumber = (String) map.get("id_sample"); String gseNumber = (String) map.get("main_gse_number"); System.out.println("-----------------------------"); System.out.println(gseNumber + " " + gsmNumber); Document doc = collection.find(Filters.eq("_id", gsmNumber)).first(); if (doc != null) { Document expGroup = (Document) doc.get("exp_group"); expGroup.put("exposure", map.get("list_substances")); System.out.println(expGroup); // Update Mongo document doc.put("exp_group", expGroup); doc.put("analyzed", true); UpdateResult updateResult = collection.updateOne(Filters.eq("_id", gsmNumber), new Document("$set", doc)); }//from w w w. jav a2 s.c o m } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.script.TransferFromEpimedProd.java
License:Open Source License
@SuppressWarnings({ "unused", "unchecked" }) public TransferFromEpimedProd() { // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); // ===== Session Mongo ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collection = db.getCollection("samples"); String sql = "select * from epimed_prod.view_exp_group order by main_gse_number, id_sample"; List<Object> list = session.createSQLQuery(sql).setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(); String[] commonAttributes = { "pathology", "tnm_stage", "id_topology_group", "histology_subtype", "tissue_stage", "dead", "dfs_months", "age_max", "morphology", "id_tissue_stage", "topology", "sex", "age_min", "m", "topology_group", "n", "t", "collection_method", "id_morphology", "relapsed", "histology_type", "os_months", "id_topology" }; List<ClPathology> listPathology = session.createCriteria(ClPathology.class).list(); Map<String, ClPathology> mapPathology = new HashMap<String, ClPathology>(); for (ClPathology p : listPathology) { mapPathology.put(p.getName(), p); }//from w w w.j a v a 2 s .com List<ClTissueStatus> listTissueStatus = session.createCriteria(ClTissueStatus.class).list(); Map<Integer, ClTissueStatus> mapTissueStatus = new HashMap<Integer, ClTissueStatus>(); for (ClTissueStatus t : listTissueStatus) { mapTissueStatus.put(t.getIdTissueStatus(), t); } System.out.println(listTissueStatus); for (Object item : list) { Map<String, Object> map = (HashMap<String, Object>) item; String gsmNumber = (String) map.get("id_sample"); String gseNumber = (String) map.get("main_gse_number"); System.out.println("-----------------------------"); System.out.println(gseNumber + " " + gsmNumber); Document doc = collection.find(Filters.eq("_id", gsmNumber)).first(); if (doc != null) { Document expGroup = (Document) doc.get("exp_group"); for (int j = 0; j < commonAttributes.length; j++) { String attr = commonAttributes[j]; expGroup.put(attr, map.get(attr)); } // Treatment expGroup.put("treatment", map.get("treatment_type")); // Pathology String pathoString = (String) map.get("pathology"); ClPathology pathology = mapPathology.get(pathoString); if (pathology != null) { expGroup.put("id_pathology", pathology.getIdPathology()); expGroup.put("pathology", pathology.getName()); } // Tissue status Integer idTissueStatus = (Integer) map.get("id_tissue_status"); if (idTissueStatus != null && idTissueStatus > 3) { idTissueStatus = 3; } ClTissueStatus tissueStatus = mapTissueStatus.get(idTissueStatus); if (tissueStatus != null) { expGroup.put("id_tissue_status", tissueStatus.getIdTissueStatus()); expGroup.put("tissue_status", tissueStatus.getName()); } System.out.println("idTissueStatus=" + tissueStatus + ", pathology=" + pathology); System.out.println(expGroup); // Update Mongo document doc.put("exp_group", expGroup); doc.put("analyzed", true); UpdateResult updateResult = collection.updateOne(Filters.eq("_id", gsmNumber), new Document("$set", doc)); } } if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); }
From source file:module.test.ImportProbesets.java
License:Open Source License
public ImportProbesets() { // === Display === System.out.println("\n================ BEGIN Module " + this.getClass().getName() + "================"); // ===== Connection ===== MongoClient mongoClient = MongoUtil.buildMongoClient(); MongoDatabase db = mongoClient.getDatabase("epimed_experiments"); MongoCollection<Document> collectionProbesets = db.getCollection("probesets"); // ===== Session PostgreSQL ===== SessionFactory sessionFactory = HibernateUtil .buildSessionFactory("config/epimed_semantic.hibernate.cfg.xml"); Session session = sessionFactory.openSession(); String idPlatform = "GPL570"; String gpl = idPlatform.toLowerCase(); // ===== Load file ===== String inputfile = this.getInputDirectory() + this.getDirSeparator() + "HG-U133_Plus_2.na36.annot.csv"; System.out.println("ID Platform " + gpl); System.out.println("LOADING \t " + inputfile); System.out.println("Please wait... "); List<String> listRows = fileService.loadTextFile(inputfile); System.out.println("File sucessfully LOADED"); // ===== Recognize header ===== List<String> header = fileService.readHeader(listRows, "\",\""); System.out.println("Header " + header); List<List<String>> data = fileService.readData(listRows, "\",\""); System.out.println(/*ww w .java 2 s .co m*/ "The data are sucessfully loaded: rows " + data.size() + ", columns " + data.get(0).size()); Integer indProbeset = fileService.findIndex(header, "Probe Set ID"); Integer indGenes = fileService.findIndex(header, "Entrez Gene"); Integer indUnigenes = fileService.findIndex(header, "UniGene ID"); Integer indTranscripts = fileService.findIndex(header, "RefSeq Transcript ID"); Integer indGb = fileService.findIndex(header, "Representative Public ID"); for (int i = 0; i < 5; i++) { List<String> dataline = data.get(i); String probeset = dataline.get(indProbeset); String genes = dataline.get(indGenes); String unigenes = dataline.get(indUnigenes); String transcripts = dataline.get(indTranscripts); String gb = dataline.get(indGb); System.out.println(probeset + "\t" + genes + "\t" + formatService.splitInArray(unigenes, "///") + "\t" + gb + "\t" + transcripts); Document docProbeset = mongoService.createProbeset(idPlatform, probeset); docProbeset.put("genes", formatService.splitInArray(genes, "///")); docProbeset.put("unigenes", formatService.splitInArray(unigenes, "///")); List<String> listTranscripts = formatService.splitInArray(transcripts, "///"); listTranscripts.addAll(formatService.splitInArray(gb, "///")); docProbeset.put("transcripts", listTranscripts); collectionProbesets.insertOne(docProbeset); /* for (int j=0; j<dataline.size(); j++) { String key = header.get(j); String value = dataline.get(j); System.out.println(key + ": " + value); } */ } /* String tableProbe = "hs.om_probe_" + gpl; String tableGP = "hs.om_gp_" + gpl; List<Object []> listProbesets = session.createNativeQuery("select * from " + tableProbe + " order by id_probe").getResultList(); for (int i=0; i<10; i++) { Object[] line = listProbesets.get(i); System.out.println(Arrays.toString(line)); // Document docProbeset = mongoService.createProbeset(idPlatform, "1007_s_at"); // collectionProbesets.insertOne(docProbeset); } */ // === Close connections === if (session.isOpen()) { session.close(); } sessionFactory.close(); mongoClient.close(); // === Display === System.out.println("================ END Module " + this.getClass().getName() + "================"); }