KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > sqls > oracle > OraSQLFactoryImpl


1 /*
2  * Copyright 2003, 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.ws.jaxme.sqls.oracle;
18
19 import java.sql.DatabaseMetaData JavaDoc;
20 import java.sql.Types JavaDoc;
21
22 import org.apache.ws.jaxme.sqls.BinaryColumn;
23 import org.apache.ws.jaxme.sqls.Column;
24 import org.apache.ws.jaxme.sqls.ObjectFactory;
25 import org.apache.ws.jaxme.sqls.SQLGenerator;
26 import org.apache.ws.jaxme.sqls.SelectStatement;
27 import org.apache.ws.jaxme.sqls.StringColumn;
28 import org.apache.ws.jaxme.sqls.Table;
29 import org.apache.ws.jaxme.sqls.impl.SQLFactoryImpl;
30
31
32 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

35 public class OraSQLFactoryImpl extends SQLFactoryImpl implements OraSQLFactory {
36     public SQLGenerator newSQLGenerator() {
37         return new OraSQLGeneratorImpl();
38     }
39     
40     protected Column readColumn(Table pTable, String JavaDoc pColumnName, int pDataType, String JavaDoc pTypeName,
41             long pColumnSize, int pDecimalDigits, int pNullable) {
42         Column.Type type;
43         if ("NUMBER".equalsIgnoreCase(pTypeName)) {
44             pDataType = Types.NUMERIC;
45         }
46         switch (pDataType) {
47             case Types.BIGINT: type = Column.Type.BIGINT; break;
48             case Types.BINARY: type = Column.Type.BINARY; break;
49             case Types.BIT: type = Column.Type.BIT; break;
50             case Types.BLOB: type = Column.Type.VARBINARY; break;
51             case 16: /* Types.BOOLEAN, introduced in Java 1.4 */
52                                       type = Column.Type.BIT; break;
53             case Types.CHAR: type = Column.Type.CHAR; break;
54             case Types.CLOB: type = Column.Type.VARCHAR; break;
55             case Types.DATE: type = Column.Type.DATE; break;
56             case Types.DOUBLE: type = Column.Type.DOUBLE; break;
57             case Types.FLOAT: type = Column.Type.FLOAT; break;
58             case Types.INTEGER: type = Column.Type.INTEGER; break;
59             case Types.LONGVARBINARY: type = Column.Type.VARBINARY; break;
60             case Types.LONGVARCHAR: type = Column.Type.VARCHAR; break;
61             case Types.NUMERIC:
62                 if (pDecimalDigits == 0) {
63                     if (pColumnSize == 0) {
64                         type = Column.Type.FLOAT;
65                     } else if (pColumnSize <= 2) {
66                         type = Column.Type.TINYINT;
67                     } else if (pColumnSize <= 4) {
68                         type = Column.Type.SMALLINT;
69                     } else if (pColumnSize <= 9) {
70                         type = Column.Type.INTEGER;
71                     } else {
72                         type = Column.Type.BIGINT;
73                     }
74                 } else if (pDecimalDigits == -127) {
75                     // Uses binary precision - See page 4-37 of the OCI book
76
if (pColumnSize < 24) {
77                         type = Column.Type.FLOAT; // 53 is double cutoff
78
} else {
79                         type = Column.Type.DOUBLE;
80                     }
81                 } else {
82                     // Uses decimal precision - See page 4-37 of the OCI book
83
if (pColumnSize < 8) {
84                         type = Column.Type.FLOAT; // 15 is double cutoff
85
} else {
86                         type = Column.Type.DOUBLE;
87                     }
88                 }
89             break;
90             case Types.OTHER:
91                 if ("CLOB".equalsIgnoreCase(pTypeName)) {
92                     type = Column.Type.CLOB;
93                 } else {
94                     type = Column.Type.BLOB;
95                 }
96             break;
97             case Types.SMALLINT: type = Column.Type.SMALLINT; break;
98             case Types.TIMESTAMP: type = Column.Type.TIMESTAMP; break;
99             case Types.TIME: type = Column.Type.TIME; break;
100             case Types.TINYINT: type = Column.Type.TINYINT; break;
101             case Types.VARBINARY: type = Column.Type.VARBINARY; break;
102             case Types.VARCHAR: type = Column.Type.VARCHAR; break;
103             default: throw new IllegalArgumentException JavaDoc("Column " + pColumnName +
104                     " in table " + pTable.getQName() +
105                     " has unknown JDBC data type " +
106                     pDataType);
107         }
108         Column column = pTable.newColumn(pColumnName, type);
109         if (column instanceof StringColumn) {
110             ((StringColumn) column).setLength(pColumnSize);
111         } else if (column instanceof BinaryColumn) {
112             ((BinaryColumn) column).setLength(pColumnSize);
113         }
114         if (pNullable == DatabaseMetaData.columnNullable) {
115             column.setNullable(true);
116         }
117         return column;
118     }
119     
120     protected ObjectFactory newObjectFactory() {
121         return new OraObjectFactoryImpl();
122     }
123     
124     public SelectStatement newSelectStatement() {
125         return new OraSelectStatementImpl(this);
126     }
127 }
128
Popular Tags