Example usage for org.hibernate Session enableFetchProfile

List of usage examples for org.hibernate Session enableFetchProfile

Introduction

In this page you can find the example usage for org.hibernate Session enableFetchProfile.

Prototype

void enableFetchProfile(String name) throws UnknownProfileException;

Source Link

Document

Enable a particular fetch profile on this session.

Usage

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

public void addPaymentFromConnection(Customers customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-paymentsFrom");
    customer = (Customers) sess.load(Customers.class, customer.getId());
    customer.getPaymentsFromClient().add(payment);
    sess.update(customer);/* w  w w. jav  a2  s  .  c o  m*/
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setPayerOfPayment(customer);
    sess.update(payment);
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

public void addPaymentToConnection(Customers customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-payments");
    customer = (Customers) sess.load(Customers.class, customer.getId());
    customer.getPaymentsToClient().add(payment);
    sess.update(customer);//from  www  .  jav  a  2s  . c o m
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setReceiverOfPayment(customer);
    sess.update(payment);
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

public void deleteDocumentConnection(Customers customer, Documents document) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-documents");
    customer = (Customers) sess.load(Customers.class, customer.getId());
    customer.getDocuments().remove(document);
    sess.update(customer);/*from w w w  .j a va  2  s.c om*/
    document = (Documents) sess.load(Documents.class, document.getId());
    document.getClients().add(customer);
    sess.update(document);
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

public void deletePaymentFrom(Customers customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-paymentsFrom");
    customer = (Customers) sess.load(Customers.class, customer.getId());
    customer.getPaymentsFromClient().remove(payment);
    sess.update(customer);//from   w  ww .  ja  v a2  s  .c o  m
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setPayerOfPayment(null);
    paymentsDAO.removePayment(payment);
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

public void deletePaymentTo(Customers customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-payments");
    customer = (Customers) sess.load(Customers.class, customer.getId());
    customer.getPaymentsToClient().remove(payment);
    sess.update(customer);/*from  w  w w  .j a va2 s  . c o  m*/
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setReceiverOfPayment(null);
    paymentsDAO.removePayment(payment);
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

@Override
public void removeCustomer(Customers customer) {
    if (null != customer) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        customer = (Customers) sess.get(Customers.class, customer.getId());
        List<Documents> temp = customer.getDocuments();
        List<Payments> temp2 = customer.getPaymentsFromClient();
        List<ContragentsInContract> temp3 = customer.getParticipantInContracts();
        List<ContragentsInShipment> temp4 = customer.getParticipantInShipments();
        List<Requests> temp5 = customer.getRequests();

        if (temp != null && temp.size() != 0) {
            sess.enableFetchProfile("clients-with-documents");
            temp = documentsDAO.getFromProxy(temp);
            for (Documents doc : temp) {
                doc.getClients().remove(customer);
                sess.update(doc);/*from w  w w. j av  a  2s .  co m*/
            }
        }

        if (temp2 != null && temp2.size() != 0) {
            sess.enableFetchProfile("clients-with-paymentsFrom");
            temp2 = paymentsDAO.getFromProxy(temp2);
            for (Payments payment : temp2) {
                payment.setPayerOfPayment(null);
                sess.update(payment);
            }
        }

        if (customer.getPaymentsToClient() != null && customer.getPaymentsToClient().size() != 0) {
            sess.enableFetchProfile("clients-with-payments");
            temp2 = paymentsDAO.getFromProxy(customer.getPaymentsToClient());
            for (Payments payment : temp2) {
                payment.setReceiverOfPayment(customer);
                sess.update(payment);
            }
        }

        if (temp3 != null && temp3.size() != 0) {
            for (ContragentsInContract contragent : temp3) {
                sess.delete(contragent);
            }
        }
        if (temp4 != null && temp4.size() != 0) {
            for (ContragentsInShipment contragent : temp4) {
                sess.delete(contragent);
            }
        }
        if (temp5 != null && temp5.size() != 0) {
            sess.enableFetchProfile("clients-with-requests");
            temp5 = requestsDAO.getFromProxy(customer.getRequests());
            for (Requests request : temp5) {
                request.setRequester(null);
                sess.update(request);
            }
        }
        sess.update(customer);
        sessionFactory.getCurrentSession().delete(customer);
    }
}

From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java

@Override
public List<Documents> getDocumentsforCustomer(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-documents");
    Clients customer = (Clients) sess.get(Clients.class, id);
    return customer.getDocuments();
}

From source file:com.mycompany.CRMFly.hibernateAccess.DailyDAOImpl.java

@Override
public void addTask(Daily task) {
    sessionFactory.getCurrentSession().save(task);

    List<Events> temp = task.getEventsConnectedWithTask();
    List<Calls> temp2 = task.getCallsConnectedWithTask();
    List<Contacts> temp3 = task.getContactsConnectedWithTask();

    if (temp != null && temp.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("tasks-with-events");
        temp = eventsDAO.getFromProxy(temp);
        for (Events event : temp) {
            event.getConnectedTasks().add(task);
            eventsDAO.changeEvent(event);
        }/*  w w w .ja  v  a 2 s . c o  m*/

    }

    if (temp2 != null && temp2.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("tasks-with-calls");
        temp2 = callsDAO.getFromProxy(temp2);
        for (Calls call : temp2) {
            call.getTasks().add(task);
            callsDAO.changeCall(call);
        }

    }

    if (temp3 != null && temp3.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("tasks-with-contacts");
        temp3 = contactsDAO.getFromProxy(temp3);
        for (Contacts contact : temp3) {
            contact.getTasks().add(task);
            contactsDAO.changeContact(contact);
        }

    }

}

From source file:com.mycompany.CRMFly.hibernateAccess.DailyDAOImpl.java

@Override
public void removeTask(Daily task) {
    if (null != task) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        task = (Daily) sess.get(Daily.class, task.getId());
        List<Events> temp = task.getEventsConnectedWithTask();
        List<Calls> temp2 = task.getCallsConnectedWithTask();
        List<Contacts> temp3 = task.getContactsConnectedWithTask();

        if (temp != null && temp.size() != 0) {

            sess.enableFetchProfile("tasks-with-events");
            temp = eventsDAO.getFromProxy(temp);
            for (Events event : temp) {
                event.getConnectedTasks().remove(task);
                sess.update(event);/*from   w w  w. j a  va 2 s  .c  o m*/
            }
        }

        if (temp2 != null && temp2.size() != 0) {
            sess.enableFetchProfile("tasks-with-calls");
            temp2 = callsDAO.getFromProxy(temp2);
            for (Calls call : temp2) {
                call.getTasks().remove(task);
                sess.update(call);
            }

        }

        if (temp3 != null && temp3.size() != 0) {
            sess.enableFetchProfile("tasks-with-contacts");
            temp3 = contactsDAO.getFromProxy(temp3);
            for (Contacts contact : temp3) {
                contact.getTasks().remove(task);
                sess.update(contact);
            }

        }
        sess.update(task);
        sessionFactory.getCurrentSession().delete(task);
    }
}

From source file:com.mycompany.CRMFly.hibernateAccess.DailyDAOImpl.java

@Override
public List<Events> getEventsforTask(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("tasks-with-events");
    Daily task = (Daily) sess.get(Daily.class, id);
    return task.getEventsConnectedWithTask();
}