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.ClientsDAOImpl.java

public List<Shipments> getShipmentsForClient(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-rolesShip");
    sess.enableFetchProfile("clients-with-shipments");
    Clients client = (Clients) sess.get(Clients.class, id);
    List<Shipments> returnList = new ArrayList<Shipments>();
    List<ContragentsInShipment> shipList = client.getParticipantInShipments();
    for (ContragentsInShipment con : shipList) {
        returnList.add(con.getShipment());
    }//from  w  w w.jav  a 2 s. c  om
    return returnList;
}

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

@Override
public List<ContragentsInContract> getParticipationInContract(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-rolesCont");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getParticipantInContracts();
}

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

@Override
public List<ContragentsInShipment> getParticipationInShipments(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-rolesShip");
    Clients client = (Clients) sess.get(Clients.class, id);
    return client.getParticipantInShipments();
}

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

@Override
public Contracts getContractForPosition(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-contracts");
    ContragentsInContract client = (ContragentsInContract) sess.get(ContragentsInContract.class, id);
    return client.getContract();
}

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

@Override
public Shipments getShipmentForPosition(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-shipments");
    ContragentsInShipment client = (ContragentsInShipment) sess.get(ContragentsInShipment.class, id);
    return client.getShipment();
}

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

@Override
public void addContact(Contacts contact) {

    List<Calls> temp = contact.getCalls();
    List<Daily> temp2 = contact.getTasks();
    List<Contracts> temp3 = contact.getContractsConnectedWithContact();
    boolean first = (temp != null && temp.size() != 0) ? true : false;
    boolean second = (temp2 != null && temp2.size() != 0) ? true : false;
    boolean third = (temp3 != null && temp3.size() != 0) ? true : false;
    sessionFactory.getCurrentSession().save(contact);

    if (first) {/*  w  w  w  . ja  va  2  s  .  c o  m*/
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("contacts-with-calls");
        temp = callsDAO.getFromProxy(temp);
        for (Calls call : temp) {
            call.setContactForCall(contact);
            callsDAO.changeCall(call);
        }

    }

    if (second) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("contacts-with-tasks");
        temp2 = dailyDAO.getFromProxy(temp2);
        for (Daily task : temp2) {
            task.getContactsConnectedWithTask().add(contact);
            dailyDAO.changeTask(task);
        }

    }

    if (third) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("contacts-with-contracts");
        temp3 = contractsDAO.getFromProxy(temp3);
        for (Contracts contract : temp3) {
            contract.getAddContacts().add(contact);
            contractsDAO.changeContract(contract);
        }

    }
}

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

public void addCallConnection(Contacts contact, Calls call) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contacts-with-calls");
    contact = (Contacts) sess.load(Contacts.class, contact.getId());
    contact.getCalls().add(call);//from   ww w  .jav a 2  s  .  c  o  m
    call.setContactForCall(contact);
    //     this.getCallsOfContact(contact.getId()).add(call);
    // contact.getCalls().add(call);
    sess.update(contact);
    //  call = (Calls) sess.get(Calls.class, call.getId());
    //   Contacts oldContact = call.getContactForCall();
    //   if(oldContact!=null)
    //   oldContact.getCalls().remove(call);
    //   sess.update(oldContact);

    //    sess.merge(call);
}

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

public void addTaskConnection(Contacts contact, Daily task) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contacts-with-tasks");
    contact = (Contacts) sess.load(Contacts.class, contact.getId());
    contact.getTasks().add(task);//from  ww  w  .ja v  a  2s . c o  m
    sess.update(contact);
    task = (Daily) sess.load(Daily.class, task.getId());
    task.getContactsConnectedWithTask().add(contact);
    sess.update(task);
}

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

public void addContractConnection(Contacts contact, Contracts contract) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contacts-with-contracts");
    contact = (Contacts) sess.load(Contacts.class, contact.getId());
    contact.getContractsConnectedWithContact().add(contract);
    sess.update(contact);//from  w  w w  .  ja  v  a  2  s  .c  o  m
    contract = (Contracts) sess.load(Contracts.class, contract.getId());
    contract.getAddContacts().add(contact);
    sess.update(contract);
}

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

public void deleteCall(Contacts contact, Calls call) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contacts-with-calls");
    contact = (Contacts) sess.load(Contacts.class, contact.getId());
    contact.getCalls().remove(call);/*from  w w w.  ja  v a 2 s.c  om*/
    callsDAO.removeCall(call);
    sess.update(contact);

}