|
24 | 24 | import java.sql.SQLException; |
25 | 25 | import java.sql.Types; |
26 | 26 |
|
| 27 | +import org.fugerit.java.core.db.daogen.ByteArrayDataHandler; |
| 28 | +import org.fugerit.java.core.db.daogen.CharArrayDataHandler; |
27 | 29 | import org.fugerit.java.core.db.helpers.BlobData; |
28 | 30 | import org.fugerit.java.core.db.helpers.DAOID; |
29 | 31 |
|
@@ -97,10 +99,22 @@ public Field newField(int value) { |
97 | 99 | return (new IntField(value)); |
98 | 100 | } |
99 | 101 |
|
| 102 | + public Field newField(ByteArrayDataHandler value) { |
| 103 | + return new BlobDataField( BlobData.valueOf( (ByteArrayDataHandler)value ) ); |
| 104 | + } |
| 105 | + |
| 106 | + public Field newField(CharArrayDataHandler value) { |
| 107 | + return new ClobDataField( value ); |
| 108 | + } |
| 109 | + |
100 | 110 | public Field newField(Object value) { |
101 | 111 | Field field = null; |
102 | 112 | if ( value instanceof BlobData ) { |
103 | 113 | field = new BlobDataField( (BlobData)value ); |
| 114 | + } else if( value instanceof CharArrayDataHandler ) { |
| 115 | + field = newField( ((CharArrayDataHandler)value) ); |
| 116 | + } else if( value instanceof ByteArrayDataHandler ) { |
| 117 | + field = newField( ((ByteArrayDataHandler)value) ); |
104 | 118 | } else if (value instanceof DAOID) { |
105 | 119 | field = this.newField( (DAOID)value ); |
106 | 120 | } else { |
@@ -155,7 +169,17 @@ public ObjectField(Object value) { |
155 | 169 | * @see it.finanze.secin.shared.dao.Field#setField(java.sql.PreparedStatement, int) |
156 | 170 | */ |
157 | 171 | public void setField(PreparedStatement ps, int index) throws SQLException { |
158 | | - ps.setObject(index, this.value); |
| 172 | + if ( this.value == null ) { |
| 173 | + ps.setObject(index, this.value); |
| 174 | + } else if ( this.value instanceof java.sql.Date ) { |
| 175 | + ps.setDate(index, ((java.sql.Date)this.value)); |
| 176 | + } else if ( this.value instanceof java.sql.Timestamp ) { |
| 177 | + ps.setTimestamp(index, ((java.sql.Timestamp)this.value)); |
| 178 | + } else if ( this.value instanceof java.util.Date ) { |
| 179 | + ps.setTimestamp(index, new java.sql.Timestamp( ((java.util.Date)this.value).getTime() ) ); |
| 180 | + } else { |
| 181 | + ps.setObject(index, this.value); |
| 182 | + } |
159 | 183 | } |
160 | 184 |
|
161 | 185 | private Object value; |
@@ -183,6 +207,27 @@ public void setField(PreparedStatement ps, int index) throws SQLException { |
183 | 207 |
|
184 | 208 | } |
185 | 209 |
|
| 210 | +class ClobDataField extends Field { |
| 211 | + |
| 212 | + public String toString() { |
| 213 | + return this.getClass().getName()+"[value:"+this.value+"]"; |
| 214 | + } |
| 215 | + |
| 216 | + public ClobDataField( CharArrayDataHandler value ) { |
| 217 | + this.value = value; |
| 218 | + } |
| 219 | + |
| 220 | + /* (non-Javadoc) |
| 221 | + * @see it.finanze.secin.shared.dao.Field#setField(java.sql.PreparedStatement, int) |
| 222 | + */ |
| 223 | + public void setField(PreparedStatement ps, int index) throws SQLException { |
| 224 | + ps.setCharacterStream(index, this.value.toReader() ); |
| 225 | + } |
| 226 | + |
| 227 | + private CharArrayDataHandler value; |
| 228 | + |
| 229 | +} |
| 230 | + |
186 | 231 | class StringField extends Field { |
187 | 232 |
|
188 | 233 | public String toString() { |
|
0 commit comments