KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > platform > database > DerbyPlatform


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22
package oracle.toplink.essentials.platform.database;
23
24 import oracle.toplink.essentials.internal.databaseaccess.FieldTypeDefinition;
25 import oracle.toplink.essentials.internal.sessions.AbstractSession;
26 import oracle.toplink.essentials.internal.helper.DatabaseTable;
27 import oracle.toplink.essentials.exceptions.ValidationException;
28 import oracle.toplink.essentials.queryframework.ValueReadQuery;
29
30 import java.util.Vector JavaDoc;
31 import java.io.Writer JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.sql.SQLException JavaDoc;
34 import java.util.Hashtable JavaDoc;
35
36 /**
37  * <p><b>Purpose</b>: Provides Derby DBMS specific behaviour.
38  *
39  * @since TOPLink Essentials 1.0
40  */

41 public class DerbyPlatform extends DB2Platform {
42
43     /**
44      * INTERNAL:
45      * TODO: Need to find out how can byte arrays be inlined in Derby
46      */

47     protected void appendByteArray(byte[] bytes, Writer JavaDoc writer) throws IOException JavaDoc {
48             super.appendByteArray(bytes, writer);
49     }
50
51     /**
52      * INTERNAL:
53      * This method returns the query to select the timestamp from the server
54      * for Derby.
55      */

56     public ValueReadQuery getTimestampQuery() {
57         if (timestampQuery == null) {
58             timestampQuery = new ValueReadQuery();
59             timestampQuery.setSQLString("VALUES CURRENT_TIMESTAMP");
60         }
61         return timestampQuery;
62
63     }
64
65     //TODO: check with reviewer. This method should be made private in DB2platform
66
public Vector JavaDoc getNativeTableInfo(String JavaDoc table, String JavaDoc creator, AbstractSession session) {
67         throw new RuntimeException JavaDoc("Should never reach here");
68     }
69
70     /**
71      * Used for stored procedure defs.
72      */

73     public String JavaDoc getProcedureEndString() {
74         return getBatchEndString();
75     }
76
77     /**
78      * Used for stored procedure defs.
79      */

80     public String JavaDoc getProcedureBeginString() {
81         return getBatchBeginString();
82     }
83
84     /**
85      * This method is used to print the output parameter token when stored
86      * procedures are called
87      */

88     public String JavaDoc getInOutputProcedureToken() {
89         return "INOUT";
90     }
91
92     /**
93      * This is required in the construction of the stored procedures with
94      * output parameters
95      */

96     public boolean shouldPrintOutputTokenAtStart() {
97         //TODO: Check with the reviewer where this is used
98
return false;
99     }
100
101     /**
102      * INTERNAL:
103      * Answers whether platform is Derby
104      */

105     public boolean isDerby() {
106         return true;
107     }
108
109     public boolean isDB2() {
110         //This class inhertits from DB2. But it is not DB2
111
return false;
112     }
113
114     /**
115      * Allow for the platform to ignore exceptions.
116      */

117     public boolean shouldIgnoreException(SQLException JavaDoc exception) {
118         // Nothing is ignored.
119
return false;
120     }
121
122
123     /**
124      * INTERNAL:
125      */

126     protected String JavaDoc getCreateTempTableSqlSuffix() {
127         return " ON COMMIT DELETE ROWS NOT LOGGED";
128     }
129
130     public boolean supportsNativeSequenceNumbers() {
131         return true;
132     }
133
134     /**
135      * INTERNAL:
136      * Indicates whether NativeSequence should retrieve
137      * sequence value after the object has been inserted into the db
138      * This method is to be used *ONLY* by sequencing classes
139      */

140     public boolean shouldNativeSequenceAcquireValueAfterInsert() {
141         return true;
142     }
143
144     /**
145      * INTERNAL:
146      * Build the identity query for native sequencing.
147      */

148     public ValueReadQuery buildSelectQueryForNativeSequence() {
149         ValueReadQuery selectQuery = new ValueReadQuery();
150         selectQuery.setSQLString("values IDENTITY_VAL_LOCAL()");
151         return selectQuery;
152     }
153
154     /**
155      * INTERNAL:
156      */

157      protected String JavaDoc getCreateTempTableSqlBodyForTable(DatabaseTable table) {
158         // returning null includes fields of the table in body
159
// see javadoc of DatabasePlatform#getCreateTempTableSqlBodyForTable(DataBaseTable)
160
// for details
161
return null;
162      }
163
164     /**
165      * INTERNAL:
166      * Append the receiver's field 'identity' constraint clause to a writer.
167      */

168     public void printFieldIdentityClause(Writer JavaDoc writer) throws ValidationException {
169         try {
170             writer.write(" GENERATED ALWAYS AS IDENTITY");
171         } catch (IOException JavaDoc ioException) {
172             throw ValidationException.fileError(ioException);
173         }
174     }
175     
176     protected Hashtable JavaDoc buildFieldTypes() {
177         Hashtable JavaDoc fieldTypeMapping = new Hashtable JavaDoc();
178
179         fieldTypeMapping.put(Boolean JavaDoc.class, new FieldTypeDefinition("SMALLINT DEFAULT 0", false));
180
181         fieldTypeMapping.put(Integer JavaDoc.class, new FieldTypeDefinition("INTEGER", false));
182         fieldTypeMapping.put(Long JavaDoc.class, new FieldTypeDefinition("BIGINT", false));
183         fieldTypeMapping.put(Float JavaDoc.class, new FieldTypeDefinition("FLOAT"));
184         fieldTypeMapping.put(Double JavaDoc.class, new FieldTypeDefinition("FLOAT", false));
185         fieldTypeMapping.put(Short JavaDoc.class, new FieldTypeDefinition("SMALLINT", false));
186         fieldTypeMapping.put(Byte JavaDoc.class, new FieldTypeDefinition("SMALLINT", false));
187         fieldTypeMapping.put(java.math.BigInteger JavaDoc.class, new FieldTypeDefinition("BIGINT", false));
188         fieldTypeMapping.put(java.math.BigDecimal JavaDoc.class, new FieldTypeDefinition("DECIMAL"));
189         fieldTypeMapping.put(Number JavaDoc.class, new FieldTypeDefinition("DECIMAL"));
190
191         fieldTypeMapping.put(String JavaDoc.class, new FieldTypeDefinition("VARCHAR", 255));
192         fieldTypeMapping.put(Character JavaDoc.class, new FieldTypeDefinition("CHAR", 1));
193         fieldTypeMapping.put(Byte JavaDoc[].class, new FieldTypeDefinition("BLOB", 64000));
194         fieldTypeMapping.put(Character JavaDoc[].class, new FieldTypeDefinition("CLOB", 64000));
195         fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BLOB", 64000));
196         fieldTypeMapping.put(char[].class, new FieldTypeDefinition("CLOB", 64000));
197         fieldTypeMapping.put(java.sql.Blob JavaDoc.class, new FieldTypeDefinition("BLOB", 64000));
198         fieldTypeMapping.put(java.sql.Clob JavaDoc.class, new FieldTypeDefinition("CLOB", 64000));
199         
200         fieldTypeMapping.put(java.sql.Date JavaDoc.class, new FieldTypeDefinition("DATE", false));
201         fieldTypeMapping.put(java.sql.Time JavaDoc.class, new FieldTypeDefinition("TIME", false));
202         fieldTypeMapping.put(java.sql.Timestamp JavaDoc.class, new FieldTypeDefinition("TIMESTAMP", false));
203
204         return fieldTypeMapping;
205     }
206
207 }
208
Popular Tags