List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:eu.optimis.common.trec.db.ip.TrecSLADAO.java
License:Apache License
public boolean addIp(String serviceId, String ipId, String slaId) throws Exception { Session session = null;/*from w ww . ja v a 2s . c om*/ ServiceSla ssla = new ServiceSla(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); ssla.setId(null); ssla.setSlaId(slaId); ssla.setIpId(ipId); ssla.setServiceId(serviceId); session.save(ssla); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); } } catch (Exception e) { logger.info("ERROR " + e.getMessage()); throw new Exception(e.toString()); } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSLADAO.java
License:Apache License
public boolean deleteIP2SPTrust(String serviceId) throws Exception { Session session = null;/* w w w .j av a 2 s . c om*/ SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery("DELETE FROM service_sla WHERE serviceId =:serviceId"); query.setParameter("serviceId", serviceId); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSNProviderDAO.java
License:Apache License
public boolean addSNProvider(String providerId, String providerType) throws Exception { Session session = null;// w w w . ja v a 2 s .c om SnProvider snp = new SnProvider(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); snp.setId(setSnProviderId(providerId, providerType)); session.save(snp); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); } } catch (Exception e) { logger.info("ERROR " + e.getMessage()); throw new Exception(e.toString()); } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSNProviderDAO.java
License:Apache License
public boolean deleteIP(String providerId, String providerType) throws Exception { Session session = null;//from w w w . j a v a 2s. c o m SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery( "DELETE FROM sn_provider WHERE provider_id =:providerId AND provider_type=:providerType"); query.setParameter("providerId", providerId); query.setParameter("providerType", providerType); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSnProviderTrustDAO.java
License:Apache License
public boolean addSnProviderTrust(String providerId, String providerType, double expectation, double belief, double disbelief, double uncertinty, double relativeAutomicity) throws Exception { Session session = null;//from w ww . ja v a 2s .com SnTrustProvider sntp = new SnTrustProvider(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); sntp.setId(null); sntp.setProviderId(providerId); sntp.setProviderType(providerType); sntp.setExpectation(expectation); sntp.setBelief(belief); sntp.setDisbelief(disbelief); sntp.setUncertinty(uncertinty); sntp.setRelativeAutomicity(relativeAutomicity); session.save(sntp); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); } } catch (Exception e) { logger.info("ERROR " + e.getMessage()); throw new Exception(e.toString()); } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java
License:Apache License
public boolean addSnRelationshipTrust(String origin, String originType, String destiny, String destinyType, double expectation, double belief, double disbelief, double uncertinty, double relativeAutomicity) throws Exception { Session session = null;/*w w w .j av a 2 s . c o m*/ SnTrustRelationship sntr = new SnTrustRelationship(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); sntr.setId(null); sntr.setOrigin(origin); sntr.setOriginType(originType); sntr.setDestiny(destiny); sntr.setDestinyType(destinyType); sntr.setExpectation(expectation); sntr.setBelief(belief); sntr.setDisbelief(disbelief); sntr.setUncertinty(uncertinty); sntr.setRelativeAutomicity(relativeAutomicity); session.save(sntr); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); } } catch (Exception e) { logger.info("ERROR " + e.getMessage()); throw new Exception(e.toString()); } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java
License:Apache License
public boolean deleteSnRelationshipByOrigin(String origin, String originType) throws Exception { Session session = null;//from ww w . j av a 2 s . com SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery( "DELETE FROM sn_trust_relationship WHERE origin=:origin AND origin_type=:originType"); query.setParameter("origin", origin); query.setParameter("originType", originType); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSnRelationshipTrustDAO.java
License:Apache License
public boolean deleteSnRelationshipByDestiny(String destiny, String destinyType) throws Exception { Session session = null;// w w w. j a v a2 s . c o m SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery( "DELETE FROM sn_trust_relationship WHERE destiny=:destiny AND destiny_type=:destinyType"); query.setParameter("destiny", destiny); query.setParameter("destinyType", destinyType); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSP2IPDAO.java
License:Apache License
public boolean addSP2IP(String serviceId, String componentId, String spId, String ipId, Date serviceTime, double serviceWellFormed, double safetyRunGap, double elasticityClosely, double ipReactionTime, double slaCompliance, double ipComplianceWithLegal, double serviceTrust) throws Exception { Session session = null;/*from w w w.j a v a 2 s . co m*/ SpToIp sp2ip = new SpToIp(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); sp2ip.setServiceId(serviceId); sp2ip.setServiceComponent(getServiceComponent(componentId)); sp2ip.setSpInfo(getSpInfo(spId)); sp2ip.setIpInfo(getIpInfo(ipId)); sp2ip.setServiceTime(serviceTime); sp2ip.setServiceWellFormed(serviceWellFormed); sp2ip.setSafetyRunGap(safetyRunGap); sp2ip.setElasticityClosely(elasticityClosely); sp2ip.setIpReactionTime(ipReactionTime); sp2ip.setSlaCompliance(slaCompliance); sp2ip.setIpComplianceWithLegal(ipComplianceWithLegal); sp2ip.setServiceTrust(serviceTrust); session.save(sp2ip); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); // System.out.println("Transaction commited"); } } catch (Exception e) { logger.info("ERROR " + e.getMessage()); // System.out.println("ERROR "+ e.getMessage()); throw new Exception(e.toString()); } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecSP2IPDAO.java
License:Apache License
public boolean deleteIPTrust(String serviceId) throws Exception { Session session = null;/* w w w . j a va 2s. co m*/ SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery("DELETE FROM sp_to_ip WHERE service_id =:serviceId"); query.setParameter("serviceId", serviceId); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }