List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:eu.optimis.common.trec.db.ip.TrecIPinfoDAO.java
License:Apache License
public boolean addIp(String IPName, String ipId, String location) throws Exception { Session session = null;//from www . ja v a 2 s .c o m IpInfo ipi = new IpInfo(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); ipi.setName(IPName); ipi.setIpId(ipId); ipi.setIpLocation(location); ipi.setIppType("ip"); session.save(ipi); tx.commit(); if (tx.wasCommitted()) { logger.info("Transaction commited"); // System.out.println("Transaction commited"); } addSNProvider(ipId); } 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.TrecIPinfoDAO.java
License:Apache License
public boolean deleteIP(String ip) throws Exception { Session session = null;/*from ww w . j av 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 ip_info WHERE ip_id =:ip OR name =:ip"); // Query query= // session.createSQLQuery("update ip_info set ip_availibility=0 where ip_id=:ip;"); query.setParameter("ip", ip); result = query.executeUpdate(); tx.commit(); sf.close(); deleteSNProvider(ip); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); // System.out.println("ERROR "+ e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecIPTrustDAO.java
License:Apache License
public boolean addIp(String ipId, double ipTrust) throws Exception { Session session = null;/*from w ww . ja va2 s .com*/ IpTrust iptrust = new IpTrust(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); iptrust.setIpInfo(getIpInfo(ipId)); iptrust.setIpTrust(ipTrust); session.save(iptrust); 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.TrecIPTrustDAO.java
License:Apache License
public boolean deleteIPTrust(String ip) throws Exception { Session session = null;//from w w w.j a v a2 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 ip_trust WHERE ip_id =:ip"); query.setParameter("ip", ip); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); // System.out.println("ERROR "+ e.getMessage()); throw new Exception(e.toString()); } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecServiceComponentDAO.java
License:Apache License
public boolean addComponentId(String componentId, String serviceId, String componentManifest) throws Exception { Session session = null;// w w w. j av a 2s. co m ServiceComponent sc = new ServiceComponent(); SessionFactory sf = HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); sc.setComponentId(componentId); sc.setServiceInfo(getServiceInfo(serviceId)); sc.setComponentManifest(componentManifest); session.save(sc); 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()); throw e; } finally { if (session != null) { try { session.close(); } catch (HibernateException e) { } } } sf.close(); return true; }
From source file:eu.optimis.common.trec.db.ip.TrecServiceComponentDAO.java
License:Apache License
public boolean deleteIPTrust(String componentId) throws Exception { Session session = null;/*from ww w. j a va 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 service_component WHERE component_id =:componentId"); query.setParameter("componentId", componentId); result = query.executeUpdate(); tx.commit(); sf.close(); } catch (Exception e) { logger.error("ERROR " + e.getMessage()); // System.out.println("ERROR "+ e.getMessage()); //throw new Exception(e.toString()); throw e; } if (result == 0) return false; return true; }
From source file:eu.optimis.common.trec.db.ip.TrecServiceInfoDAO.java
License:Apache License
public boolean addService(String serviceId, String serviceProviderId, String serviceManifest, boolean deployed) throws Exception { Session session = null;//from w w w. j a v a2 s .c o m ServiceInfo si = new ServiceInfo(); SessionFactory sf = eu.optimis.common.trec.db.ip.utils.HibernateUtil.getSessionFactory(); try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); si.setServiceId(serviceId); si.setSpId(serviceProviderId); si.setServiceManifest(serviceManifest); si.setDeployed(deployed); session.save(si); 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.TrecServiceInfoDAO.java
License:Apache License
public boolean deleteService(String service) throws Exception { Session session = null;//from www. j a v a 2s. com SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery( "DELETE FROM service_info WHERE service_id =:service OR service_name =:service"); query.setParameter("service", service); 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.TrecServiceInfoDAO.java
License:Apache License
public boolean updateDeployed(String service, boolean deployed) throws Exception { Session session = null;// w w w.j av a2s.c om SessionFactory sf = HibernateUtil.getSessionFactory(); int result = 0; try { session = sf.openSession(); Transaction tx = session.beginTransaction(); tx.begin(); Query query = session.createSQLQuery( "update service_info set deployed=:deploy where service_id=:service or service_name=:service"); query.setParameter("service", service); query.setParameter("deploy", deployed); 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.TrecServiceInfoDAO.java
License:Apache License
public boolean updateSLAid(String service, String slaId) throws Exception { Session session = null;//from w w w. j a v a 2 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( "update service_info set sla_id=:sla where service_id=:service or service_name=:service"); query.setParameter("service", service); query.setParameter("sla", slaId); 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; }