View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.useroptions.dao.impl;
17  
18  import org.apache.ojb.broker.PersistenceBroker;
19  import org.apache.ojb.broker.query.Criteria;
20  import org.apache.ojb.broker.query.QueryByCriteria;
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.core.api.util.RiceConstants;
23  import org.kuali.rice.core.framework.persistence.platform.DatabasePlatform;
24  import org.kuali.rice.kew.useroptions.UserOptions;
25  import org.kuali.rice.kew.useroptions.dao.UserOptionsDAO;
26  import org.springmodules.orm.ojb.PersistenceBrokerCallback;
27  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
28  
29  import java.util.ArrayList;
30  import java.util.Collection;
31  import java.util.List;
32  
33  
34  public class UserOptionsDAOOjbImpl extends PersistenceBrokerDaoSupport implements UserOptionsDAO {
35  
36  	public Long getNewOptionIdForActionList() {
37          return (Long)this.getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
38              public Object doInPersistenceBroker(PersistenceBroker broker) {
39              	return getPlatform().getNextValSQL("KREW_ACTN_LIST_OPTN_S", broker);
40              }
41          });
42      }
43  
44  	protected DatabasePlatform getPlatform() {
45      	return (DatabasePlatform)GlobalResourceLoader.getService(RiceConstants.DB_PLATFORM);
46      }
47  
48      public List<UserOptions> findByUserQualified(String principalId, String likeString) {
49          Criteria criteria = new Criteria();
50          criteria.addEqualTo("workflowId", principalId);
51          criteria.addLike("optionId", likeString);
52          return new ArrayList<UserOptions>(this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(UserOptions.class, criteria)));
53      }
54  
55      public void deleteByUserQualified(String principalId, String likeString) {
56          Criteria criteria = new Criteria();
57          criteria.addEqualTo("workflowId", principalId);
58          criteria.addLike("optionId", likeString);
59          this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(UserOptions.class, criteria));
60      }
61  
62      public Collection<UserOptions> findByWorkflowUser(String principalId) {
63          UserOptions userOptions = new UserOptions();
64          userOptions.setWorkflowId(principalId);
65          return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(userOptions));
66      }
67  
68      public void save(UserOptions userOptions) {
69      	this.getPersistenceBrokerTemplate().store(userOptions);
70      }
71      
72      public void save(Collection<UserOptions> userOptions) {
73      	if (userOptions != null) for (UserOptions option : userOptions) {
74      		this.getPersistenceBrokerTemplate().store(option);
75      	}
76      }
77      
78      public void deleteUserOptions(UserOptions userOptions) {
79      	this.getPersistenceBrokerTemplate().delete(userOptions);
80      }
81  
82      public UserOptions findByOptionId(String optionId, String principalId) {
83          UserOptions userOptions = new UserOptions();
84          userOptions.setOptionId(optionId);
85          userOptions.setWorkflowId(principalId);
86          return (UserOptions) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(userOptions));
87      }
88  
89      public Collection<UserOptions> findByOptionValue(String optionId, String optionValue) {
90          UserOptions userOptions = new UserOptions();
91          userOptions.setOptionId(optionId);
92          userOptions.setOptionVal(optionValue);
93          return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(userOptions));
94      }
95  }