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:
18: package org.apache.cocoon.components.modules.database;
19:
20: import java.sql.Connection;
21: import java.sql.PreparedStatement;
22: import java.sql.ResultSet;
23: import java.sql.SQLException;
24: import java.sql.Statement;
25: import java.util.Map;
26:
27: import org.apache.avalon.framework.configuration.Configuration;
28: import org.apache.avalon.framework.configuration.ConfigurationException;
29: import org.apache.avalon.framework.thread.ThreadSafe;
30:
31: /**
32: * Encapsulate MS SQLServer behaviour for autoincrement columns.
33: *
34: *
35: * @author <a href="mailto:andrzej@chaeron.com">Andrzej Jan Taramina</a>
36: * @version CVS $Id: SQLServerIdentityAutoIncrementModule.java 433543 2006-08-22 06:22:54Z crossley $
37: */
38: public class SQLServerIdentityAutoIncrementModule implements
39: AutoIncrementModule, ThreadSafe {
40:
41: public Object getPostValue(Configuration tableConf,
42: Configuration columnConf, Configuration modeConf,
43: Connection conn, Statement stmt, Map objectModel)
44: throws SQLException, ConfigurationException {
45:
46: Integer id = null;
47: /*
48: // if SQLServer did support callable statements ...
49:
50: CallableStatement callStmt = conn.prepareCall("? = {select @@IDENTITY}");
51: callStmt.registerOutParameter(1, Types.INTEGER);
52: ResultSet resultSet = callStmt.executeQuery();
53: */
54:
55: PreparedStatement pstmt = conn
56: .prepareStatement("select @@IDENTITY");
57: ResultSet resultSet = pstmt.executeQuery();
58: while (resultSet.next()) {
59: id = new Integer(resultSet.getInt(1));
60: }
61: resultSet.close();
62:
63: return id;
64: }
65:
66: public boolean includeInQuery() {
67: return false;
68: }
69:
70: public boolean includeAsValue() {
71: return false;
72: }
73:
74: public Object getPreValue(Configuration tableConf,
75: Configuration columnConf, Configuration modeConf,
76: Connection conn, Map objectModel) throws SQLException,
77: ConfigurationException {
78:
79: return null;
80: }
81:
82: public String getSubquery(Configuration tableConf,
83: Configuration columnConf, Configuration modeConf)
84: throws ConfigurationException {
85:
86: return null;
87: }
88: }
|