List of usage examples for org.hibernate Query getQueryString
String getQueryString();
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests parent query.//ww w . j a v a2 s. c om * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testParentQuery() throws Exception { ItemFilter filter = new ItemFilter(); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibItem i join i.parentDetails pd where " + "pd.primaryKey.collection=:parent", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests display name and parent query.//from w w w . jav a 2 s. co m * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testDisplayNameAndParentQuery() throws Exception { ItemFilter filter = new ItemFilter(); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); filter.setDisplayName(Restrictions.eq("test")); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibItem i join i.parentDetails pd where " + "pd.primaryKey.collection=:parent and i.displayName=:param1", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests content item query./*from w w w .j av a2s. c o m*/ * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testContentItemQuery() throws Exception { ContentItemFilter filter = new ContentItemFilter(); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); filter.setTriageStatusCode(Restrictions.eq(TriageStatus.CODE_DONE)); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibContentItem i join i.parentDetails pd where " + "pd.primaryKey.collection=:parent and i.triageStatus.code=:param1", query.getQueryString()); filter.setTriageStatusCode(Restrictions.isNull()); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibContentItem i join i.parentDetails pd where " + "pd.primaryKey.collection=:parent and i.triageStatus.code is null", query.getQueryString()); filter.setTriageStatusCode(Restrictions.eq(TriageStatus.CODE_DONE)); filter.addOrderBy(ContentItemFilter.ORDER_BY_TRIAGE_STATUS_RANK_ASC); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibContentItem i join i.parentDetails pd where " + "pd.primaryKey.collection=:parent and i.triageStatus.code=:param1 order by " + "i.triageStatus.rank", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests note item query.//from w w w .j ava 2s .co m * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testNoteItemQuery() throws Exception { NoteItemFilter filter = new NoteItemFilter(); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); filter.setDisplayName(Restrictions.eq("test")); filter.setIcalUid(Restrictions.eq("icaluid")); filter.setBody(Restrictions.eq("body")); filter.setTriageStatusCode(Restrictions.eq(TriageStatus.CODE_DONE)); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, " + "HibTextAttribute ta4 where pd.primaryKey.collection=:parent and " + "i.displayName=:param1 and i.triageStatus.code=:param2 and i.icalUid=:param3 and " + "ta4.item=i and ta4.qname=:ta4qname and ta4.value=:param5", query.getQueryString()); filter = new NoteItemFilter(); filter.setIsModification(true); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where i.modifies is not null", query.getQueryString()); filter.setIsModification(false); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where i.modifies is null", query.getQueryString()); filter.setIsModification(null); filter.setHasModifications(true); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where size(i.modifications) > 0", query.getQueryString()); filter.setHasModifications(false); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where size(i.modifications) = 0", query.getQueryString()); filter = new NoteItemFilter(); filter.setMasterNoteItem(new HibNoteItem()); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where (i=:masterItem or " + "i.modifies=:masterItem)", query.getQueryString()); filter = new NoteItemFilter(); Date date1 = new Date(1000); Date date2 = new Date(2000); filter.setReminderTime(Restrictions.between(date1, date2)); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibNoteItem i, HibTimestampAttribute tsa0 where " + "tsa0.item=i and tsa0.qname=:tsa0qname and tsa0.value between :param1 and :param2", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests event stamp query.//from w w w. j a va2 s . c o m * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testEventStampQuery() throws Exception { NoteItemFilter filter = new NoteItemFilter(); EventStampFilter eventFilter = new EventStampFilter(); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); filter.setDisplayName(Restrictions.eq("test")); filter.setIcalUid(Restrictions.eq("icaluid")); //filter.setBody("body"); filter.getStampFilters().add(eventFilter); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, " + "HibBaseEventStamp es where pd.primaryKey.collection=:parent and " + "i.displayName=:param1 and es.item=i and i.icalUid=:param2", query.getQueryString()); eventFilter.setIsRecurring(true); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, HibBaseEventStamp " + "es where pd.primaryKey.collection=:parent and i.displayName=:param1 and" + " es.item=i and (es.timeRangeIndex.isRecurring=true or i.modifies is not null) " + "and i.icalUid=:param2", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests event stamp time range query.//w w w. ja v a 2 s . co m * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testEventStampTimeRangeQuery() throws Exception { NoteItemFilter filter = new NoteItemFilter(); EventStampFilter eventFilter = new EventStampFilter(); Period period = new Period(new DateTime("20070101T100000Z"), new DateTime("20070201T100000Z")); eventFilter.setPeriod(period); eventFilter.setTimezone(registry.getTimeZone("America/Chicago")); CollectionItem parent = new HibCollectionItem(); filter.setParent(parent); filter.getStampFilters().add(eventFilter); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i join i.parentDetails pd, " + "HibBaseEventStamp es where pd.primaryKey.collection=:parent and es.item=i " + "and ( (es.timeRangeIndex.isFloating=true and " + "es.timeRangeIndex.startDate < '20070201T040000' and " + "es.timeRangeIndex.endDate > '20070101T040000') or " + "(es.timeRangeIndex.isFloating=false and " + "es.timeRangeIndex.startDate < '20070201T100000Z' and " + "es.timeRangeIndex.endDate > '20070101T100000Z') or " + "(es.timeRangeIndex.startDate=es.timeRangeIndex.endDate and " + "(es.timeRangeIndex.startDate='20070101T040000' or " + "es.timeRangeIndex.startDate='20070101T100000Z')))", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests basic stamp query./*from w w w. j a v a2s.co m*/ * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testBasicStampQuery() throws Exception { NoteItemFilter filter = new NoteItemFilter(); StampFilter missingFilter = new StampFilter(); missingFilter.setStampClass(EventStamp.class); filter.getStampFilters().add(missingFilter); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals("select i from HibNoteItem i where exists (select s.id from HibStamp s " + "where s.item=i and s.class=HibEventStamp)", query.getQueryString()); missingFilter.setMissing(true); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibNoteItem i where not exists " + "(select s.id from HibStamp s where s.item=i and s.class=HibEventStamp)", query.getQueryString()); }
From source file:org.unitedinternet.cosmo.dao.hibernate.query.StandardItemFilterProcessorTest.java
License:Apache License
/** * Tests basic attribute query./* w ww .j a v a 2 s .co m*/ * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testBasicAttributeQuery() throws Exception { NoteItemFilter filter = new NoteItemFilter(); AttributeFilter missingFilter = new AttributeFilter(); missingFilter.setQname(new HibQName("ns", "name")); filter.getAttributeFilters().add(missingFilter); Query query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibNoteItem i where exists " + "(select a.id from HibAttribute a where a.item=i and a.qname=:param0)", query.getQueryString()); missingFilter.setMissing(true); query = queryBuilder.buildQuery(session, filter); Assert.assertEquals( "select i from HibNoteItem i where not exists" + " (select a.id from HibAttribute a where a.item=i and a.qname=:param0)", query.getQueryString()); }
From source file:org.xchain.framework.hibernate.HqlEntityPermission.java
License:Apache License
private void populateParameters(Query query, String principal, Serializable id) throws IllegalArgumentException { String[] namedParameters = query.getNamedParameters(); for (String namedParameter : namedParameters) { if ("id".equals(namedParameter)) { query.setParameter(namedParameter, id); } else if ("principal".equals(namedParameter)) { query.setParameter(namedParameter, principal); } else {//from ww w. j a v a2 s .c om throw new IllegalArgumentException(String.format( "Unknown parameter '%s' in permission hql '%s'. The only defined parameters are the current entity id (:id) and the principal (:principal).", namedParameter, query.getQueryString())); } } }
From source file:org.yawlfoundation.yawl.engine.YPersistenceManager.java
License:Open Source License
/** * executes a Query object based on the sql string passed * * @param query - the sql query to execute * @return the List of objects returned//from w ww.j a va 2s. co m * @throws YPersistenceException if there's a problem reading the db */ public List execQuery(Query query) throws YPersistenceException { try { return (query != null) ? query.list() : null; } catch (HibernateException he) { throw new YPersistenceException("Error executing query: " + query.getQueryString(), he); } }