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.database.platform;
018:
019: import java.sql.Connection;
020: import java.sql.PreparedStatement;
021: import java.sql.ResultSet;
022: import java.sql.SQLException;
023:
024: import org.apache.ojb.broker.PersistenceBroker;
025: import org.apache.ojb.broker.accesslayer.LookupException;
026: import org.kuali.rice.core.Core;
027:
028: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
029:
030: /**
031: * Platform implementation that generates Oracle-compliant SQL
032: * @author arh14 at cornell dot edu
033: */
034: public class OraclePlatform extends ANSISqlPlatform {
035:
036: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
037: .getLogger(OraclePlatform.class);
038: private static final long DEFAULT_TIMEOUT_SECONDS = 60 * 60; // default to 1 hour
039:
040: public Long getNextValSQL(String sequenceName,
041: PersistenceBroker persistenceBroker) {
042: PreparedStatement statement = null;
043: ResultSet resultSet = null;
044: try {
045: Connection connection = persistenceBroker
046: .serviceConnectionManager().getConnection();
047: statement = connection.prepareStatement("select "
048: + sequenceName + ".nextval from dual");
049: resultSet = statement.executeQuery();
050:
051: if (!resultSet.next()) {
052: throw new WorkflowRuntimeException(
053: "Error retrieving next option id for action list from sequence.");
054: }
055: return new Long(resultSet.getLong(1));
056: } catch (SQLException e) {
057: throw new WorkflowRuntimeException(
058: "Error retrieving next option id for action list from sequence.",
059: e);
060: } catch (LookupException e) {
061: throw new WorkflowRuntimeException(
062: "Error retrieving next option id for action list from sequence.",
063: e);
064: } finally {
065: if (statement != null) {
066: try {
067: statement.close();
068: } catch (SQLException e) {
069: }
070: }
071: if (resultSet != null) {
072: try {
073: resultSet.close();
074: } catch (SQLException e) {
075: }
076: }
077: }
078: }
079:
080: public String getLockRouteHeaderQuerySQL(Long routeHeaderId,
081: boolean wait) {
082: long timeoutSeconds = getTimeoutSeconds();
083: String waitClause = "";
084: if (!wait) {
085: waitClause = " NOWAIT";
086: } else if (wait && timeoutSeconds > 0) {
087: waitClause = " WAIT " + timeoutSeconds;
088: }
089: return "SELECT DOC_HDR_ID FROM EN_DOC_HDR_T WHERE DOC_HDR_ID=? FOR UPDATE"
090: + waitClause;
091: }
092:
093: public String toString() {
094: return "[OraclePlatform]";
095: }
096:
097: protected long getTimeoutSeconds() {
098: String timeoutValue = Core.getCurrentContextConfig()
099: .getDocumentLockTimeout();
100: if (timeoutValue != null) {
101: try {
102: return Long.parseLong(timeoutValue);
103: } catch (NumberFormatException e) {
104: LOG
105: .warn("Failed to parse document lock timeout as it was not a valid number: "
106: + timeoutValue);
107: }
108: }
109: return DEFAULT_TIMEOUT_SECONDS;
110: }
111: }
|