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

public void addProductConnection(Contracts contract, PositionsInContract position) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-products");
    sess.enableFetchProfile("products-with-contracts");
    contract.getProductPositions().add(position);
    sess.update(contract);//from ww w.  j a  v  a  2  s. co m
    sess.save(position);
    Products product = position.getProduct();
    product.getPositionsInContract().add(position);
    sess.update(product);
}

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

public void addContragentConnection(Contracts contract, ContragentsInContract agent) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-contracts");
    sess.enableFetchProfile("contracts-with-clients");
    contract.getContragents().add(agent);
    sess.update(contract);/*from ww w .  ja  v  a 2s  .  co m*/
    sess.save(agent);
    Clients client = agent.getClient();
    client.getParticipantInContracts().add(agent);
    sess.update(client);
}

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

public void deleteContactConnection(Contracts contract, Contacts contact) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-contacts");
    contract.getAddContacts().remove(contact);
    sess.update(contract);/*from  w  w w  . j  a v a2  s .  c  o m*/
    contact.getContractsConnectedWithContact().remove(contract);
    sess.update(contact);
}

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

public void deleteDocumentConnection(Contracts contract, Documents document) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-documents");
    contract.getDocsForContract().remove(document);
    sess.update(contract);//from  w ww.j av  a  2 s  .c  o  m
    document.setContract(null);
    sess.update(contract);
}

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

public void deletePaymentConnection(Contracts contract, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-payments");
    contract.getPaymentsForContract().remove(payment);
    sess.update(contract);//from  w w  w . j a  v  a2s .  c  o m
    payment.setContractOnPayment(null);
    sess.update(contract);
}

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

public void deleteProductConnection(Contracts contract, PositionsInContract position) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-products");
    sess.enableFetchProfile("products-with-contracts");
    contract.getProductPositions().remove(position);
    sess.update(contract);/*from   ww  w. ja  v  a2 s.  com*/
    Products product = position.getProduct();
    product.getPositionsInContract().remove(position);
    sess.update(product);
    sess.delete(position);
}

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

public void deleteContragentConnection(Contracts contract, ContragentsInContract agent) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-contracts");
    sess.enableFetchProfile("contracts-with-clients");
    contract.getContragents().remove(agent);
    sess.update(contract);//from   w w  w.j a v  a 2 s  . c  o  m
    Clients client = agent.getClient();
    client.getParticipantInContracts().remove(agent);
    sess.update(client);
    sess.delete(agent);
}

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

@Override
public void removeContract(Contracts contract) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    contract = (Contracts) sess.get(Contracts.class, contract.getId());
    if (null != contract) {
        List<Contacts> contTemp = contract.getAddContacts();
        List<Documents> docTemp = contract.getDocsForContract();
        List<Payments> payTemp = contract.getPaymentsForContract();
        List<ContragentsInContract> contrTemp = contract.getContragents();
        List<PositionsInContract> prodTemp = contract.getProductPositions();

        if (contTemp != null && contTemp.size() != 0) {
            sess.enableFetchProfile("contracts-with-contacts");
            contTemp = contactsDAO.getFromProxy(contTemp);
            for (Contacts contact : contTemp) {
                contact.getContractsConnectedWithContact().remove(contract);
                sess.update(contact);/*from  w  w  w.j a  v a 2  s .co m*/
            }
        }
        if (payTemp != null && payTemp.size() != 0) {
            sess.enableFetchProfile("contracts-with-payments");
            payTemp = paymentsDAO.getFromProxy(payTemp);
            for (Payments payment : payTemp) {
                payment.setContractOnPayment(null);
                sess.update(payment);
            }

        }

        if (docTemp != null && docTemp.size() != 0) {
            sess.enableFetchProfile("contracts-with-documents");
            docTemp = documentsDAO.getFromProxy(docTemp);
            for (Documents document : docTemp) {
                document.setContract(null);
                sess.update(document);
            }
        }
        if (contrTemp != null && contrTemp.size() != 0) {
            for (ContragentsInContract contragent : contrTemp) {
                sess.delete(contragent);
            }
        }

        if (prodTemp != null && prodTemp.size() != 0) {
            prodTemp = contract.getProductPositions();
            for (PositionsInContract position : prodTemp) {
                sess.delete(position);
            }
        }

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

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

@Override
public List<Documents> getDocumentsforContract(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-documents");
    Contracts contract = (Contracts) sess.get(Contracts.class, id);
    return contract.getDocsForContract();
}

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

@Override
public List<Payments> getPaymentsforContract(Long id) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("contracts-with-payments");
    Contracts contract = (Contracts) sess.get(Contracts.class, id);
    return contract.getPaymentsForContract();

}