KickJava   Java API By Example, From Geeks To Geeks.

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


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.SQLException JavaDoc;
21 import java.sql.Statement JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.thread.ThreadSafe;
27
28 /**
29  * Abstraction layer to encapsulate different DBMS behaviour for autoincrement columns.
30  *
31  * Here: <a HREF="http://www.mckoi.org">McKoi</a> sequences. The default
32  * sequence name is constructed from the table name, a "_", the column name, and
33  * the suffix "_seq". To use a different sequence name, set an attribute
34  * "sequence" for the modeConf e.g. &lt;mode name="auto" type="auto"
35  * sequence="my_sequence"/&gt;.
36  *
37  * @author <a HREF="mailto:haul@apache.org">Christian Haul</a>
38  * @version CVS $Id: McKoiSequenceModule.java 30932 2004-07-29 17:35:38Z vgritsenko $
39  */

40 public class McKoiSequenceModule implements AutoIncrementModule, ThreadSafe {
41
42     public Object JavaDoc getPostValue(
43         Configuration tableConf,
44         Configuration columnConf,
45         Configuration modeConf,
46         Connection JavaDoc conn,
47         Statement JavaDoc stmt,
48         Map JavaDoc objectModel)
49         throws SQLException JavaDoc, ConfigurationException {
50         return null;
51     }
52
53     public boolean includeInQuery() {
54         return true;
55     }
56
57     public boolean includeAsValue() {
58         return false;
59     }
60
61     public Object JavaDoc getPreValue(
62         Configuration tableConf,
63         Configuration columnConf,
64         Configuration modeConf,
65         Connection JavaDoc conn,
66         Map JavaDoc objectModel)
67         throws SQLException JavaDoc, ConfigurationException {
68
69         return null;
70     }
71
72     public String JavaDoc getSubquery(
73         Configuration tableConf,
74         Configuration columnConf,
75         Configuration modeConf)
76         throws ConfigurationException {
77
78         String JavaDoc sequence = modeConf.getAttribute("sequence", null);
79         StringBuffer JavaDoc queryBuffer = new StringBuffer JavaDoc();
80         queryBuffer.append(" NEXTVAL('");
81         if (sequence != null) {
82             queryBuffer.append(sequence);
83         } else {
84             queryBuffer.append(tableConf.getAttribute("name", ""));
85             queryBuffer.append('_');
86             queryBuffer.append(columnConf.getAttribute("name"));
87             queryBuffer.append("_seq");
88         }
89         queryBuffer.append("')");
90
91         return queryBuffer.toString();
92     }
93 }
94
Popular Tags