1 17 package org.apache.ws.jaxme.sqls.oracle; 18 19 import java.sql.DatabaseMetaData ; 20 import java.sql.Types ; 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 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 pColumnName, int pDataType, String 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: 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 if (pColumnSize < 24) { 77 type = Column.Type.FLOAT; } else { 79 type = Column.Type.DOUBLE; 80 } 81 } else { 82 if (pColumnSize < 8) { 84 type = Column.Type.FLOAT; } 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 ("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 |