| 1 package com.daffodilwoods.daffodildb.server.datadictionarysystem.information; 2 3 11 12 import java.io.*; 13 14 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 15 import com.daffodilwoods.daffodildb.server.sql99.common.*; 16 import com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition.*; 17 import com.daffodilwoods.database.general.*; 18 import com.daffodilwoods.database.general.TypeConverter; 19 import com.daffodilwoods.database.resource.*; 20 import com.daffodilwoods.database.utility.*; 21 22 public class ColumnsInformation implements _ColumnsInformation { 23 private int count; 24 private String [] columnNames; 25 private String [] columnTypes; 26 private String [] relatedTable; 27 private String [] relations; 28 private int[] size; 29 private String [] primaryKeys; 30 private int[] precision; 31 private int[] scale; 32 private boolean[] nullable; 33 private Object [] defaultValues; 34 35 public ColumnsInformation() { 36 } 37 38 public ColumnsInformation(_DataDictionary dataDictionary, QualifiedIdentifier tableName) { 39 40 try { 41 _ColumnCharacteristics columnCharacteristics = dataDictionary.getColumnCharacteristics(tableName, true); 42 _DefaultValueGetter defaulValueGetter = dataDictionary.getDefaultValueGetter(tableName); 43 int startIndex = SystemFields.systemFields.length; 44 count = columnCharacteristics.getColumnCount() - startIndex; 45 init(); 46 String [] allcolumnNames = columnCharacteristics.getColumnNames(); 47 primaryKeys = columnCharacteristics.getPrimaryKeys(); 48 for (int j = 0, i = startIndex; j < count; i++, j++) { 49 int colType = columnCharacteristics.getColumnType(i); 50 columnNames[j] = allcolumnNames[i]; 51 relatedTable[j] = columnCharacteristics.getRelatedTable(i); 52 relations[j] = columnCharacteristics.getRelation(i); 53 precision[j] = columnCharacteristics.getPrecision(i); 54 scale[j] = columnCharacteristics.getScale(i); 55 size[j] = getByteSize(columnCharacteristics.getSize(i), colType); 56 columnTypes[j] = TypeConverter.getDataBaseTypeName(colType); 57 nullable[j] = columnCharacteristics.isNullable(i) == 1; 58 defaultoption doa = defaulValueGetter.getDefaultValueExpression(i); 59 defaultValues[j] = doa == null ? null : doa.toString(); 60 } 61 } catch (DException ex) { 62 throw new RuntimeException (ex.getMessage()); 63 } 64 } 65 66 private int getByteSize(int size, int type) { 67 if (type == Datatypes.LONGVARBINARY || type == Datatypes.LONGVARCHAR 68 || type == Datatypes.BLOB || type == Datatypes.CLOB 69 || type == Datatypes.CHARLARGEOBJECT 70 || type == Datatypes.CHARACTERLARGEOBJECT 71 || type == Datatypes.BINARYLARGEOBJECT) 72 return -1; 73 return size; 74 } 75 76 private void init() { 77 columnNames = new String [count]; 78 columnTypes = new String [count]; 79 relatedTable = new String [count]; 80 relations = new String [count]; 81 size = new int[count]; 82 precision = new int[count]; 83 scale = new int[count]; 84 nullable = new boolean[count]; 85 defaultValues = new Object [count]; 86 } 87 88 public String getColumnTypeName(int index) { 89 return columnTypes[index]; 90 } 91 92 public String getColumnName(int parm1) { 93 return columnNames[parm1]; 94 } 95 96 public String getRelatedTable(int parm1) { 97 return relatedTable[parm1]; 98 } 99 100 public int getColumnCount() { 101 return count; 102 } 103 104 public String [] getColumnNames() { 105 return columnNames; 106 } 107 108 public int getSize(int parm1) { 109 return size[parm1]; 110 } 111 112 public String [] getPrimaryKeys() { 113 return primaryKeys; 114 } 115 116 public String getRelation(int parm1) { 117 return relations[parm1]; 118 } 119 120 public int getPrecision(int index) { 121 return precision[index]; 122 } 123 124 public int getScale(int index) { 125 return scale[index]; 126 } 127 128 public boolean isNullable(int index) { 129 return nullable[index]; 130 } 131 132 public int getColumnIndex(String columnName) throws DException { 133 int index = P.indexOfIgnoreCase(columnNames, columnName); 134 if (index == -1) { 135 throw new DException("DSE256", new Object [] {columnName}); 136 } 137 return index; 138 } 139 140 public boolean isPrimaryKey(int columnIndex) { 141 String columnName = getColumnName(columnIndex); 142 return P.indexOfIgnoreCase(primaryKeys, columnName) != -1; 143 } 144 145 public Object getDefaultValue(int index) { 146 return defaultValues[index]; 147 } 148 149 public void readExternal(ObjectInput oi) throws IOException, ClassNotFoundException { 150 count = oi.readInt(); 151 columnNames = (String []) oi.readObject(); 152 columnTypes = (String []) oi.readObject(); 153 relatedTable = (String []) oi.readObject(); 154 relations = (String []) oi.readObject(); 155 size = (int[]) oi.readObject(); 156 primaryKeys = (String []) oi.readObject(); 157 precision = (int[]) oi.readObject(); 158 scale = (int[]) oi.readObject(); 159 nullable = (boolean[]) oi.readObject(); 160 defaultValues = (Object []) oi.readObject(); 161 } 162 163 public void writeExternal(ObjectOutput oo) throws IOException { 164 oo.writeInt(count); 165 oo.writeObject(columnNames); 166 oo.writeObject(columnTypes); 167 oo.writeObject(relatedTable); 168 oo.writeObject(relations); 169 oo.writeObject(size); 170 oo.writeObject(primaryKeys); 171 oo.writeObject(precision); 172 oo.writeObject(scale); 173 oo.writeObject(nullable); 174 oo.writeObject(defaultValues); 175 } 176 } 177 | Popular Tags |