public void testTransactionFlush_2() throws Exception { String name = "testTransactionFlush_2_" + System.currentTimeMillis(); TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.begin(); PersistenceBroker broker = tx.getBroker(); ODMGZoo obj = new ODMGZoo(); obj.setName(name); tx.lock(obj, Transaction.WRITE); tx.flush(); // System.err.println("First flush call, insert new object"); // PB to query Criteria crit = new Criteria(); crit.addEqualTo("name", obj.getName()); QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit); // we flushed all objects, thus we should found object in DB/cache Iterator it = broker.getIteratorByQuery(query); assertTrue(it.hasNext()); ODMGZoo other = (ODMGZoo) it.next(); assertNotNull(other); assertEquals(obj.getZooId(), other.getZooId()); assertEquals(obj.getName(), other.getName()); assertFalse(it.hasNext()); /** * Charles : Start ** */ // Let's flush, change the name and flush again tx.flush(); // System.err.println("Second flush call, nothing to do"); obj.setName("updated_" + name); tx.flush(); // System.err.println("Third flush call, update"); OQLQuery q = odmg.newOQLQuery(); q.create("select zoos from " + ODMGZoo.class.getName() + " where name like $1"); q.bind("updated_" + name); // Redo the query - we should find the object again it = ((Collection) q.execute()).iterator(); assertTrue(it.hasNext()); other = (ODMGZoo) it.next(); assertNotNull(other); assertEquals(obj.getZooId(), other.getZooId()); assertEquals(obj.getName(), other.getName()); assertFalse(it.hasNext()); /** * Charles : End ** */ // now we abort tx, so all flushed objects shouldn't be found // in further queries tx.abort(); tx = (TransactionExt) odmg.newTransaction(); tx.begin(); broker = tx.getBroker(); QueryByIdentity query2 = new QueryByIdentity(obj); Object result = broker.getObjectByQuery(query2); tx.commit(); assertNull("We should not find objects from aborted tx", result); }
/** * @see org.kuali.rice.krad.dao.MaintenanceDocumentDao#getLockingDocumentNumber(java.lang.String, * java.lang.String) */ public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) { String lockingDocNumber = ""; // build the query criteria Criteria criteria = new Criteria(); criteria.addEqualTo("lockingRepresentation", lockingRepresentation); // if a docHeaderId is specified, then it will be excluded from the // locking representation test. if (StringUtils.isNotBlank(documentNumber)) { criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber); } // attempt to retrieve a document based off this criteria MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate() .getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria)); // if a document was found, then there's already one out there pending, and // we consider it 'locked' and we return the docnumber. if (maintenanceLock != null) { lockingDocNumber = maintenanceLock.getDocumentNumber(); } return lockingDocNumber; }
@Override @SuppressWarnings("unchecked") public List<PositionBaseBo> getPositions( String positionNum, String description, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) { List<PositionBaseBo> results = new ArrayList<PositionBaseBo>(); Criteria root = new Criteria(); if (StringUtils.isNotBlank(positionNum)) { root.addLike("positionNumber", positionNum); } if (StringUtils.isNotBlank(description)) { root.addLike("UPPER(description)", description.toUpperCase()); // KPME-2695 } Criteria effectiveDateFilter = new Criteria(); if (fromEffdt != null) { effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate()); } if (toEffdt != null) { effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate()); } if (fromEffdt == null && toEffdt == null) { effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate()); } root.addAndCriteria(effectiveDateFilter); if (StringUtils.isNotBlank(active)) { Criteria activeFilter = new Criteria(); if (StringUtils.equals(active, "Y")) { activeFilter.addEqualTo("active", true); } else if (StringUtils.equals(active, "N")) { activeFilter.addEqualTo("active", false); } root.addAndCriteria(activeFilter); } if (StringUtils.equals(showHistory, "N")) { root.addEqualTo( "effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter( PositionBaseBo.class, effectiveDateFilter, PositionBaseBo.BUSINESS_KEYS, false)); root.addEqualTo( "timestamp", OjbSubQueryUtil.getTimestampSubQuery( PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false)); } Query query = QueryFactory.newQuery(PositionBaseBo.class, root); results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query)); return results; }
/** * @see * org.kuali.kfs.module.cab.dataaccess.PurchasingAccountsPayableReportDao#findPurchasingAccountsPayableDocuments(java.util.Map) */ @Override public Collection findPurchasingAccountsPayableDocuments(Map fieldValues) { Criteria criteria = OJBUtility.buildCriteriaFromMap(fieldValues, new PurchasingAccountsPayableDocument()); QueryByCriteria query = QueryFactory.newQuery(PurchasingAccountsPayableDocument.class, criteria); return getPersistenceBrokerTemplate().getCollectionByQuery(query); }
@Override public PositionBaseBo getPosition(String hrPositionId) { Criteria crit = new Criteria(); crit.addEqualTo("hrPositionId", hrPositionId); Query query = QueryFactory.newQuery(PositionBaseBo.class, crit); return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query); }
/** @see org.kuali.rice.krad.dao.DocumentHeaderDao#getByDocumentHeaderId(java.lang.String) */ public DocumentHeader getByDocumentHeaderId(String id) { Criteria criteria = new Criteria(); criteria.addEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, id); return (DocumentHeader) getPersistenceBrokerTemplate() .getObjectByQuery(QueryFactory.newQuery(getDocumentHeaderBaseClass(), criteria)); }
@Override public ClassificationBo getClassificationById(String pmClassificationId) { Criteria crit = new Criteria(); crit.addEqualTo("pmPositionClassId", pmClassificationId); Query query = QueryFactory.newQuery(ClassificationBo.class, crit); return (ClassificationBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query); }
/** @see org.kuali.kfs.pdp.dataaccess.PendingTransactionDao#clearExtractedTransactions() */ public void clearExtractedTransactions() { LOG.debug("clearExtractedTransactions() started"); Criteria criteria = new Criteria(); criteria.addEqualTo(PdpPropertyConstants.PROCESS_IND, true); QueryByCriteria qbc = QueryFactory.newQuery(GlPendingTransaction.class, criteria); getPersistenceBrokerTemplate().deleteByQuery(qbc); getPersistenceBrokerTemplate().clearCache(); }
/** * @see org.kuali.kfs.coa.dataaccess.ObjectCodeDao#getYearList(java.lang.String, java.lang.String) */ public List getYearList(String chartOfAccountsCode, String financialObjectCode) { List returnList = new ArrayList(); Criteria criteria = new Criteria(); criteria.addEqualTo("chartOfAccountsCode", chartOfAccountsCode); criteria.addEqualTo("financialObjectCode", financialObjectCode); Collection years = getPersistenceBrokerTemplate() .getCollectionByQuery(QueryFactory.newQuery(ObjectCode.class, criteria)); for (Iterator iter = years.iterator(); iter.hasNext(); ) { ObjectCode o = (ObjectCode) iter.next(); if (o != null) { returnList.add(o.getUniversityFiscalYear()); } } return returnList; }
public void testCollectionRetrieval() throws Exception { // Use PersistenceBroker to lookup persistent objects. // Loop through categories with id 1 to 9 // A ProductGroup holds a List of all Article Objects in the specific category // the repository.xml specifies that the List of Artikels has to be // materialized immediately. for (int i = 1; i < 9; i++) { ProductGroup example = new ProductGroup(); example.setId(new Integer(i)); ProductGroup group = (ProductGroup) broker.getObjectByQuery(QueryFactory.newQuery(example)); assertNotNull("Expect a ProductGroup with id " + i, group); assertEquals("should be equal", i, group.getId().intValue()); List articleList = group.getAllArticles(); for (int j = 0; j < articleList.size(); j++) { Object o = articleList.get(j); assertNotNull(o); } } }
/** * Retrieves accounting lines associate with a given document header ID using OJB. * * @param classname * @param id * @return */ public ArrayList findByDocumentHeaderId(Class clazz, String documentHeaderId) throws DataAccessException { Criteria criteria = new Criteria(); criteria.addEqualTo("FDOC_NBR", documentHeaderId); if (MetadataManager.getInstance() .getRepository() .getDescriptorFor(clazz) .getFieldDescriptorByName("financialDocumentLineTypeCode") != null) { if (SourceAccountingLine.class.isAssignableFrom(clazz)) { criteria.addEqualTo("FDOC_LN_TYP_CD", KFSConstants.SOURCE_ACCT_LINE_TYPE_CODE); } else if (TargetAccountingLine.class.isAssignableFrom(clazz)) { criteria.addEqualTo("FDOC_LN_TYP_CD", KFSConstants.TARGET_ACCT_LINE_TYPE_CODE); } } QueryByCriteria query = QueryFactory.newQuery(clazz, criteria); Collection lines = findCollection(query); return new ArrayList(lines); }
@Override public PositionBaseBo getPosition(String positionNumber, LocalDate effectiveDate) { Criteria root = new Criteria(); root.addEqualTo("positionNumber", positionNumber); root.addEqualTo( "effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery( PositionBaseBo.class, effectiveDate, PositionBaseBo.BUSINESS_KEYS, false)); root.addEqualTo( "timestamp", OjbSubQueryUtil.getTimestampSubQuery( PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false)); Criteria activeFilter = new Criteria(); // Inner Join For Activity activeFilter.addEqualTo("active", true); root.addAndCriteria(activeFilter); Query query = QueryFactory.newQuery(PositionBaseBo.class, root); return (PositionBaseBo) this.getPersistenceBrokerTemplate().getObjectByQuery(query); }
public void testTransactionFlush() throws Exception { String name = "testTransactionFlush_" + System.currentTimeMillis(); TransactionExt tx = (TransactionExt) odmg.newTransaction(); tx.begin(); PersistenceBroker broker = tx.getBroker(); ODMGZoo obj = new ODMGZoo(); tx.lock(obj, Transaction.WRITE); obj.setName(name); tx.flush(); Criteria crit = new Criteria(); crit.addEqualTo("name", obj.getName()); QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit); // we flushed all objects, thus we should find object in DB/cache Iterator it = broker.getIteratorByQuery(query); assertTrue(it.hasNext()); ODMGZoo other = (ODMGZoo) it.next(); assertNotNull(other); assertEquals(obj.getZooId(), other.getZooId()); assertEquals(obj.getName(), other.getName()); assertFalse(it.hasNext()); // now we abort tx, so all flushed objects shouldn't be found // in further queries tx.abort(); tx = (TransactionExt) odmg.newTransaction(); tx.begin(); broker = tx.getBroker(); QueryByIdentity query2 = new QueryByIdentity(obj); Object result = broker.getObjectByQuery(query2); tx.commit(); assertNull("We should not find objects from aborted tx", result); }