01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.db;
18:
19: import java.util.HashSet;
20: import java.util.List;
21: import java.util.Set;
22:
23: import org.bpmscript.ProcessState;
24: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
25:
26: public class ProcessStateCreator extends HibernateDaoSupport {
27:
28: @SuppressWarnings("unchecked")
29: @Override
30: protected void initDao() throws Exception {
31: super .initDao();
32: Set<String> statesSet = new HashSet<String>();
33: ProcessState[] states = ProcessState.values();
34: for (int i = 0; i < states.length; i++) {
35: statesSet.add(states[i].name());
36: }
37: List<DbProcessInstanceState> existingStates = getHibernateTemplate()
38: .find(
39: "from org.bpmscript.db.DbProcessInstanceState state");
40: for (DbProcessInstanceState state : existingStates) {
41: statesSet.remove(state.getName());
42: }
43: for (String state : statesSet) {
44: getHibernateTemplate().save(
45: new DbProcessInstanceState(state));
46: }
47: }
48:
49: }
|