KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Encapsulate MS SQLServer behaviour for autoincrement columns.
32  *
33  *
34  * @author <a HREF="mailto:andrzej@chaeron.com">Andrzej Jan Taramina</a>
35  * @version CVS $Id: SQLServerIdentityAutoIncrementModule.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

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

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