KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > dba > sqlserver > SQLServerAdapter


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

19
20 package org.apache.cayenne.dba.sqlserver;
21
22 import org.apache.cayenne.access.DataNode;
23 import org.apache.cayenne.access.trans.QualifierTranslator;
24 import org.apache.cayenne.access.trans.QueryAssembler;
25 import org.apache.cayenne.access.trans.TrimmingQualifierTranslator;
26 import org.apache.cayenne.dba.sybase.SybaseAdapter;
27 import org.apache.cayenne.map.DbAttribute;
28 import org.apache.cayenne.query.Query;
29 import org.apache.cayenne.query.SQLAction;
30
31 /**
32  * Cayenne DbAdapter implementation for <a
33  * HREF="http://www.microsoft.com/sql/"Microsoft SQL Server </a> engine.
34  * </p>
35  * <h3>Microsoft Driver Settings</h3>
36  * <p>
37  * Sample <a target="_top"
38  * HREF="../../../../../../../developerguide/unit-tests.html">connection settings </a> to
39  * use with MS SQL Server are shown below:
40  *
41  * <pre>
42  *
43  *
44  *
45  * sqlserver.cayenne.adapter = org.apache.cayenne.dba.sqlserver.SQLServerAdapter
46  * sqlserver.jdbc.username = test
47  * sqlserver.jdbc.password = secret
48  * sqlserver.jdbc.url = jdbc:sqlserver://192.168.0.65;databaseName=cayenne;SelectMethod=cursor
49  * sqlserver.jdbc.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
50  * </pre>
51  *
52  * <p>
53  * <i>Note on case-sensitive LIKE: if your application requires case-sensitive LIKE
54  * support, ask your DBA to configure the database to use a case-senstitive collation (one
55  * with "CS" in symbolic collation name instead of "CI", e.g.
56  * "SQL_Latin1_general_CP1_CS_AS"). </i>
57  * </p>
58  * <h3>jTDS Driver Settings</h3>
59  * <p>
60  * jTDS is an open source driver that can be downloaded from <a HREF=
61  * "http://jtds.sourceforge.net">http://jtds.sourceforge.net </a>. It supports both
62  * SQLServer and Sybase. Sample SQLServer settings are the following:
63  * </p>
64  *
65  * <pre>
66  *
67  *
68  *
69  * sqlserver.cayenne.adapter = org.apache.cayenne.dba.sqlserver.SQLServerAdapter
70  * sqlserver.jdbc.username = test
71  * sqlserver.jdbc.password = secret
72  * sqlserver.jdbc.url = jdbc:jtds:sqlserver://192.168.0.65/cayenne
73  * sqlserver.jdbc.driver = net.sourceforge.jtds.jdbc.Driver
74  *
75  *
76  *
77  * </pre>
78  *
79  * @author Andrus Adamchik
80  * @since 1.1
81  */

82 public class SQLServerAdapter extends SybaseAdapter {
83
84     public static final String JavaDoc TRIM_FUNCTION = "RTRIM";
85
86     public SQLServerAdapter() {
87         // TODO: i wonder if Sybase supports generated keys...
88
// in this case we need to move this to the super.
89
this.setSupportsGeneratedKeys(true);
90         this.setSupportsBatchUpdates(true);
91     }
92     
93
94     /**
95      * Uses SQLServerActionBuilder to create the right action.
96      *
97      * @since 1.2
98      */

99     public SQLAction getAction(Query query, DataNode node) {
100         return query.createSQLAction(new SQLServerActionBuilder(this, node.getEntityResolver()));
101     }
102
103     
104     /**
105      * Returns a trimming translator.
106      */

107     public QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler) {
108         return new TrimmingQualifierTranslator(
109                 queryAssembler,
110                 SQLServerAdapter.TRIM_FUNCTION);
111     }
112
113     
114     /**
115      * Overrides super implementation to correctly set up identity columns.
116      *
117      * @since 1.2
118      */

119     protected void createTableAppendColumn(StringBuffer JavaDoc sqlBuffer, DbAttribute column) {
120         super.createTableAppendColumn(sqlBuffer, column);
121         
122         if(column.isGenerated()) {
123             // current limitation - we don't allow to set identity parameters...
124
sqlBuffer.append(" IDENTITY (1, 1)");
125         }
126     }
127 }
128
Popular Tags