@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criterion tmp1 = Expression.between("deadline", startDate, endDate); Criterion tmp2 = Expression.eq("warningTypes", wtype); Criteria crt = session.createCriteria(Warnings.class).add(Expression.and(tmp1, tmp2)); crt.createAlias("lending", "l").createAlias("l.users", "u").createAlias("warningTypes", "w"); crt.setProjection(Projections.projectionList() .add(Projections.property("warnNo")) .add(Projections.property("w.name")) .add(Projections.property("wdate")) .add(Projections.property("deadline")) .add(Projections.property("u.userId")) .add(Projections.property("u.lastName")) .add(Projections.property("u.firstName")) .add(Projections.property("l.ctlgNo")) .add(Projections.property("l.returnDate")) .add(Projections.property("note"))); list = crt.list(); tx.commit(); }catch (Exception e){ log.error(e); } }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criteria crt = session.createCriteria(Users.class); crt.add(Expression.isNotNull("blockReasons")); crt.add(Expression.not(Expression.like("blockReasons",""))); crt.addOrder(Order.desc("blockReasons")); if (!location.equals(" ")) { crt.createAlias("signings", "s"); crt.add(Expression.eq("s.location", location)); crt.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); } if (crt != null) { list = crt.list(); } tx.commit(); log.info("Blocked report"); }catch (Exception e){ log.error("Blocked report failed"); log.error(e); } }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criteria crt = session.createCriteria(Users.class); Criteria signcrt = crt.createCriteria("signings"); signcrt.add(Expression.between("signDate", start, end)); signcrt.add(Expression.or(Expression.isNull("cost"),Expression.eq("cost", 0.0))); if (!location.equals(" ")) { signcrt.add(Expression.eq("location", location)); } if (crt != null) { num = crt.list().size(); } tx.commit(); log.info("FreeSigning report"); }catch (Exception e){ log.error("FreeSigning report failed"); log.error(e); } }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criteria crt = session.createCriteria(Groups.class); // if (!location.equals(" ")) { // Criteria crt1 = crt.createCriteria("userses"); // Criteria crt2 = crt1.createCriteria("signings"); // crt2.add(Expression.eq("location", location)); // } if (!location.equals("")) { crt.add(Expression.like("userId", location+"%")); } if (crt != null) { list = crt.list(); } tx.commit(); log.info("Groups report"); }catch (Exception e){ log.error("Groups report failed"); log.error(e); } }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criteria crt = session.createCriteria(Users.class); Criteria signcrt = crt.createCriteria("signings"); signcrt.add(Expression.between("signDate", start, end)); if (!location.equals(" ")) { signcrt.add(Expression.eq("location", location)); } if (crt != null) { num = crt.list().size(); } tx.commit(); log.info("UsersNumber report"); }catch (Exception e){ log.error("UsersNumber report failed"); log.error(e); } }
@Override public void execute() { try{ Transaction tx = session.beginTransaction(); Criteria crt = session.createCriteria(Users.class); Criteria crt1 = crt.createCriteria("signings"); crt1.add(Expression.between("signDate", start,end)); crt.add(Expression.eq("groups", group)); if (!location.equals(" ")) { crt1.add(Expression.eq("location", location)); } if (crt != null) { list = crt.list(); } tx.commit(); log.info("MemberByGroup report"); }catch (Exception e){ log.error("MemberByGroup report failed"); log.error(e); } }
/** * Finds Tasks who are valid candidates to be added as children to the passed Task. This finds Tasks in the same * groups and who are not already children or parents of the passed Task. * * @param task Task to find candidate children for. * @return Set of candidate child Tasks. */ public Set<Task> findCandidateChildren(final Task task) { final Set<Long> parentTasklds = task.getParentTaskIds(true); final Set<Long> childTaskIds = task.getChildTaskIds(false); List<Task> taskList = (List<Task>) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { Criteria criteria = session.createCriteria(Task.class); criteria.add(Expression.eq("groupName", task.getGroupName())); criteria.add(Expression.not(Expression.eq("id", task.getId()))); if (!parentTasklds.isEmpty()) { criteria.add(Expression.not(Expression.in("id", parentTasklds))); } if (!childTaskIds.isEmpty()) { criteria.add(Expression.not(Expression.in("id", childTaskIds))); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); } }); return new HashSet<Task>(taskList); }
public void testJunctionNotExpressionQBE() throws Exception { deleteData(); initData(); Session s = openSession(); Transaction t = s.beginTransaction(); Componentizable master = getMaster("hibernate", null, "ope%"); Criteria crit = s.createCriteria(Componentizable.class); Example ex = Example.create(master).enableLike(); crit.add(Expression.or(Expression.not(ex), ex)); List result = crit.list(); assertNotNull(result); assertEquals(2, result.size()); t.commit(); s.close(); }
public void testCriteriaCollection() throws Exception { Session s = openSession(); Fum fum = new Fum( fumKey("fum") ); fum.setFum("a value"); fum.getMapComponent().getFummap().put("self", fum); fum.getMapComponent().getStringmap().put("string", "a staring"); fum.getMapComponent().getStringmap().put("string2", "a notha staring"); fum.getMapComponent().setCount(1); s.save(fum); s.flush(); s.connection().commit(); s.close(); s = openSession(); Fum b = (Fum) s.createCriteria(Fum.class).add( Expression.in("fum", new String[] { "a value", "no value" } ) ) .uniqueResult(); //assertTrue( Hibernate.isInitialized( b.getMapComponent().getFummap() ) ); assertTrue( Hibernate.isInitialized( b.getMapComponent().getStringmap() ) ); assertTrue( b.getMapComponent().getFummap().size()==1 ); assertTrue( b.getMapComponent().getStringmap().size()==2 ); s.delete(b); s.flush(); s.connection().commit(); s.close(); }
public void testCriteria() throws Exception { Session s = openSession(); Transaction t = s.beginTransaction(); Lower l = new Lower(); s.save(l); assertTrue( l==s.createCriteria(Top.class).uniqueResult() ); s.delete(l); s.flush(); Criteria c = s.createCriteria(Lower.class); c.createCriteria("yetanother") .add( Expression.isNotNull("id") ) .createCriteria("another"); c.createCriteria("another").add( Expression.isNotNull("id") ); c.list(); t.commit(); s.close(); }
public void testManyToManyFilterOnCriteria() { TestData testData = new TestData(); testData.prepare(); Session session = openSession(); session.enableFilter( "effectiveDate" ).setParameter( "asOfDate", new Date() ); Product prod = ( Product ) session.createCriteria( Product.class ) .setResultTransformer( new DistinctRootEntityResultTransformer() ) .add( Expression.eq( "id", testData.prod1Id ) ) .uniqueResult(); assertNotNull( prod ); assertEquals( "Incorrect Product.categories count for filter", 1, prod.getCategories().size() ); session.close(); testData.release(); }
private DetachedCriteria getAttributeOrderCriteria(String template, DetachedCriteria ciCrit, DetachedCriteria ci2Crit, OrderInfo info) { if (info.getAttrType().equals("complex")) { return(getComplexAttributeOrderCriteria2(template, ciCrit, ci2Crit, info)); } DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class); DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId")); crit.add(Property.forName("ownerId").in(ciIdProjection)); crit.add(Expression.eq("alias", info.getAttrAlias())); if (info.isDescenden()) { crit.addOrder(Order.desc(info.getAttrType())); } else { crit.addOrder(Order.asc(info.getAttrType())); } return(crit); }
private DetachedCriteria getComplexAttributeOrderCriteria(String template, DetachedCriteria ciCrit, OrderInfo info) { DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class); DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId")); crit.add(Property.forName("ownerId").in(ciIdProjection)); crit.add(Expression.eq("alias", info.getAttrAlias())); //crit.add(Expression.isNotEmpty("valueAsLong")); ICi ci = this.msvc.findCi(new Path(template)); IAttribute attr = ci.getAttributeDefinitionWithAlias(info.getAttrAlias()); IType type = attr.getValueType(); String targetTemplate = type.getAlias(); DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class); refCrit.add(Property.forName("longId").in(crit.setProjection(Projections.property("valueAsLong")))); DetachedCriteria refCiCrit = DetachedCriteria.forClass(ConfigurationItem.class); refCiCrit.add(Property.forName("longId").in(refCrit.setProjection(Projections.property("targetId")))); return(getDisplayNameOrder(targetTemplate, refCiCrit, info)); }
private DetachedCriteria getBackComplexAttributeOrder(List<Long> attrOwnerId, DetachedCriteria ci2Crit, OrderInfo info) { DetachedCriteria targetCrit = DetachedCriteria.forClass(ConfigurationItem.class); targetCrit.add(Property.forName("longId").in(attrOwnerId)); DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class); refCrit.add(Property.forName("targetId").in(targetCrit.setProjection(Projections.property("longId")))); DetachedCriteria attrCrit = DetachedCriteria.forClass(BasicAttribute.class); attrCrit.add(Property.forName("valueAsLong").in(refCrit.setProjection(Projections.property("longId")))); attrCrit.add(Property.forName("ownerId").in(ci2Crit.setProjection(Projections.property("longId")))); attrCrit.add(Expression.eq("alias", info.getAttrAlias())); attrCrit.addOrder(Order.desc("longId")); return(attrCrit); }
public DetachedCriteria getCriteria() { DetachedCriteria crit = null; if (type == null) { type = ItemRFCSelector.RFC_ANY_TYPE; } if (type.equals(ItemRFCSelector.RFC_ANY_TYPE)) { crit = DetachedCriteria.forClass(RFC.class); } else if (type.equals(ItemRFCSelector.RFC_MODIFY_VALUE_TYPE)) { crit = DetachedCriteria.forClass(RFCModifyAttributeValue.class); } else if (type.equals(ItemRFCSelector.RFC_NEW_CI_TYPE)) { crit = DetachedCriteria.forClass(RFCNewCi.class); } //crit.addOrder( Order.desc("ts") ); if (this.txId != null) { crit.add(Expression.eq("txId", this.txId)); } return(crit); }
private Criterion getCriterion(String valueType, Object value) { switch(operation) { case AttributeValueConstraint.EQUALS: return(Expression.eq(valueType, value)); case AttributeValueConstraint.GREATER_THAN: return(Expression.gt(valueType, value)); case AttributeValueConstraint.LESS_THAN: return(Expression.lt(valueType, value)); case AttributeValueConstraint.GREATER_THAN_OR_EQUAL: return(Expression.ge(valueType, value)); case AttributeValueConstraint.LESS_THAN_OR_EQUAL: return(Expression.le(valueType, value)); case AttributeValueConstraint.LIKE: return(Expression.ilike(valueType, value)); case AttributeValueConstraint.CONTAINS: break; case AttributeValueConstraint.IS_NULL: return(Expression.isNull(valueType)); } return(Expression.conjunction()); }
public List query(String entityName, HashMap<String, Object> map) { // Quering the db. Session session = getSession(); try { Profiler.start("query(" + entityName +")"); Criteria criteria = session.createCriteria(entityName); for (String key : map.keySet()) { Object value = map.get(key); if (value == null) { criteria.add(Expression.isNull(key)); } else { criteria.add(Expression.eq(key, map.get(key))); } } List objects = criteria.list(); return (objects); } finally { Profiler.stop(); closeSession(session); } }
@Override protected DetachedCriteria getCriteria() { // Select Target/Source attribute id. DetachedCriteria attrTarget = DetachedCriteria.forClass(BasicAttribute.class); attrTarget.add(Expression.eq("valueAsLong", targetId)); attrTarget.add(Expression.eq("alias", "target")); DetachedCriteria relOwnerCrit = attrTarget.setProjection(Projections.property("ownerId")); DetachedCriteria relCi = DetachedCriteria.forClass(ConfigurationItem.class); relCi.add(Property.forName("longId").in(relOwnerCrit)); relCi.add(Expression.eq("derivedFromId", referenceTemplateId)); DetachedCriteria targetOwnerCrit = relCi.setProjection(Projections.property("longId")); DetachedCriteria attrSource = DetachedCriteria.forClass(BasicAttribute.class); attrSource.add(Expression.eq("alias", "source")); attrSource.add(Property.forName("ownerId").in(targetOwnerCrit)); DetachedCriteria sourceIdCrit = attrSource.setProjection(Projections.property("valueAsLong")); DetachedCriteria sourceCi = DetachedCriteria.forClass(ConfigurationItem.class); sourceCi.add(Property.forName("longId").in(sourceIdCrit)); return(sourceCi); }
/** * * @param aClass the class to search for * @param aKey the key to search for * @return */ protected Object selectObjectByKey(Class aClass, String aKey) throws NoDataFoundException { if(aClass == null) throw new IllegalArgumentException("aClass required in HibernateDAO.selectByKey"); Criteria crit = session.createCriteria(aClass); crit.add( Expression.eq("key", aKey) ); crit.setMaxResults(1); List results = crit.list(); if(results.isEmpty()) { throw new NoDataFoundException("class="+aClass.getName()+" key="+aKey); } return results.iterator().next(); }
/** * * @param aClass the class to select * @param aProperty the class property to compare * @param aValue the value of the property * @return * @throws NoDataFoundException */ protected Collection selectObjectsByProperty(Class aClass, String aProperty, Object aValue) throws NoDataFoundException { if(aClass == null) throw new IllegalArgumentException("aClass required in HibernateDAO.selectByKey"); Criteria crit = session.createCriteria(aClass); crit.add( Expression.eq(aProperty, aValue) ); List results = crit.list(); if(results == null || results.isEmpty()) { throw new NoDataFoundException("class="+aClass.getName()+aProperty+" ="+aValue); } return results; }
/** * Select objects by property in * @param aClass the class to select * @param aProperty the property of the class * @param aValues the values to compare * @return Collection of the classes * @throws NoDataFoundException */ protected Collection selectObjectsByPropertyIn(Class aClass, String aProperty, Object[] aValues) throws NoDataFoundException { if(aValues == null || aValues.length == 0) throw new RequiredException("Values in HibernateDAO.selectObjectsByPropertyIn"); if(aClass == null) throw new IllegalArgumentException("aClass required in HibernateDAO.selectByKey"); Criteria crit = session.createCriteria(aClass); crit.add( Expression.in(aProperty, aValues)); List results = crit.list(); if(results.isEmpty()) { throw new NoDataFoundException("class="+aClass.getName()+aProperty+" ="+Debugger.toString(aValues)); } return results; }
public RWikiCurrentObject findByGlobalName(final String name) { long start = System.currentTimeMillis(); try { // there is no point in sorting by version, since there is only one // version in // this table. // also using like is much slower than eq HibernateCallback<List> callback = session -> session .createCriteria(RWikiCurrentObject.class) .add(Expression.eq("name", name)) .list(); List found = getHibernateTemplate().execute(callback); if (found.size() == 0) { log.debug("Found {} objects with name {}", found.size(), name); return null; } log.debug("Found {} objects with name {} returning most recent one.", found.size(), name); return (RWikiCurrentObject) proxyObject(found.get(0)); } finally { long finish = System.currentTimeMillis(); TimeLogger.printTimer("RWikiObjectDaoImpl.findByGlobalName: " + name, start, finish); } }
public RWikiCurrentObject getRWikiCurrentObject(final RWikiObject reference) { long start = System.currentTimeMillis(); try { HibernateCallback<List> callback = session -> session.createCriteria(RWikiCurrentObject.class) .add(Expression.eq("id", reference.getRwikiobjectid())) .list(); List found = getHibernateTemplate().execute(callback); if (found.size() == 0) { log.debug("Found {} objects with id {}", found.size(), reference.getRwikiobjectid()); return null; } log.debug("Found {} objects with id {} returning most recent one.", found.size(), reference.getRwikiobjectid()); return (RWikiCurrentObject) proxyObject(found.get(0)); } finally { long finish = System.currentTimeMillis(); TimeLogger.printTimer("RWikiCurrentObjectDaoImpl.getRWikiCurrentObject: " + reference.getName(), start, finish); } }
public RWikiObjectContent getContentObject(final RWikiObject parent) { long start = System.currentTimeMillis(); try { HibernateCallback<List> callback = session -> session.createCriteria( RWikiCurrentObjectContent.class).add( Expression.eq("rwikiid", parent.getId())).list(); List found = getHibernateTemplate().execute(callback); if (found.size() == 0) { log.debug("Found {} objects with id {}", found.size(), parent.getId()); return null; } log.debug("Found {} objects with name {} returning most recent one.", found.size(), parent.getId()); return (RWikiObjectContent) found.get(0); } finally { long finish = System.currentTimeMillis(); TimeLogger.printTimer( "RWikiCurrentObjectContentDaoImpl.getContentObject: " + parent.getId(), start, finish); } }
public Gradebook getGradebookByTitleAndContext(final String title, final String context) { if (title == null || context == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback hcb = session -> { Criteria crit = session.createCriteria(GradebookImpl.class).add( Expression.eq(TITLE, title)).add(Expression.eq(CONTEXT, context)) .setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook gradebook = (Gradebook) crit.uniqueResult(); return gradebook; }; return (Gradebook) getHibernateTemplate().execute(hcb); } }
public SortedSet getStudentGradesForGradebook(final Gradebook gradebook) throws IllegalArgumentException { if (gradebook == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback hcb = session -> { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(Gradebook.class).add( Expression.eq(ID, gradebook.getId())).setFetchMode(STUDENTS, FetchMode.EAGER); Gradebook grades = (Gradebook) crit.uniqueResult(); if (grades != null) { return grades.getStudents(); } return new TreeSet(); }; return (SortedSet) getHibernateTemplate().execute(hcb); } }
public StudentGrades getStudentByGBAndUsername(final Gradebook gradebook, final String username) { if (gradebook == null || username == null) { throw new IllegalArgumentException("Null gradebookId or username passed to getStudentByGBIdAndUsername"); } HibernateCallback hcb = session -> { gradebook.setStudents(null); Criteria crit = session.createCriteria(StudentGradesImpl.class).add( Expression.eq("gradebook", gradebook)).add(Expression.eq("username", username).ignoreCase()); StudentGrades student = (StudentGrades)crit.uniqueResult(); return student; }; return (StudentGrades) getHibernateTemplate().execute(hcb); }
public int getChannelMessagesCount(ChatChannel channel, String context, Date date) { if (channel == null) { // default to the first one List<ChatChannel> channels = getContextChannels(context, true); if (channels != null && channels.size() > 0) { channel = channels.iterator().next(); } } int count = 0; if (channel != null) { Criteria c = this.getSessionFactory().getCurrentSession().createCriteria(ChatMessage.class); c.add(Expression.eq("chatChannel", channel)); if (date != null) { c.add(Expression.ge("messageDate", date)); } c.setProjection(Projections.rowCount()); count = ((Long) c.uniqueResult()).intValue(); } return count; }
public List<SiteVisits> getSiteVisits(final String siteId, final Date iDate, final Date fDate) { if(siteId == null){ throw new IllegalArgumentException("Null siteId"); }else{ HibernateCallback<List<SiteVisits>> hcb = session -> { Criteria c = session.createCriteria(SiteVisitsImpl.class) .add(Expression.eq("siteId", siteId)); if(iDate != null) c.add(Expression.ge("date", iDate)); if(fDate != null){ // adjust final date Calendar ca = Calendar.getInstance(); ca.setTime(fDate); ca.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = ca.getTime(); c.add(Expression.lt("date", fDate2)); } return c.list(); }; return getHibernateTemplate().execute(hcb); } }
public List<SiteActivity> getSiteActivity(final String siteId, final List<String> events, final Date iDate, final Date fDate) { if(siteId == null){ throw new IllegalArgumentException("Null siteId"); }else{ HibernateCallback<List<SiteActivity>> hcb = session -> { Criteria c = session.createCriteria(SiteActivityImpl.class) .add(Expression.eq("siteId", siteId)) .add(Expression.in("eventId", events)); if(iDate != null) c.add(Expression.ge("date", iDate)); if(fDate != null){ // adjust final date Calendar ca = Calendar.getInstance(); ca.setTime(fDate); ca.add(Calendar.DAY_OF_YEAR, 1); Date fDate2 = ca.getTime(); c.add(Expression.lt("date", fDate2)); } return c.list(); }; return getHibernateTemplate().execute(hcb); } }
public List isFerpaEnabled(final Collection agentUuids) { if (log.isDebugEnabled()) { log.debug("isFerpaEnabled(Set {})", agentUuids); } if (agentUuids == null || agentUuids.isEmpty()) { throw new IllegalArgumentException("Illegal Set agentUuids argument!"); } final HibernateCallback hcb = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { final Criteria c = session.createCriteria(SakaiPersonImpl.class); c.add(Expression.in(AGENT_UUID, agentUuids)); c.add(Expression.eq(FERPA_ENABLED, Boolean.TRUE)); return c.list(); } }; return (List) getHibernateTemplate().execute(hcb); }
/** * getSyllabiForSyllabusItem returns the collection of syllabi * @param syllabusItem */ public Set getSyllabiForSyllabusItem(final SyllabusItem syllabusItem) { if (syllabusItem == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback<Set> hcb = session -> { // get syllabi in an eager fetch mode Criteria crit = session.createCriteria(SyllabusItemImpl.class) .add(Expression.eq(SURROGATE_KEY, syllabusItem.getSurrogateKey())) .setFetchMode(SYLLABI, FetchMode.EAGER); SyllabusItem syllabusItem1 = (SyllabusItem) crit.uniqueResult(); if (syllabusItem1 != null){ return syllabusItem1.getSyllabi(); } return new TreeSet(); }; return getHibernateTemplate().execute(hcb); } }
public Set getSyllabusAttachmentsForSyllabusData(final SyllabusData syllabusData) { if (syllabusData == null) { throw new IllegalArgumentException("Null Argument"); } else { HibernateCallback<Set<SyllabusAttachment>> hcb = session -> { Criteria crit = session.createCriteria(SyllabusDataImpl.class) .add(Expression.eq(SYLLABUS_DATA_ID, syllabusData.getSyllabusId())) .setFetchMode(ATTACHMENTS, FetchMode.EAGER); SyllabusData syllabusData1 = (SyllabusData) crit.uniqueResult(); if (syllabusData1 != null){ return syllabusData1.getAttachments(); } return new TreeSet(); }; return getHibernateTemplate().execute(hcb); } }