List of usage examples for org.hibernate Session enableFetchProfile
void enableFetchProfile(String name) throws UnknownProfileException;
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public List<Shipments> getShipmentsOnContract(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-shipments"); Contracts contract = (Contracts) sess.get(Contracts.class, id); return contract.getShipmentsOnContract(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public List<Contacts> getAddContactsforContract(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-contacts"); Contracts contract = (Contracts) sess.get(Contracts.class, id); return contract.getAddContacts(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public List<ContragentsInContract> getContragentsForContract(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-contragents"); Contracts contract = (Contracts) sess.get(Contracts.class, id); return contract.getContragents(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public List<PositionsInContract> getPositionsForContract(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-productPos"); Contracts contract = (Contracts) sess.get(Contracts.class, id); return contract.getProductPositions(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public Clients getClientsForPosition(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-clients"); ContragentsInContract contragent = (ContragentsInContract) sess.get(ContragentsInContract.class, id); return contragent.getClient(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
@Override public Products getProductForPosition(Long id) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-products"); PositionsInContract position = (PositionsInContract) sess.get(PositionsInContract.class, id); return position.getProduct(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
public List getStatisticsOnContractsForDates(Date after, Date before) { Calendar afterCalendar = prepareDate(after); Calendar beforeCalendar = prepareDate(before); // after = afterCalendar.getTime(); // before = beforeCalendar.getTime(); Integer yearDif = beforeCalendar.get(Calendar.YEAR) - afterCalendar.get(Calendar.YEAR); Integer monthDif = beforeCalendar.get(Calendar.MONTH) - afterCalendar.get(Calendar.MONTH) + yearDif * 12; List<Statistics> stat = new ArrayList<Statistics>(); org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-clients"); List<Object[]> res = new ArrayList<Object[]>(); // afterCalendar = prepareDate(before); // afterCalendar.add(Calendar.MONTH, -1); for (int i = 0; i < monthDif + 1; i++) { if (monthDif == 0) { } else {//from w w w . j a v a 2 s.c om if (i == 0) { afterCalendar.setTime(beforeCalendar.getTime()); afterCalendar.set(Calendar.DAY_OF_MONTH, 1); } else if (i == monthDif) { beforeCalendar.setTime(afterCalendar.getTime()); afterCalendar.setTime(after); } else { beforeCalendar.setTime(afterCalendar.getTime()); afterCalendar.add(Calendar.MONTH, -1); } } // beforeCalendar.add(Calendar.MONTH, -1); // afterCalendar.add(Calendar.MONTH, -1); Date afterNew = afterCalendar.getTime(); Date beforeNew = beforeCalendar.getTime(); String afterString = afterNew.toString().substring(4, 7); /* List results = sess.createCriteria(Contracts.class) .add( Restrictions.between("begin_date", after, before) ) .setProjection( Projections.projectionList() .add( Projections.sum("totalSum") ) .add( Projections.avg("totalSum") ) .add( Projections.rowCount() ) //.add( Projections.max("totalSum") ) ).list();*/ Query query = sess.createQuery("select '" + afterString + "', sum(contracts.totalSum), " + "avg(contracts.totalSum), count(contracts) " + "from com.mycompany.CRMFly.entities.Contracts contracts " + " where contracts.begin_date between :date1 and :date2"); query.setParameter("date1", afterNew); query.setParameter("date2", beforeNew); List list = query.list(); if (list != null && list.size() != 0) { for (Iterator it = list.iterator(); it.hasNext();) { Object[] row = (Object[]) it.next(); stat.add(new Statistics(row)); } } } return stat; }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
public List getStatisticsOnClientsForDates(Date after, Date before) { Calendar afterCalendar = prepareDate(after); Calendar beforeCalendar = prepareDate(before); List<Statistics> stat = new ArrayList<Statistics>(); org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("contracts-with-clients"); Query query = sess.createQuery("select contr.name, sum(contracts.totalSum), " + "avg(contracts.totalSum), count(contracts) " + "from com.mycompany.CRMFly.entities.Contracts contracts " + "inner join contracts.contragents " + "contr where " + "contracts.begin_date between :date1 and :date2 " + "group by contr.name "); query.setParameter("date1", after); query.setParameter("date2", before); List list = query.list();//from w ww . j a v a2 s.com for (Iterator it = list.iterator(); it.hasNext();) { Object[] row = (Object[]) it.next(); stat.add(new Statistics(row)); } return stat; }
From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java
@Override public void addCustomer(Customers customer) { sessionFactory.getCurrentSession().save(customer); 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(); //add links to documents if (temp != null && temp.size() != 0) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("clients-with-documents"); temp = documentsDAO.getFromProxy(temp); for (Documents doc : temp) { doc.getClients().add(customer); documentsDAO.changeDocument(doc); }/*from ww w .ja v a 2 s.com*/ } if (temp2 != null && temp2.size() != 0) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("clients-with-paymentsFrom"); temp2 = paymentsDAO.getFromProxy(temp2); for (Payments payment : temp2) { payment.setPayerOfPayment(customer); paymentsDAO.changePayment(payment); } } if (customer.getPaymentsToClient() != null) { org.hibernate.Session sess = sessionFactory.getCurrentSession(); sess.enableFetchProfile("clients-with-payments"); temp2 = paymentsDAO.getFromProxy(customer.getPaymentsToClient()); for (Payments payment : temp2) { payment.setReceiverOfPayment(customer); paymentsDAO.changePayment(payment); } } }
From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java
public void addDocumentConnection(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().add(document); sess.update(customer);//from www . j a v a 2s.c o m document = (Documents) sess.load(Documents.class, document.getId()); document.getClients().add(customer); sess.update(document); }