KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > dba > sybase > SybaseAdapter


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.sybase;
21
22 import java.sql.PreparedStatement JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.sql.Types JavaDoc;
25
26 import org.apache.cayenne.access.types.ByteArrayType;
27 import org.apache.cayenne.access.types.ByteType;
28 import org.apache.cayenne.access.types.CharType;
29 import org.apache.cayenne.access.types.ExtendedTypeMap;
30 import org.apache.cayenne.access.types.ShortType;
31 import org.apache.cayenne.dba.JdbcAdapter;
32 import org.apache.cayenne.dba.PkGenerator;
33
34 /**
35  * DbAdapter implementation for <a HREF="http://www.sybase.com">Sybase RDBMS</a>.
36  *
37  * @author Andrus Adamchik
38  */

39 public class SybaseAdapter extends JdbcAdapter {
40
41     /**
42      * Returns word "go".
43      *
44      * @since 1.0.4
45      */

46     public String JavaDoc getBatchTerminator() {
47         return "go";
48     }
49     
50     /**
51      * Installs appropriate ExtendedTypes as converters for passing values
52      * between JDBC and Java layers.
53      */

54     protected void configureExtendedTypes(ExtendedTypeMap map) {
55         super.configureExtendedTypes(map);
56
57         // create specially configured CharType handler
58
map.registerType(new CharType(true, false));
59
60         // create specially configured ByteArrayType handler
61
map.registerType(new ByteArrayType(true, false));
62
63         // address Sybase driver inability to handle java.lang.Short and java.lang.Byte
64
map.registerType(new ShortType(true));
65         map.registerType(new ByteType(true));
66     }
67
68     /**
69      * Creates and returns a primary key generator.
70      * Overrides superclass implementation to return an
71      * instance of SybasePkGenerator.
72      */

73     protected PkGenerator createPkGenerator() {
74         return new SybasePkGenerator();
75     }
76
77     public void bindParameter(
78         PreparedStatement JavaDoc statement,
79         Object JavaDoc object,
80         int pos,
81         int sqlType,
82         int precision)
83         throws SQLException JavaDoc, Exception JavaDoc {
84
85         // Sybase driver doesn't like CLOBs and BLOBs as parameters
86
if (object == null) {
87             if (sqlType == Types.CLOB) {
88                 sqlType = Types.VARCHAR;
89             }
90             else if (sqlType == Types.BLOB) {
91                 sqlType = Types.VARBINARY;
92             }
93         }
94
95         super.bindParameter(statement, object, pos, sqlType, precision);
96     }
97 }
98
Popular Tags