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.lang.Integer;
21: import java.sql.PreparedStatement;
22: import java.sql.Connection;
23: import java.sql.ResultSet;
24: import java.sql.Statement;
25: import java.sql.SQLException;
26: import java.util.Map;
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: * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
33: *
34: * Here: <a href="http://www.mysql.com">MYSQL</a> AUTO_INCREMENT columns
35: *
36: * @author <a href="mailto:phantom@stserv.hcf.jhu.edu">Tim Myers</a>
37: * @version CVS $Id: MysqlAutoIncrementModule.java 433543 2006-08-22 06:22:54Z crossley $
38: */
39: public class MysqlAutoIncrementModule implements AutoIncrementModule,
40: ThreadSafe {
41:
42: public Object getPostValue(Configuration tableConf,
43: Configuration columnConf, Configuration modeConf,
44: Connection conn, Statement stmt, Map objectModel)
45: throws SQLException, ConfigurationException {
46:
47: Integer id = null;
48: /*
49: // if mysql did support callable statements ... i'm not sure what what would go here, maybe:
50:
51: CallableStatement callStmt = conn.prepareCall("? = {CALL LAST_INSERT_ID()}");
52: callStmt.registerOutParameter(1, Types.INTEGER);
53: ResultSet resultSet = callStmt.executeQuery();
54: */
55:
56: PreparedStatement pstmt = conn
57: .prepareStatement("SELECT LAST_INSERT_ID()");
58: ResultSet resultSet = pstmt.executeQuery();
59: while (resultSet.next()) {
60: id = new Integer(resultSet.getInt(1));
61: }
62: resultSet.close();
63:
64: return id;
65: }
66:
67: public boolean includeInQuery() {
68: return false;
69: }
70:
71: public boolean includeAsValue() {
72: return false;
73: }
74:
75: public Object getPreValue(Configuration tableConf,
76: Configuration columnConf, Configuration modeConf,
77: Connection conn, Map objectModel) throws SQLException,
78: ConfigurationException {
79:
80: return null;
81: }
82:
83: public String getSubquery(Configuration tableConf,
84: Configuration columnConf, Configuration modeConf)
85: throws ConfigurationException {
86:
87: return null;
88: }
89: }
|