1 22 package org.jboss.ejb.plugins.cmp.jdbc; 23 24 import java.sql.Types ; 25 26 27 34 public final class JDBCTypeSimple implements JDBCType 35 { 36 private final String [] columnNames; 37 private final Class [] javaTypes; 38 private final int[] jdbcTypes; 39 private final String [] sqlTypes; 40 private final boolean[] notNull; 41 private final boolean[] autoIncrement; 42 private final JDBCResultSetReader[] resultSetReader; 43 private final JDBCParameterSetter[] paramSetter; 44 45 private final Mapper mapper; 46 47 public JDBCTypeSimple( 48 String columnName, 49 Class javaType, 50 int jdbcType, 51 String sqlType, 52 boolean notNull, 53 boolean autoIncrement, 54 Mapper mapper, 55 JDBCParameterSetter paramSetter, 56 JDBCResultSetReader resultReader 57 ) 58 { 59 columnNames = new String []{columnName}; 60 javaTypes = new Class []{javaType}; 61 jdbcTypes = new int[]{jdbcType}; 62 sqlTypes = new String []{sqlType}; 63 this.notNull = new boolean[]{notNull}; 64 this.autoIncrement = new boolean[]{autoIncrement}; 65 this.mapper = mapper; 66 resultSetReader = new JDBCResultSetReader[]{resultReader}; 67 this.paramSetter = new JDBCParameterSetter[]{paramSetter}; 68 } 69 70 public final String [] getColumnNames() 71 { 72 return columnNames; 73 } 74 75 public final Class [] getJavaTypes() 76 { 77 return javaTypes; 78 } 79 80 public final int[] getJDBCTypes() 81 { 82 return jdbcTypes; 83 } 84 85 public final String [] getSQLTypes() 86 { 87 return sqlTypes; 88 } 89 90 public final boolean[] getNotNull() 91 { 92 return notNull; 93 } 94 95 public final boolean[] getAutoIncrement() 96 { 97 return autoIncrement; 98 } 99 100 public final Object getColumnValue(int index, Object value) 101 { 102 if(index != 0) 103 { 104 throw new IndexOutOfBoundsException ("JDBCSimpleType does not support an index>0."); 105 } 106 return mapper == null ? value : mapper.toColumnValue(value); 107 } 108 109 public final Object setColumnValue(int index, Object value, Object columnValue) 110 { 111 if(index != 0) 112 { 113 throw new IndexOutOfBoundsException ("JDBCSimpleType does not support an index>0."); 114 } 115 return mapper == null ? columnValue : mapper.toFieldValue(columnValue); 116 } 117 118 public boolean hasMapper() 119 { 120 return mapper != null; 121 } 122 123 public boolean isSearchable() 124 { 125 int jdbcType = jdbcTypes[0]; 126 return jdbcType != Types.BINARY && 127 jdbcType != Types.BLOB && 128 jdbcType != Types.CLOB && 129 jdbcType != Types.LONGVARBINARY && 130 jdbcType != Types.LONGVARCHAR && 131 jdbcType != Types.VARBINARY; 132 } 133 134 public final JDBCResultSetReader[] getResultSetReaders() 135 { 136 return resultSetReader; 137 } 138 139 public JDBCParameterSetter[] getParameterSetter() 140 { 141 return paramSetter; 142 } 143 } 144 | Popular Tags |