01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.database.platform;
18:
19: import java.sql.Connection;
20: import java.sql.PreparedStatement;
21: import java.sql.ResultSet;
22: import java.sql.SQLException;
23:
24: import org.apache.ojb.broker.PersistenceBroker;
25: import org.apache.ojb.broker.accesslayer.LookupException;
26:
27: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
28:
29: public class MySQLPlatform extends ANSISqlPlatform {
30:
31: public String getLockRouteHeaderQuerySQL(Long routeHeaderId,
32: boolean wait) {
33: return "SELECT DOC_HDR_ID FROM EN_DOC_HDR_T WHERE DOC_HDR_ID=? FOR UPDATE";
34: }
35:
36: public Long getNextValSQL(String sequenceName,
37: PersistenceBroker persistenceBroker) {
38: PreparedStatement statement = null;
39: ResultSet resultSet = null;
40: try {
41: Connection connection = persistenceBroker
42: .serviceConnectionManager().getConnection();
43: statement = connection.prepareStatement("INSERT INTO "
44: + sequenceName + " VALUES (NULL);");
45: statement.executeUpdate();
46: statement = connection
47: .prepareStatement("SELECT LAST_INSERT_ID()");
48: resultSet = statement.executeQuery();
49:
50: if (!resultSet.next()) {
51: throw new WorkflowRuntimeException(
52: "Error retrieving next option id for action list from sequence.");
53: }
54: return new Long(resultSet.getLong(1));
55: } catch (SQLException e) {
56: throw new WorkflowRuntimeException(
57: "Error retrieving next option id for action list from sequence.",
58: e);
59: } catch (LookupException e) {
60: throw new WorkflowRuntimeException(
61: "Error retrieving next option id for action list from sequence.",
62: e);
63: } finally {
64: if (statement != null) {
65: try {
66: statement.close();
67: } catch (SQLException e) {
68: }
69: }
70: if (resultSet != null) {
71: try {
72: resultSet.close();
73: } catch (SQLException e) {
74: }
75: }
76: }
77: }
78:
79: public boolean isSITCacheSupported() {
80: return false;
81: }
82:
83: public String toString() {
84: return "[MySQLPlatform]";
85: }
86:
87: }
|