001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.jdbc.sql;
020:
021: import java.io.InputStream;
022: import java.io.Reader;
023: import java.math.BigDecimal;
024: import java.math.BigInteger;
025: import java.sql.Array;
026: import java.sql.Blob;
027: import java.sql.Clob;
028: import java.sql.SQLException;
029: import java.sql.Time;
030: import java.sql.Timestamp;
031: import java.util.Calendar;
032: import java.util.Date;
033: import java.util.Locale;
034:
035: import org.apache.openjpa.jdbc.meta.RelationId;
036: import org.apache.openjpa.jdbc.schema.Column;
037: import org.apache.openjpa.jdbc.schema.ColumnIO;
038: import org.apache.openjpa.jdbc.schema.ForeignKey;
039: import org.apache.openjpa.jdbc.schema.Table;
040: import org.apache.openjpa.kernel.OpenJPAStateManager;
041:
042: /**
043: * Logical representation of a table row for insert/update/delete. The
044: * {@link org.apache.openjpa.jdbc.kernel.UpdateManager} is responsible for implementing
045: * rows to do something useful when the values are set.
046: *
047: * @author Abe White
048: */
049: public interface Row {
050:
051: /**
052: * Symbolic constant reserved for situations when a row operation
053: * is unknown.
054: */
055: public static final int ACTION_UNKNOWN = -1;
056:
057: /**
058: * Mark the row for update.
059: */
060: public static final int ACTION_UPDATE = 0;
061:
062: /**
063: * Mark the row for inserttion.
064: */
065: public static final int ACTION_INSERT = 1;
066:
067: /**
068: * Mark the row for deletion.
069: */
070: public static final int ACTION_DELETE = 2;
071:
072: /**
073: * Return the table for this row.
074: */
075: public Table getTable();
076:
077: /**
078: * Return the action for this row.
079: */
080: public int getAction();
081:
082: /**
083: * Return the failed object to include in optimistic lock exceptions.
084: */
085: public Object getFailedObject();
086:
087: /**
088: * Set the failed object to include in the optimistic lock exception
089: * that will be thrown if this update results in an update count of 0
090: * when executed. Leave null to avoid checking the update count.
091: */
092: public void setFailedObject(Object failed);
093:
094: /**
095: * Whether this row has information set on it.
096: */
097: public boolean isValid();
098:
099: /**
100: * Whether this row has information set on it.
101: */
102: public void setValid(boolean valid);
103:
104: /**
105: * Return the instance that controls this row. The
106: * {@link #setPrimaryKey} method does not necessarily have to be called
107: * to know the owning instance, nor does this row's table have to have
108: * an actual primary key.
109: */
110: public OpenJPAStateManager getPrimaryKey();
111:
112: /**
113: * Set the primary key to represent the given object.
114: */
115: public void setPrimaryKey(OpenJPAStateManager sm)
116: throws SQLException;
117:
118: /**
119: * Set the primary key to represent the given object.
120: *
121: * @param io information on which columns are settable; may be null
122: */
123: public void setPrimaryKey(ColumnIO io, OpenJPAStateManager sm)
124: throws SQLException;
125:
126: /**
127: * Set the primary key equality criteria for this row.
128: */
129: public void wherePrimaryKey(OpenJPAStateManager sm)
130: throws SQLException;
131:
132: /**
133: * Set the value of the given foreign key to the given object.
134: * If the related type uses table-per-class mappings, the foreign key may
135: * be targeted at an independent superclass table.
136: */
137: public void setForeignKey(ForeignKey fk, OpenJPAStateManager sm)
138: throws SQLException;
139:
140: /**
141: * Set the value of the given foreign key to the given object.
142: * If the related type uses table-per-class mappings, the foreign key may
143: * be targeted at an independent superclass table.
144: *
145: * @param io information on which columns are settable; may be null
146: */
147: public void setForeignKey(ForeignKey fk, ColumnIO io,
148: OpenJPAStateManager sm) throws SQLException;
149:
150: /**
151: * Set the foreign key equality criteria to link to the given object.
152: * If the related type uses table-per-class mappings, the foreign key may
153: * be targeted at an independent superclass table.
154: */
155: public void whereForeignKey(ForeignKey fk, OpenJPAStateManager sm)
156: throws SQLException;
157:
158: /**
159: * Set the value of the given column in this row.
160: */
161: public void setArray(Column col, Array val) throws SQLException;
162:
163: /**
164: * Set the value of the given column in this row.
165: */
166: public void setAsciiStream(Column col, InputStream val, int length)
167: throws SQLException;
168:
169: /**
170: * Set the value of the given column in this row.
171: */
172: public void setBigDecimal(Column col, BigDecimal val)
173: throws SQLException;
174:
175: /**
176: * Set the value of the given column in this row.
177: */
178: public void setBigInteger(Column col, BigInteger val)
179: throws SQLException;
180:
181: /**
182: * Set the value of the given column in this row.
183: */
184: public void setBinaryStream(Column col, InputStream val, int length)
185: throws SQLException;
186:
187: /**
188: * Set the value of the given column in this row.
189: */
190: public void setBlob(Column col, Blob val) throws SQLException;
191:
192: /**
193: * Set the value of the given column in this row.
194: */
195: public void setBoolean(Column col, boolean val) throws SQLException;
196:
197: /**
198: * Set the value of the given column in this row.
199: */
200: public void setByte(Column col, byte val) throws SQLException;
201:
202: /**
203: * Set the value of the given column in this row.
204: */
205: public void setBytes(Column col, byte[] val) throws SQLException;
206:
207: /**
208: * Set the value of the given column in this row.
209: */
210: public void setCalendar(Column col, Calendar val)
211: throws SQLException;
212:
213: /**
214: * Set the value of the given column in this row.
215: */
216: public void setChar(Column col, char val) throws SQLException;
217:
218: /**
219: * Set the value of the given column in this row.
220: */
221: public void setCharacterStream(Column col, Reader val, int length)
222: throws SQLException;
223:
224: /**
225: * Set the value of the given column in this row.
226: */
227: public void setClob(Column col, Clob val) throws SQLException;
228:
229: /**
230: * Set the value of the given column in this row.
231: */
232: public void setDate(Column col, Date val) throws SQLException;
233:
234: /**
235: * Set the value of the given column in this row.
236: */
237: public void setDate(Column col, java.sql.Date val, Calendar cal)
238: throws SQLException;
239:
240: /**
241: * Set the value of the given column in this row.
242: */
243: public void setDouble(Column col, double val) throws SQLException;
244:
245: /**
246: * Set the value of the given column in this row.
247: */
248: public void setFloat(Column col, float val) throws SQLException;
249:
250: /**
251: * Set the value of the given column in this row.
252: */
253: public void setInt(Column col, int val) throws SQLException;
254:
255: /**
256: * Set the value of the given column in this row.
257: */
258: public void setLong(Column col, long val) throws SQLException;
259:
260: /**
261: * Set the value of the given column in this row.
262: */
263: public void setLocale(Column col, Locale val) throws SQLException;
264:
265: /**
266: * Set the value of the given column in this row.
267: */
268: public void setNull(Column col) throws SQLException;
269:
270: /**
271: * Set the value of the given column in this row.
272: *
273: * @param overrideDefault whether to set this column to null even if this
274: * is an insert and the column has a default
275: */
276: public void setNull(Column col, boolean overrideDefault)
277: throws SQLException;
278:
279: /**
280: * Set the value of the given column in this row.
281: */
282: public void setNumber(Column col, Number val) throws SQLException;
283:
284: /**
285: * Set the value of the given column in this row.
286: *
287: * @param col the column being set
288: * @param val the value for the column
289: */
290: public void setObject(Column col, Object val) throws SQLException;
291:
292: /**
293: * Set a DB understood value for the given column.
294: * The value will not be parameterized and instead be inserted as raw SQL.
295: */
296: public void setRaw(Column col, String value) throws SQLException;
297:
298: /**
299: * Set the value of the given column to the identity of given instance,
300: * using the given callback to create the column value. This method is
301: * used for mappings that store some serialized form of id values, but must
302: * make sure that the related object's id is assigned (which might
303: * require an insert if the instance uses auto-increment) before it is
304: * serialized.
305: */
306: public void setRelationId(Column col, OpenJPAStateManager sm,
307: RelationId rel) throws SQLException;
308:
309: /**
310: * Set the value of the given column in this row.
311: */
312: public void setShort(Column col, short val) throws SQLException;
313:
314: /**
315: * Set the value of the given column in this row.
316: */
317: public void setString(Column col, String val) throws SQLException;
318:
319: /**
320: * Set the value of the given column in this row.
321: */
322: public void setTime(Column col, Time val, Calendar cal)
323: throws SQLException;
324:
325: /**
326: * Set the value of the given column in this row.
327: */
328: public void setTimestamp(Column col, Timestamp val, Calendar cal)
329: throws SQLException;
330:
331: /**
332: * Set an equality condition on the value of the given column in this row.
333: */
334: public void whereArray(Column col, Array val) throws SQLException;
335:
336: /**
337: * Set an equality condition on the value of the given column in this row.
338: */
339: public void whereAsciiStream(Column col, InputStream val, int length)
340: throws SQLException;
341:
342: /**
343: * Set an equality condition on the value of the given column in this row.
344: */
345: public void whereBigDecimal(Column col, BigDecimal val)
346: throws SQLException;
347:
348: /**
349: * Set an equality condition on the value of the given column in this row.
350: */
351: public void whereBigInteger(Column col, BigInteger val)
352: throws SQLException;
353:
354: /**
355: * Set an equality condition on the value of the given column in this row.
356: */
357: public void whereBinaryStream(Column col, InputStream val,
358: int length) throws SQLException;
359:
360: /**
361: * Set an equality condition on the value of the given column in this row.
362: */
363: public void whereBlob(Column col, Blob val) throws SQLException;
364:
365: /**
366: * Set an equality condition on the value of the given column in this row.
367: */
368: public void whereBoolean(Column col, boolean val)
369: throws SQLException;
370:
371: /**
372: * Set an equality condition on the value of the given column in this row.
373: */
374: public void whereByte(Column col, byte val) throws SQLException;
375:
376: /**
377: * Set an equality condition on the value of the given column in this row.
378: */
379: public void whereBytes(Column col, byte[] val) throws SQLException;
380:
381: /**
382: * Set an equality condition on the value of the given column in this row.
383: */
384: public void whereCalendar(Column col, Calendar val)
385: throws SQLException;
386:
387: /**
388: * Set an equality condition on the value of the given column in this row.
389: */
390: public void whereChar(Column col, char val) throws SQLException;
391:
392: /**
393: * Set an equality condition on the value of the given column in this row.
394: */
395: public void whereCharacterStream(Column col, Reader val, int length)
396: throws SQLException;
397:
398: /**
399: * Set an equality condition on the value of the given column in this row.
400: */
401: public void whereClob(Column col, Clob val) throws SQLException;
402:
403: /**
404: * Set an equality condition on the value of the given column in this row.
405: */
406: public void whereDate(Column col, Date val) throws SQLException;
407:
408: /**
409: * Set an equality condition on the value of the given column in this row.
410: */
411: public void whereDate(Column col, java.sql.Date val, Calendar cal)
412: throws SQLException;
413:
414: /**
415: * Set an equality condition on the value of the given column in this row.
416: */
417: public void whereDouble(Column col, double val) throws SQLException;
418:
419: /**
420: * Set an equality condition on the value of the given column in this row.
421: */
422: public void whereFloat(Column col, float val) throws SQLException;
423:
424: /**
425: * Set an equality condition on the value of the given column in this row.
426: */
427: public void whereInt(Column col, int val) throws SQLException;
428:
429: /**
430: * Set an equality condition on the value of the given column in this row.
431: */
432: public void whereLong(Column col, long val) throws SQLException;
433:
434: /**
435: * Set an equality condition on the value of the given column in this row.
436: */
437: public void whereLocale(Column col, Locale val) throws SQLException;
438:
439: /**
440: * Set an equality condition on the value of the given column in this row.
441: */
442: public void whereNull(Column col) throws SQLException;
443:
444: /**
445: * Set an equality condition on the value of the given column in this row.
446: */
447: public void whereNumber(Column col, Number val) throws SQLException;
448:
449: /**
450: * Set an equality condition on the value of the given column in this row.
451: *
452: * @param col the column being set
453: * @param val the value for the column
454: */
455: public void whereObject(Column col, Object val) throws SQLException;
456:
457: /**
458: * Set a DB understood where condition for the given column.
459: * The value will not be parameterized and instead be inserted as raw SQL.
460: */
461: public void whereRaw(Column col, String value) throws SQLException;
462:
463: /**
464: * Set an equality condition on the value of the given column in this row.
465: */
466: public void whereShort(Column col, short val) throws SQLException;
467:
468: /**
469: * Set an equality condition on the value of the given column in this row.
470: */
471: public void whereString(Column col, String val) throws SQLException;
472:
473: /**
474: * Set an equality condition on the value of the given column in this row.
475: */
476: public void whereTime(Column col, Time val, Calendar cal)
477: throws SQLException;
478:
479: /**
480: * Set an equality condition on the value of the given column in this row.
481: */
482: public void whereTimestamp(Column col, Timestamp val, Calendar cal)
483: throws SQLException;
484: }
|