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.sp.TrecServiceInfoDAO.java

License:Apache License

public boolean updateDeployed(String service, boolean deployed) throws Exception {
    Session session = null;// w  ww  . ja  v  a  2 s.co  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 deployed=:deploy where service_id=: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.sp.TrecServiceInfoDAO.java

License:Apache License

public boolean updateSLAid(String service, String slaId) throws Exception {
    Session session = null;//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("update service_info set sla_id=:sla where service_id=: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;
}

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

License:Apache License

public boolean deleteProvider(String providerId, String providerType) 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_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.sp.TrecSPinfoDAO.java

License:Apache License

public boolean addSP(String SPName, String spId) throws Exception {
    Session session = null;//from   w  ww.  j  a  va 2  s. c o m
    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.sp.TrecSPTrustDAO.java

License:Apache License

public boolean addSp(String spId, double spTrust) throws Exception {
    Session session = null;/*from w  w w .  j  ava  2  s  .  c  o  m*/
    SpTrust sptrust = new SpTrust();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();
        sptrust.setId(null);
        sptrust.setTstamp(new Date());
        sptrust.setSpInfo(getSpInfo(spId));
        sptrust.setSpTrust(spTrust);

        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.sp.TrecSPTrustDAO.java

License:Apache License

public boolean deleteIPTrust(String sp) throws Exception {
    Session session = null;//from w w  w  .j av  a 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_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.ecoefficiencytool.trecdb.ip.EcoIpTableDAO.java

License:Open Source License

public static Integer addEcoAssessment(double energyEffAssessment, double ecologicalEffAssessment,
        double performance, double power, double grCO2) throws Exception {
    Session session = null;//  w  ww .j av  a  2s .  c  o  m
    Integer ret = null;
    IpEcoIpTable ipTable = new IpEcoIpTable();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();

        ipTable.setEnergyEffIp(energyEffAssessment);
        ipTable.setEcologicalEffIp(ecologicalEffAssessment);
        ipTable.setPerformanceIp(performance);
        ipTable.setPowerIp(power);
        ipTable.setGrCo2sIp(grCO2);

        ret = (Integer) session.save(ipTable);
        tx.commit();
        if (tx.wasCommitted()) {
            log.debug("Infrastructure assessment was commited correctly with id " + ret.toString() + ".");
        } else {
            log.error("Unable to insert infrastructure assessment data.");
        }
    } catch (Exception e) {
        log.error("Unable to insert infrastructure assessment data: " + e.getMessage());
        throw new Exception(e.toString());
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (HibernateException e) {
            }
        }
    }
    sf.close();
    return ret;
}

From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoNodeTableDAO.java

License:Open Source License

public static Integer addEcoAssessment(String nodeId, double energyEffAssessment,
        double ecologicalEffAssessment, double performance, double power, double grCO2) throws Exception {
    Session session = null;/*from   w w  w .  ja v a  2 s .co  m*/
    Integer ret = null;
    IpEcoNodeTable nodeTable = new IpEcoNodeTable();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();

        nodeTable.setNodeId(nodeId);
        nodeTable.setEnergyEffNode(energyEffAssessment);
        nodeTable.setEcologicalEffNode(ecologicalEffAssessment);
        nodeTable.setPerformanceNode(performance);
        nodeTable.setPowerNode(power);
        nodeTable.setGrCo2sNode(grCO2);

        ret = (Integer) session.save(nodeTable);
        tx.commit();
        if (tx.wasCommitted()) {
            log.debug("Node " + nodeId + " assessment was commited correctly with id " + ret.toString() + ".");
        } else {
            log.error("Unable to insert node " + nodeId + " assessment data.");
        }
    } catch (Exception e) {
        log.error("Unable to insert node " + nodeId + " assessment data: " + e.getMessage());
        throw new Exception(e.toString());
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (HibernateException e) {
            }
        }
    }
    sf.close();
    return ret;
}

From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoServiceTableDAO.java

License:Open Source License

public static Integer addEcoAssessment(String serviceId, double energyEffAssessment,
        double ecologicalEffAssessment, double performance, double power, double grCO2) throws Exception {
    Session session = null;//from  w  w w.j  a  v  a  2 s  . c o  m
    Integer ret = null;
    IpEcoService serviceTable = new IpEcoService();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();

        serviceTable.setServiceId(serviceId);
        serviceTable.setEnergyEffService(energyEffAssessment);
        serviceTable.setEcologicalEffService(ecologicalEffAssessment);
        serviceTable.setPerformanceService(performance);
        serviceTable.setPowerService(power);
        serviceTable.setGrCo2sService(grCO2);

        ret = (Integer) session.save(serviceTable);
        tx.commit();
        if (tx.wasCommitted()) {
            log.debug("Service " + serviceId + " assessment was commited correctly with id " + ret.toString()
                    + ".");
        } else {
            log.error("Unable to insert service " + serviceId + " assessment data.");
        }
    } catch (Exception e) {
        log.error("Unable to insert service " + serviceId + " assessment data: " + e.getMessage());
        throw new Exception(e.toString());
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (HibernateException e) {
            }
        }
    }
    sf.close();
    return ret;
}

From source file:eu.optimis.ecoefficiencytool.trecdb.ip.EcoVMTableDAO.java

License:Open Source License

public static Integer addEcoAssessment(String vmId, double energyEffAssessment, double ecologicalEffAssessment,
        double performance, double power, double grCO2) throws Exception {
    Session session = null;//ww w  . j av a2 s . co m
    Integer ret = null;
    IpEcoVmTable vmTable = new IpEcoVmTable();
    SessionFactory sf = HibernateUtil.getSessionFactory();
    try {
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        tx.begin();

        vmTable.setVmId(vmId);
        vmTable.setEnergyEffVm(energyEffAssessment);
        vmTable.setEcologicalEffVm(ecologicalEffAssessment);
        vmTable.setPerformanceVm(performance);
        vmTable.setPowerVm(power);
        vmTable.setGrCo2sVm(grCO2);

        ret = (Integer) session.save(vmTable);
        tx.commit();
        if (tx.wasCommitted()) {
            log.debug("VM " + vmId + " assessment was commited correctly with id " + ret.toString() + ".");
        } else {
            log.error("Unable to insert VM " + vmId + " assessment data.");
        }
    } catch (Exception e) {
        log.error("Unable to insert VM " + vmId + " assessment data: " + e.getMessage());
        throw new Exception(e.toString());
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (HibernateException e) {
            }
        }
    }
    sf.close();
    return ret;
}