KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > modules > database > HsqlIdentityAutoIncrementModule


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.modules.database;
18
19 import java.sql.Connection JavaDoc;
20 import java.sql.PreparedStatement JavaDoc;
21 import java.sql.ResultSet JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.sql.Statement JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.avalon.framework.configuration.Configuration;
27 import org.apache.avalon.framework.configuration.ConfigurationException;
28 import org.apache.avalon.framework.thread.ThreadSafe;
29
30 /**
31  * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
32  *
33  * Here: <a HREF="http://hsqldb.sourceforge.net">HSQLDB</a> 1.6 IDENTITY columns
34  *
35  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
36  * @version CVS $Id: HsqlIdentityAutoIncrementModule.java 30932 2004-07-29 17:35:38Z vgritsenko $
37  */

38 public class HsqlIdentityAutoIncrementModule implements AutoIncrementModule, ThreadSafe {
39
40     public Object JavaDoc getPostValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
41                                 Connection JavaDoc conn, Statement JavaDoc stmt, Map JavaDoc objectModel ) throws SQLException JavaDoc, ConfigurationException {
42
43         Integer JavaDoc id = null;
44         /*
45           // if hsqldb did support callable statements ...
46
47           CallableStatement callStmt = conn.prepareCall("? = {CALL IDENTITY()}");
48           callStmt.registerOutParameter(1, Types.INTEGER);
49           ResultSet resultSet = callStmt.executeQuery();
50         */

51
52         PreparedStatement JavaDoc pstmt = conn.prepareStatement("CALL IDENTITY()");
53         ResultSet JavaDoc resultSet = pstmt.executeQuery();
54         while ( resultSet.next() ) {
55             id = new Integer JavaDoc(resultSet.getInt(1));
56         }
57         resultSet.close();
58
59         return id;
60     }
61
62
63     public boolean includeInQuery() { return false; }
64
65
66     public boolean includeAsValue() { return false; }
67
68
69     public Object JavaDoc getPreValue( Configuration tableConf, Configuration columnConf, Configuration modeConf,
70                                Connection JavaDoc conn, Map JavaDoc objectModel ) throws SQLException JavaDoc, ConfigurationException {
71
72         return null;
73     }
74
75
76     public String JavaDoc getSubquery( Configuration tableConf, Configuration columnConf, Configuration modeConf )
77         throws ConfigurationException {
78
79         return null;
80     }
81 }
82
Popular Tags