01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.workflow.spi.jdbc;
06:
07: import com.opensymphony.workflow.StoreException;
08:
09: import java.sql.Connection;
10: import java.sql.PreparedStatement;
11: import java.sql.ResultSet;
12: import java.sql.SQLException;
13:
14: import java.util.Map;
15:
16: /**
17: * @author Christopher Farnham
18: * Created on Feb 27, 2004
19: */
20: public class MySQLWorkflowStore extends JDBCWorkflowStore {
21: //~ Instance fields ////////////////////////////////////////////////////////
22:
23: protected String entrySequenceIncrement = null;
24: protected String entrySequenceRetrieve = null;
25: protected String stepSequenceIncrement = null;
26: protected String stepSequenceRetrieve = null;
27:
28: //~ Methods ////////////////////////////////////////////////////////////////
29:
30: public void init(Map props) throws StoreException {
31: super .init(props);
32: stepSequenceIncrement = (String) props
33: .get("step.sequence.increment");
34: stepSequenceRetrieve = (String) props
35: .get("step.sequence.retrieve");
36: entrySequenceIncrement = (String) props
37: .get("entry.sequence.increment");
38: entrySequenceRetrieve = (String) props
39: .get("entry.sequence.retrieve");
40: }
41:
42: protected long getNextEntrySequence(Connection c)
43: throws SQLException {
44: PreparedStatement stmt = null;
45: ResultSet rset = null;
46:
47: try {
48: stmt = c.prepareStatement(entrySequenceIncrement);
49: stmt.executeUpdate();
50: rset = stmt.executeQuery(entrySequenceRetrieve);
51:
52: rset.next();
53:
54: long id = rset.getLong(1);
55:
56: return id;
57: } finally {
58: cleanup(null, stmt, rset);
59: }
60: }
61:
62: protected long getNextStepSequence(Connection c)
63: throws SQLException {
64: PreparedStatement stmt = null;
65: ResultSet rset = null;
66:
67: try {
68: stmt = c.prepareStatement(stepSequenceIncrement);
69: stmt.executeUpdate();
70: rset = stmt.executeQuery(stepSequenceRetrieve);
71:
72: rset.next();
73:
74: long id = rset.getLong(1);
75:
76: return id;
77: } finally {
78: cleanup(null, stmt, rset);
79: }
80: }
81: }
|