Example usage for org.hibernate SessionFactory close

List of usage examples for org.hibernate SessionFactory close

Introduction

In this page you can find the example usage for org.hibernate SessionFactory close.

Prototype

void close() throws HibernateException;

Source Link

Document

Destroy this SessionFactory and release all resources (caches, connection pools, etc).

Usage

From source file:eu.optimis.common.trec.db.ip.TrecSPinfoDAO.java

License:Apache License

public boolean addSP(String SPName, String spId) throws Exception {
    Session session = null;/*from   ww w.  ja v  a 2  s. com*/
    SpInfo spi = new SpInfo();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        spi.setSpName(SPName);
        spi.setSpId(spId);
        session.save(spi);
        tx.commit();
        if (tx.wasCommitted()) {
            logger.info("Transaction commited");
        }
        addSNProvider(spId);
    } 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.TrecSPinfoDAO.java

License:Apache License

public boolean deleteSP(String sp) throws Exception {
    Session session = null;// ww w  . j a  v  a2 s .  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_info WHERE sp_id =:sp OR sp_name =:sp");
        query.setParameter("sp", sp);
        result = query.executeUpdate();
        tx.commit();
        sf.close();
        deleteSNProvider(sp);
    } 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.TrecSPTrustDAO.java

License:Apache License

public boolean addSp(String spId, double spTrust) throws Exception {
    Session session = null;/*www .  j  a v a 2  s . c om*/
    SpTrust sptrust = new SpTrust();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        sptrust.setId(null);
        sptrust.setSpInfo(getSpInfo(spId));
        sptrust.setSpTrust(spTrust);
        sptrust.setTstamp(new Date());
        session.save(sptrust);
        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.TrecSPTrustDAO.java

License:Apache License

public boolean deleteSPTrust(String sp) throws Exception {
    Session session = null;/*from   w  ww .  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 sp_trust WHERE sp_id =:sp");
        query.setParameter("sp", sp);
        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.sp.TrecIPinfoDAO.java

License:Apache License

public boolean addIp(String IPName, String ipId, String location) throws Exception {
    Session session = null;/*from www. j  a v a 2 s.  c  om*/
    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.sp.TrecIPinfoDAO.java

License:Apache License

public boolean deleteIP(String ip) throws Exception {
    Session session = null;//from w  ww  .  j a  v a 2s.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_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.sp.TrecIPTrustDAO.java

License:Apache License

public boolean addIp(String ipId, double ipTrust) throws Exception {
    Session session = null;//from ww w .  j  a v a  2  s.c  o m
    IpTrust iptrust = new IpTrust();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        iptrust.setId(null);
        iptrust.setIpInfo(getIpInfo(ipId));
        iptrust.setIpTrust(ipTrust);
        iptrust.setTstamp(new Date());
        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.sp.TrecServiceComponentDAO.java

License:Apache License

public boolean addComponentId(String componentId, String serviceId, String componentManifest) throws Exception {
    Session session = null;/*w  ww.  ja v a  2s.  com*/
    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());
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (HibernateException e) {
            }
        }
    }
    sf.close();
    return true;
}

From source file:eu.optimis.common.trec.db.sp.TrecServiceComponentDAO.java

License:Apache License

public boolean deleteIPTrust(String componentId) throws Exception {
    Session session = null;/* w  w w  .  jav 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_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());
    }

    if (result == 0)
        return false;

    return true;
}

From source file:eu.optimis.common.trec.db.sp.TrecServiceInfoDAO.java

License:Apache License

public boolean addService(String serviceId, String serviceProviderId, String serviceManifest, boolean deployed)
        throws Exception {
    Session session = null;//w w  w .  j a v a2 s.  c o  m
    ServiceInfo si = new ServiceInfo();
    SessionFactory sf = eu.optimis.common.trec.db.sp.utils.HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        si.setServiceId(serviceId);
        si.setSpId(serviceProviderId);
        si.setServiceManifest(serviceManifest);
        si.setSlaId(null);
        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;
}