1 21 22 package org.continuent.sequoia.controller.backend; 23 24 import java.sql.ResultSetMetaData ; 25 import java.sql.SQLException ; 26 27 import org.continuent.sequoia.common.protocol.Field; 28 import org.continuent.sequoia.controller.cache.metadata.MetadataCache; 29 30 36 public class SequoiaResultSetMetaDataFactory 37 implements 38 ResultSetMetaDataFactory 39 { 40 41 45 public Field[] copyResultSetMetaData(ResultSetMetaData metaData, 46 MetadataCache metadataCache) throws SQLException 47 { 48 if (metaData == null) 49 { 50 return new Field[0]; 52 } 55 56 int nbColumn = metaData.getColumnCount(); 57 Field[] fields = new Field[nbColumn]; 58 for (int i = 1; i <= nbColumn; i++) 59 { String columnName = metaData.getColumnName(i); 61 String fTableName = null; 62 try 63 { 64 fTableName = metaData.getTableName(i); 65 } 66 catch (Exception ignore) 67 { 68 } 69 String columnLabel = null; 70 try 71 { 72 columnLabel = metaData.getColumnLabel(i); 73 } 74 catch (Exception ignore) 75 { 76 } 77 if (metadataCache != null) 78 { fields[i - 1] = metadataCache.getField(fTableName + "." + columnName 80 + "." + columnLabel); 81 if (fields[i - 1] != null) 82 continue; } 84 int fColumnDisplaySize = 0; 86 try 87 { 88 fColumnDisplaySize = metaData.getColumnDisplaySize(i); 89 } 90 catch (Exception ignore) 91 { 92 } 93 int columnType = -1; 94 try 95 { 96 columnType = metaData.getColumnType(i); 97 } 98 catch (Exception ignore) 99 { 100 } 101 String columnTypeName = null; 102 try 103 { 104 columnTypeName = metaData.getColumnTypeName(i); 105 } 106 catch (Exception ignore) 107 { 108 } 109 String fColumnClassName = null; 110 try 111 { 112 fColumnClassName = metaData.getColumnClassName(i); 113 } 114 catch (Exception ignore) 115 { 116 } 117 boolean fIsAutoIncrement = false; 118 try 119 { 120 fIsAutoIncrement = metaData.isAutoIncrement(i); 121 } 122 catch (Exception ignore) 123 { 124 } 125 boolean fIsCaseSensitive = false; 126 try 127 { 128 fIsCaseSensitive = metaData.isCaseSensitive(i); 129 } 130 catch (Exception ignore) 131 { 132 } 133 boolean fIsCurrency = false; 134 try 135 { 136 fIsCurrency = metaData.isCurrency(i); 137 } 138 catch (Exception ignore) 139 { 140 } 141 int fIsNullable = ResultSetMetaData.columnNullableUnknown; 142 try 143 { 144 fIsNullable = metaData.isNullable(i); 145 } 146 catch (Exception ignore) 147 { 148 } 149 boolean fIsReadOnly = false; 150 try 151 { 152 fIsReadOnly = metaData.isReadOnly(i); 153 } 154 catch (Exception ignore) 155 { 156 } 157 boolean fIsWritable = false; 158 try 159 { 160 fIsWritable = metaData.isWritable(i); 161 } 162 catch (Exception ignore) 163 { 164 } 165 boolean fIsDefinitelyWritable = false; 166 try 167 { 168 fIsDefinitelyWritable = metaData.isDefinitelyWritable(i); 169 } 170 catch (Exception ignore) 171 { 172 } 173 boolean fIsSearchable = false; 174 try 175 { 176 fIsSearchable = metaData.isSearchable(i); 177 } 178 catch (Exception ignore) 179 { 180 } 181 boolean fIsSigned = false; 182 try 183 { 184 fIsSigned = metaData.isSigned(i); 185 } 186 catch (Exception ignore) 187 { 188 } 189 int fPrecision = 0; 190 try 191 { 192 fPrecision = metaData.getPrecision(i); 193 } 194 catch (Exception ignore) 195 { 196 } 197 int fScale = 0; 198 try 199 { 200 fScale = metaData.getScale(i); 201 } 202 catch (Exception ignore) 203 { 204 } 205 String encoding = null; 206 fields[i - 1] = new Field(fTableName, columnName, columnLabel, 210 fColumnDisplaySize, columnType, columnTypeName, fColumnClassName, 211 fIsAutoIncrement, fIsCaseSensitive, fIsCurrency, fIsNullable, 212 fIsReadOnly, fIsWritable, fIsDefinitelyWritable, fIsSearchable, 213 fIsSigned, fPrecision, fScale, encoding); 214 215 if (metadataCache != null) 216 metadataCache.addField(fTableName + "." + columnName + "." 218 + columnLabel, fields[i - 1]); 219 } return fields; 221 } 222 223 } 224 | Popular Tags |