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

@Transactional
public void removeUserFromGroup(UserAccount acc, UserGroup group) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("users-with-groups");
    acc = (UserAccount) sess.load(UserAccount.class, acc.getId());
    sess.enableFetchProfile("groups-with-users");
    group = (UserGroup) sess.load(UserGroup.class, group.getId());
    acc.getGroups().remove(group);//w ww .  j ava 2 s . co m
    group.getAccounts().remove(acc);
    updateUser(acc);
    updateGroup(group);
}

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

@Transactional
public void clearGroup(UserGroup group) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("groups-with-users");
    group = (UserGroup) sess.load(UserGroup.class, group.getId());
    Set<UserAccount> users = group.getAccounts();
    for (UserAccount user : users) {
        user.getGroups().remove(group);// w w  w . ja  va  2 s  . c om
        updateUser(user);
    }
    updateGroup(group);
}

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

@Transactional
public void deleteUser(UserAccount account) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("users-with-groups");
    account = (UserAccount) sess.load(UserAccount.class, account.getId());
    Set<UserGroup> groups = account.getGroups();
    account.setGroups(null);//w w w .  ja v a  2 s .com
    for (UserGroup group : groups) {
        group.getAccounts().remove(account);
        updateGroup(group);
    }
    Collection<UserAuthority> authorities = account.getUserAuthorities();
    account.setUserAuthorities(null);
    for (UserAuthority auth : authorities) {
        auth.setAccount(null);
        deleteAuthority(auth);
    }
    sessionFactory.getCurrentSession().delete(account);
}

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

@Transactional
public List<UserAuthority> getAllGroupAuthoritiesFotUser(UserAccount account) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("users-with-groups");
    Boolean reprise = false;//from ww  w .j a v  a2  s .  c  om
    account = (UserAccount) sess.load(UserAccount.class, account.getId());
    Set<UserGroup> groups = account.getGroups();
    List<UserAuthority> nessAuth = new ArrayList<UserAuthority>();
    List<String> Sorted = new ArrayList<String>();
    List<UserAuthority> SortedAuth = new ArrayList<UserAuthority>();
    for (UserGroup group : groups) {
        nessAuth.addAll(group.getAuthorities());
    }
    /*   for(int i=0; i<nessAuth.size(); i++)
       {
     String auth = nessAuth.get(i).getAuthority();
     for (int j=0; j<i; j++)
     {
         if (Sorted.get(j).equals(auth))
         {reprise = true;
         break;}  
     }
     if (reprise==false)
     {
     Sorted.add(auth);
     SortedAuth.add(nessAuth.get(i));
     }
       }
       return SortedAuth;*/
    return nessAuth;

}

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

@Override
public void addOrganisation(Organisations organisation) {
    sessionFactory.getCurrentSession().save(organisation);

    List<Contacts> temp = organisation.getContacts();
    List<ParticipantsInProject> temp2 = organisation.getParticipateInProjects();
    List<Products> temp3 = organisation.getProducts();
    List<Documents> temp4 = organisation.getDocuments();
    List<Payments> temp5 = organisation.getPaymentsFromClient();
    List<Payments> temp6 = organisation.getPaymentsToClient();
    //    List<ContragentsInContract> temp3=customer.getParticipantInContracts();
    //List<ContragentsInShipment> temp4=customer.getParticipantInShipments();
    // List<Requests> temp5 = customer.getRequests(); 

    //add links to documents
    if (temp4 != null && temp4.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-documents");
        temp4 = documentsDAO.getFromProxy(temp4);
        for (Documents doc : temp4) {
            doc.getClients().add(organisation);
            documentsDAO.changeDocument(doc);
        }//from   w  ww  . j  ava2s.  c  o m
    }

    if (temp2 != null && temp2.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-payments");
        temp5 = paymentsDAO.getFromProxy(temp5);
        for (Payments payment : temp5) {
            payment.setPayerOfPayment(organisation);
            paymentsDAO.changePayment(payment);
        }
    }

    if (organisation.getPaymentsToClient() != null) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("clients-with-payments");
        temp6 = paymentsDAO.getFromProxy(organisation.getPaymentsToClient());
        for (Payments payment : temp6) {
            payment.setReceiverOfPayment(organisation);
            paymentsDAO.changePayment(payment);
        }
    }
    if (temp != null && temp.size() != 0) {

        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("organisations-with-contacts");
        temp = contactsDAO.getFromProxy(temp);
        for (Contacts contact : temp) {
            contact.setOrganisation(organisation);
            contactsDAO.changeContact(contact);
        }
    }

    if (temp3 != null && temp3.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        sess.enableFetchProfile("organisations-with-products");
        temp3 = productsDAO.getFromProxy(temp3);
        for (Products product : temp3) {
            product.getManufacturers().add(organisation);
            productsDAO.changeProduct(product);
        }

    }

    if (temp2 != null && temp2.size() != 0) {
        org.hibernate.Session sess = sessionFactory.getCurrentSession();
        for (ParticipantsInProject project : temp2) {
            project.setOrganisation(organisation);
        }

    }
}

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

public void addDocumentConnection(Organisations customer, Documents document) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-documents");
    customer = (Organisations) sess.load(Organisations.class, customer.getId());
    customer.getDocuments().add(document);
    sess.update(customer);/* w w w. j a v a2s . co m*/
    document = (Documents) sess.load(Documents.class, document.getId());
    document.getClients().add(customer);
    sess.update(document);
}

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

public void addPaymentFromConnection(Organisations customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-paymentsFrom");
    customer = (Organisations) sess.load(Organisations.class, customer.getId());
    customer.getPaymentsFromClient().add(payment);
    sess.update(customer);/*ww w . java 2 s  .com*/
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setPayerOfPayment(customer);
    sess.update(payment);
}

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

public void addPaymentToConnection(Organisations customer, Payments payment) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("clients-with-payments");
    customer = (Organisations) sess.load(Organisations.class, customer.getId());
    customer.getPaymentsToClient().add(payment);
    sess.update(customer);// w w  w .j a va2  s  .  co  m
    payment = (Payments) sess.load(Payments.class, payment.getId());
    payment.setReceiverOfPayment(customer);
    sess.update(payment);
}

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

public void addProductConnection(Organisations organisation, Products product) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("organisations-with-products");
    organisation = (Organisations) sess.load(Organisations.class, organisation.getId());
    organisation.getProducts().add(product);
    sess.update(organisation);//from  w w  w .  j a v a 2s  . c  o  m
    product = (Products) sess.load(Products.class, product.getId());
    product.getManufacturers().add(organisation);
    sess.update(product);
}

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

public void addContactConnection(Organisations organisation, Contacts contact) {
    org.hibernate.Session sess = sessionFactory.getCurrentSession();
    sess.enableFetchProfile("organisations-with-contacts");
    organisation = (Organisations) sess.load(Organisations.class, organisation.getId());
    organisation.getContacts().add(contact);
    sess.update(organisation);/*ww w  . j a v  a 2 s .c  om*/
    contact = (Contacts) sess.load(Contacts.class, contact.getId());
    contact.setOrganisation(organisation);
    sess.update(contact);
}