001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.useroptions.dao;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.List;
022:
023: import org.apache.ojb.broker.PersistenceBroker;
024: import org.apache.ojb.broker.query.Criteria;
025: import org.apache.ojb.broker.query.QueryByCriteria;
026: import org.kuali.rice.resourceloader.GlobalResourceLoader;
027: import org.springmodules.orm.ojb.PersistenceBrokerCallback;
028: import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
029: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
030:
031: import edu.iu.uis.eden.KEWServiceLocator;
032: import edu.iu.uis.eden.database.platform.Platform;
033: import edu.iu.uis.eden.user.WorkflowUser;
034: import edu.iu.uis.eden.useroptions.UserOptions;
035:
036: public class UserOptionsDAOOjbImpl extends PersistenceBrokerDaoSupport
037: implements UserOptionsDAO {
038:
039: public Long getNewOptionIdForActionList() {
040: return (Long) this .getPersistenceBrokerTemplate().execute(
041: new PersistenceBrokerCallback() {
042: public Object doInPersistenceBroker(
043: PersistenceBroker broker) {
044: return getPlatform().getNextValSQL(
045: "SEQ_ACTION_LIST_OPTN", broker);
046: }
047: });
048: }
049:
050: protected Platform getPlatform() {
051: return (Platform) GlobalResourceLoader
052: .getService(KEWServiceLocator.DB_PLATFORM);
053: }
054:
055: public List findByUserQualified(WorkflowUser user, String likeString) {
056: Criteria criteria = new Criteria();
057: criteria.addEqualTo("workflowId", user.getWorkflowUserId()
058: .getWorkflowId());
059: criteria.addLike("optionId", likeString);
060: return new ArrayList(
061: this .getPersistenceBrokerTemplate()
062: .getCollectionByQuery(
063: new QueryByCriteria(UserOptions.class,
064: criteria)));
065: }
066:
067: public void deleteByUserQualified(WorkflowUser user,
068: String likeString) {
069: Criteria criteria = new Criteria();
070: criteria.addEqualTo("workflowId", user.getWorkflowUserId()
071: .getWorkflowId());
072: criteria.addLike("optionId", likeString);
073: this .getPersistenceBrokerTemplate().deleteByQuery(
074: new QueryByCriteria(UserOptions.class, criteria));
075: }
076:
077: public Collection findByWorkflowUser(WorkflowUser workflowUser) {
078: UserOptions userOptions = new UserOptions();
079: userOptions.setWorkflowId(workflowUser.getWorkflowUserId()
080: .getWorkflowId());
081: return this .getPersistenceBrokerTemplate()
082: .getCollectionByQuery(new QueryByCriteria(userOptions));
083: }
084:
085: public void save(UserOptions userOptions) {
086: this .getPersistenceBrokerTemplate().store(userOptions);
087: }
088:
089: public void deleteUserOptions(UserOptions userOptions) {
090: this .getPersistenceBrokerTemplate().delete(userOptions);
091: }
092:
093: public UserOptions findByOptionId(String optionId,
094: WorkflowUser workflowUser) {
095: UserOptions userOptions = new UserOptions();
096: userOptions.setOptionId(optionId);
097: userOptions.setWorkflowId(workflowUser.getWorkflowUserId()
098: .getWorkflowId());
099: return (UserOptions) this .getPersistenceBrokerTemplate()
100: .getObjectByQuery(new QueryByCriteria(userOptions));
101: }
102:
103: public Collection findByOptionValue(String optionId,
104: String optionValue) {
105: UserOptions userOptions = new UserOptions();
106: userOptions.setOptionId(optionId);
107: userOptions.setOptionVal(optionValue);
108: return this .getPersistenceBrokerTemplate()
109: .getCollectionByQuery(new QueryByCriteria(userOptions));
110: }
111: }
|