Package org.apache.ojb.broker.query

Examples of org.apache.ojb.broker.query.Criteria


   
   
    try {      // for error handling
     
      Class clazz = null;
      Criteria criteria = new Criteria();
      String[] projectionAttrs;
      boolean distinct = false;
     
      match(LITERAL_select);
      {
View Full Code Here


   
   
    try {      // for error handling
     
      Class clazz = null;
      Criteria criteria = new Criteria();
     
      match(LITERAL_exists);
      projectionAttributes();
      match(LITERAL_in);
      clazz=fromClause();
View Full Code Here

      {
      _loop97:
      do {
        if ((LA(1)==LITERAL_or) && (_tokenSet_8.member(LA(2))) && (_tokenSet_9.member(LA(3)))) {
          match(LITERAL_or);
          Criteria orCriteria = new Criteria();
          andExpr(orCriteria);
          criteria.addOrCriteria(orCriteria);
        }
        else {
          break _loop97;
View Full Code Here

      {
      _loop100:
      do {
        if ((LA(1)==LITERAL_and) && (_tokenSet_8.member(LA(2))) && (_tokenSet_9.member(LA(3)))) {
          match(LITERAL_and);
          Criteria andCriteria = new Criteria();
          quantifierExpr(andCriteria);
          criteria.addAndCriteria(andCriteria);
        }
        else {
          break _loop100;
View Full Code Here

        try
        {
            predicateQuery.create(oql);
            Query pQ = ((OQLQueryImpl) predicateQuery).getQuery();
            Criteria pCrit = pQ.getCriteria();

            Criteria allElementsCriteria = this.getPkCriteriaForAllElements(broker);
            // join selection of elements with predicate criteria:
            pCrit.addAndCriteria(allElementsCriteria);
            Class clazz = this.getElementsExtentClass(broker);
            Query q = new QueryByCriteria(clazz, pCrit);
            if (log.isDebugEnabled()) log.debug(q.toString());
View Full Code Here

    private Criteria getPkCriteriaForAllElements(PersistenceBroker broker)
    {
        try
        {
            Criteria crit = null;
            for (int i = 0; i < elements.size(); i++)
            {
                DListEntry entry = (DListEntry) elements.get(i);
                Object obj = entry.getRealSubject();
                ClassDescriptor cld = broker.getClassDescriptor(obj.getClass());

                FieldDescriptor[] pkFields = cld.getPkFields();
                ValueContainer[] pkValues = broker.serviceBrokerHelper().getKeyValues(cld, obj);

                Criteria criteria = new Criteria();
                for (int j = 0; j < pkFields.length; j++)
                {
                    FieldDescriptor fld = pkFields[j];
                    criteria.addEqualTo(fld.getPersistentField().getName(), pkValues[j].getValue());
                }

                if (crit == null)
                    crit = criteria;
                else
View Full Code Here

        PersistenceBroker pb = null;
        try
        {
            pb = PersistenceBrokerFactory.defaultPersistenceBroker();
            pb.clearCache();
            Criteria crit = new Criteria();
            crit.addLike("name", name);
            Query q = QueryFactory.newQuery(Gatherer.class, crit);
            fetchedGatherer = (Gatherer) pb.getObjectByQuery(q);
        }
        finally
        {
            if(pb != null) pb.close();
        }

        // check queried result
        assertNotNull(fetchedGatherer);
        assertEquals(gat.getGatId(), fetchedGatherer.getGatId());
        assertNotNull(fetchedGatherer.getCollectiblesB());
        assertEquals(1, fetchedGatherer.getCollectiblesB().size());
        CollectibleB fetched_B = (CollectibleB) fetchedGatherer.getCollectiblesB().iterator().next();
        assertNotNull(fetched_B);

        // Now work with queried result
        tx.begin();
        tx.getBroker().clearCache();
        //*************************************
        tx.lock(fetchedGatherer, Transaction.WRITE);
        CollectibleB newB = new CollectibleB(name);
        newB.setGatherer(fetchedGatherer);
        fetchedGatherer.getCollectiblesB().add(newB);
        tx.lock(newB, Transaction.WRITE);
        //*************************************
        assertEquals(2, fetchedGatherer.getCollectiblesB().size());
        tx.commit();

        // now cross again ODMG with PB api
        fetchedGatherer = null;
        pb = null;
        try
        {
            pb = PersistenceBrokerFactory.defaultPersistenceBroker();
            pb.clearCache();
            Criteria crit = new Criteria();
            crit.addLike("name", name);
            Query q = QueryFactory.newQuery(Gatherer.class, crit);
            fetchedGatherer = (Gatherer) pb.getObjectByQuery(q);
        }
        finally
        {
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public List<JetspeedPrincipal> getAssociatedTo(Long principalToId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain)
    {
        Criteria criteria = new Criteria();
        criteria.addEqualTo("associationsFrom.associationName", associationName);
        criteria.addEqualTo("associationsFrom.to.id", principalToId);
        criteria.addEqualTo("type", from.getName());
        criteria.addEqualTo("associationsFrom.to.type", to.getName());
        criteria.addEqualTo("associationsFrom.to.domainId", toSecurityDomain);
        criteria.addEqualTo("domainId", fromSecurityDomain);
        Query query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria);
        return (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query));
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public List<String> getAssociatedNamesFrom(String principalFromName, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain)
    {
        Criteria criteria = new Criteria();
        criteria.addEqualTo("associationsTo.associationName", associationName);
        criteria.addEqualTo("associationsTo.from.name", principalFromName);
        criteria.addEqualTo("associationsTo.from.type", from.getName());
        criteria.addEqualTo("type", to.getName());
        criteria.addEqualTo("associationsTo.from.domainId", fromSecurityDomain);
        criteria.addEqualTo("domainId", toSecurityDomain);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(PersistentJetspeedPrincipal.class, criteria);
        query.setAttributes(new String[]{"name"});
        ArrayList<String> names = new ArrayList<String>();
        for (Iterator<Object[]> iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); iter.hasNext(); )
        {
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public List<String> getAssociatedNamesFrom(Long principalFromId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain)
    {
        Criteria criteria = new Criteria();
        criteria.addEqualTo("associationsTo.associationName", associationName);
        criteria.addEqualTo("associationsTo.from.id", principalFromId);
        criteria.addEqualTo("associationsTo.from.type", from.getName());
        criteria.addEqualTo("type", to.getName());
        criteria.addEqualTo("associationsTo.from.domainId", fromSecurityDomain);
        criteria.addEqualTo("domainId", toSecurityDomain);
        ReportQueryByCriteria query = QueryFactory.newReportQuery(PersistentJetspeedPrincipal.class, criteria);
        query.setAttributes(new String[]{"name"});
        ArrayList<String> names = new ArrayList<String>();
        for (Iterator<Object[]> iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); iter.hasNext(); )
        {
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.query.Criteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.