1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.openjpa.jdbc.sql;
20
21 import java.io.InputStream;
22 import java.io.Reader;
23 import java.io.StringReader;
24 import java.math.BigDecimal;
25 import java.math.BigInteger;
26 import java.sql.Array;
27 import java.sql.Blob;
28 import java.sql.Clob;
29 import java.sql.Ref;
30 import java.sql.SQLException;
31 import java.sql.Time;
32 import java.sql.Timestamp;
33 import java.util.Calendar;
34 import java.util.Date;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.Locale;
38 import java.util.Map;
39
40 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
41 import org.apache.openjpa.jdbc.kernel.JDBCStore;
42 import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
43 import org.apache.openjpa.jdbc.meta.ClassMapping;
44 import org.apache.openjpa.jdbc.meta.FieldMapping;
45 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
46 import org.apache.openjpa.jdbc.schema.Column;
47 import org.apache.openjpa.jdbc.schema.ForeignKey;
48 import org.apache.openjpa.jdbc.schema.Table;
49 import org.apache.openjpa.lib.util.Closeable;
50 import org.apache.openjpa.meta.JavaTypes;
51 import org.apache.openjpa.util.UnsupportedException;
52
53 import serp.util.Strings;
54
55 /**
56 * A {@link Result} implementation designed to be subclassed easily by
57 * implementations. All <code>get<type></code> calls are delegated to
58 * the {@link #getObjectInternal(Object,int,Object,Joins)} method, which
59 * should be implemented by subclasses along with {@link #nextInternal},
60 * {@link #containsInternal}, and {@link Result#size}.
61 * Most of the methods of this class will accept return values from
62 * {@link #getObjectInternal(Object,int,Object,Joins)} that are not exactly
63 * the right type. For example, any numeric type can be returned as any
64 * {@link Number} type, and dates, locales, characters, and booleans can be
65 * returned as strings.
66 *
67 * @author Abe White
68 * @see ResultSetResult
69 */
70 public abstract class AbstractResult
71 implements Result {
72
73 private static final Joins JOINS = new NoOpJoins();
74
75 private Map _eager = null;
76 private ClassMapping _base = null;
77 private int _index = 0;
78 private boolean _gotEager = false;
79 private boolean _wasNull = false;
80 private boolean _locking = false;
81 private boolean _ignoreNext = false;
82 private boolean _last = false;
83
84 public Object getEager(FieldMapping key) {
85 Map map = getEagerMap(true);
86 return (map == null) ? null : map.get(key);
87 }
88
89 public void putEager(FieldMapping key, Object res) {
90 Map map = getEagerMap(false);
91 if (map == null) {
92 map = new HashMap();
93 setEagerMap(map);
94 }
95 map.put(key, res);
96 }
97
98 /**
99 * Raw eager information. May be null.
100 *
101 * @param client whether the client is accessing eager information
102 */
103 protected Map getEagerMap(boolean client) {
104 if (client)
105 _gotEager = true;
106 return _eager;
107 }
108
109 /**
110 * Raw eager information.
111 */
112 protected void setEagerMap(Map eager) {
113 _eager = eager;
114 }
115
116 /**
117 * Closes all eager results.
118 */
119 public void close() {
120 closeEagerMap(_eager);
121 }
122
123 /**
124 * Close all results in eager map.
125 */
126 protected void closeEagerMap(Map eager) {
127 if (eager != null) {
128 Object res;
129 for (Iterator itr = eager.values().iterator(); itr.hasNext();) {
130 res = itr.next();
131 if (res != this && res instanceof Closeable)
132 try {
133 ((Closeable) res).close();
134 } catch (Exception e) {
135 }
136 }
137 }
138 }
139
140 /**
141 * Returns false by default.
142 */
143 public boolean supportsRandomAccess()
144 throws SQLException {
145 return false;
146 }
147
148 public boolean absolute(int row)
149 throws SQLException {
150 _gotEager = false;
151 return absoluteInternal(row);
152 }
153
154 /**
155 * Throws an exception by default.
156 */
157 protected boolean absoluteInternal(int row)
158 throws SQLException {
159 throw new UnsupportedException();
160 }
161
162 public boolean next()
163 throws SQLException {
164 _gotEager = false;
165 if (_ignoreNext) {
166 _ignoreNext = false;
167 return _last;
168 }
169 _last = nextInternal();
170 return _last;
171 }
172
173 /**
174 * Advance this row.
175 */
176 protected abstract boolean nextInternal()
177 throws SQLException;
178
179 public void pushBack()
180 throws SQLException {
181 _ignoreNext = true;
182 }
183
184 /**
185 * Returns a no-op joins object by default.
186 */
187 public Joins newJoins() {
188 return JOINS;
189 }
190
191 public boolean contains(Object obj)
192 throws SQLException {
193 return containsInternal(obj, null);
194 }
195
196 public boolean containsAll(Object[] objs)
197 throws SQLException {
198 return containsAllInternal(objs, null);
199 }
200
201 public boolean contains(Column col, Joins joins)
202 throws SQLException {
203 return containsInternal(col, joins);
204 }
205
206 public boolean containsAll(Column[] cols, Joins joins)
207 throws SQLException {
208 return containsAllInternal(cols, joins);
209 }
210
211 /**
212 * Return whether this result contains data for the given id or column.
213 * The id or column has not beed passed through {@link #translate}.
214 */
215 protected abstract boolean containsInternal(Object obj, Joins joins)
216 throws SQLException;
217
218 /**
219 * Return whether this result contains data for all the given ids or
220 * columns. The ids or columns have not been passed through
221 * {@link #translate}. Delegates to {@link #containsInternal} by default.
222 */
223 protected boolean containsAllInternal(Object[] objs, Joins joins)
224 throws SQLException {
225 for (int i = 0; i < objs.length; i++)
226 if (!containsInternal(objs[i], joins))
227 return false;
228 return true;
229 }
230
231 public ClassMapping getBaseMapping() {
232 // if we've returned an eager result this call might be for that eager
233 // result instead of our primary mapping, so return null
234 return (_gotEager) ? null : _base;
235 }
236
237 public void setBaseMapping(ClassMapping base) {
238 _base = base;
239 }
240
241 public int indexOf() {
242 return _index;
243 }
244
245 public void setIndexOf(int idx) {
246 _index = idx;
247 }
248
249 public Object load(ClassMapping mapping, JDBCStore store,
250 JDBCFetchConfiguration fetch)
251 throws SQLException {
252 return load(mapping, store, fetch, null);
253 }
254
255 public Object load(ClassMapping mapping, JDBCStore store,
256 JDBCFetchConfiguration fetch, Joins joins)
257 throws SQLException {
258 return ((JDBCStoreManager) store).load(mapping, fetch, null, this);
259 }
260
261 public Array getArray(Object obj)
262 throws SQLException {
263 return getArrayInternal(translate(obj, null), null);
264 }
265
266 public Array getArray(Column col, Joins joins)
267 throws SQLException {
268 return getArrayInternal(translate(col, joins), joins);
269 }
270
271 protected Array getArrayInternal(Object obj, Joins joins)
272 throws SQLException {
273 return (Array) checkNull(getObjectInternal(obj,
274 JavaSQLTypes.SQL_ARRAY, null, joins));
275 }
276
277 public InputStream getAsciiStream(Object obj)
278 throws SQLException {
279 return getAsciiStreamInternal(translate(obj, null), null);
280 }
281
282 public InputStream getAsciiStream(Column col, Joins joins)
283 throws SQLException {
284 return getAsciiStreamInternal(translate(col, joins), joins);
285 }
286
287 protected InputStream getAsciiStreamInternal(Object obj, Joins joins)
288 throws SQLException {
289 return (InputStream) checkNull(getObjectInternal(obj,
290 JavaSQLTypes.ASCII_STREAM, null, joins));
291 }
292
293 public BigDecimal getBigDecimal(Object obj)
294 throws SQLException {
295 return getBigDecimalInternal(translate(obj, null), null);
296 }
297
298 public BigDecimal getBigDecimal(Column col, Joins joins)
299 throws SQLException {
300 return getBigDecimalInternal(translate(col, joins), joins);
301 }
302
303 protected BigDecimal getBigDecimalInternal(Object obj, Joins joins)
304 throws SQLException {
305 Object val = checkNull(getObjectInternal(obj,
306 JavaTypes.BIGDECIMAL, null, joins));
307 if (val == null)
308 return null;
309 if (val instanceof BigDecimal)
310 return (BigDecimal) val;
311 return new BigDecimal(val.toString());
312 }
313
314 public BigInteger getBigInteger(Object obj)
315 throws SQLException {
316 return getBigIntegerInternal(translate(obj, null), null);
317 }
318
319 public BigInteger getBigInteger(Column col, Joins joins)
320 throws SQLException {
321 return getBigIntegerInternal(translate(col, joins), joins);
322 }
323
324 protected BigInteger getBigIntegerInternal(Object obj, Joins joins)
325 throws SQLException {
326 Object val = checkNull(getObjectInternal(obj,
327 JavaTypes.BIGINTEGER, null, joins));
328 if (val == null)
329 return null;
330 if (val instanceof BigInteger)
331 return (BigInteger) val;
332 return new BigInteger(val.toString());
333 }
334
335 public InputStream getBinaryStream(Object obj)
336 throws SQLException {
337 return getBinaryStreamInternal(translate(obj, null), null);
338 }
339
340 public InputStream getBinaryStream(Column col, Joins joins)
341 throws SQLException {
342 return getBinaryStreamInternal(translate(col, joins), joins);
343 }
344
345 public InputStream getLOBStream(JDBCStore store, Object obj)
346 throws SQLException {
347 return getLOBStreamInternal(store, translate(obj, null), null);
348 }
349
350 protected InputStream getBinaryStreamInternal(Object obj, Joins joins)
351 throws SQLException {
352 return (InputStream) checkNull(getObjectInternal(obj,
353 JavaSQLTypes.BINARY_STREAM, null, joins));
354 }
355
356 protected InputStream getLOBStreamInternal(JDBCStore store, Object obj,
357 Joins joins) throws SQLException {
358 return (InputStream) checkNull(getStreamInternal(store, obj,
359 JavaSQLTypes.BINARY_STREAM, null, joins));
360 }
361
362 public Blob getBlob(Object obj)
363 throws SQLException {
364 return getBlobInternal(translate(obj, null), null);
365 }
366
367 public Blob getBlob(Column col, Joins joins)
368 throws SQLException {
369 return getBlobInternal(translate(col, joins), joins);
370 }
371
372 protected Blob getBlobInternal(Object obj, Joins joins)
373 throws SQLException {
374 return (Blob) checkNull(getObjectInternal(obj, JavaSQLTypes.BLOB,
375 null, joins));
376 }
377
378 public boolean getBoolean(Object obj)
379 throws SQLException {
380 return getBooleanInternal(translate(obj, null), null);
381 }
382
383 public boolean getBoolean(Column col, Joins joins)
384 throws SQLException {
385 return getBooleanInternal(translate(col, joins), joins);
386 }
387
388 protected boolean getBooleanInternal(Object obj, Joins joins)
389 throws SQLException {
390 Object val = checkNull(getObjectInternal(obj, JavaTypes.BOOLEAN,
391 null, joins));
392 if (val == null)
393 return false;
394 return Boolean.valueOf(val.toString()).booleanValue();
395 }
396
397 public byte getByte(Object obj)
398 throws SQLException {
399 return getByteInternal(translate(obj, null), null);
400 }
401
402 public byte getByte(Column col, Joins joins)
403 throws SQLException {
404 return getByteInternal(translate(col, joins), joins);
405 }
406
407 protected byte getByteInternal(Object obj, Joins joins)
408 throws SQLException {
409 Number val = (Number) checkNull(getObjectInternal(obj,
410 JavaTypes.BYTE, null, joins));
411 return (val == null) ? 0 : val.byteValue();
412 }
413
414 public byte[] getBytes(Object obj)
415 throws SQLException {
416 return getBytesInternal(translate(obj, null), null);
417 }
418
419 public byte[] getBytes(Column col, Joins joins)
420 throws SQLException {
421 return getBytesInternal(translate(col, joins), joins);
422 }
423
424 protected byte[] getBytesInternal(Object obj, Joins joins)
425 throws SQLException {
426 return (byte[]) checkNull(getObjectInternal(obj,
427 JavaSQLTypes.BYTES, null, joins));
428 }
429
430 public Calendar getCalendar(Object obj)
431 throws SQLException {
432 return getCalendarInternal(translate(obj, null), null);
433 }
434
435 public Calendar getCalendar(Column col, Joins joins)
436 throws SQLException {
437 return getCalendarInternal(translate(col, joins), joins);
438 }
439
440 protected Calendar getCalendarInternal(Object obj, Joins joins)
441 throws SQLException {
442 Object val = checkNull(getObjectInternal(obj, JavaTypes.CALENDAR,
443 null, joins));
444 if (val == null)
445 return null;
446 if (val instanceof Calendar)
447 return (Calendar) val;
448
449 Calendar cal = Calendar.getInstance();
450 cal.setTime(new Date(val.toString()));
451 return cal;
452 }
453
454 public char getChar(Object obj)
455 throws SQLException {
456 return getCharInternal(translate(obj, null), null);
457 }
458
459 public char getChar(Column col, Joins joins)
460 throws SQLException {
461 return getCharInternal(translate(col, joins), joins);
462 }
463
464 protected char getCharInternal(Object obj, Joins joins)
465 throws SQLException {
466 Object val = checkNull(getObjectInternal(obj, JavaTypes.CHAR,
467 null, joins));
468 if (val == null)
469 return 0;
470 if (val instanceof Character)
471 return ((Character) val).charValue();
472
473 String str = val.toString();
474 return (str.length() == 0) ? 0 : str.charAt(0);
475 }
476
477 public Reader getCharacterStream(Object obj)
478 throws SQLException {
479 return getCharacterStreamInternal(translate(obj, null), null);
480 }
481
482 public Reader getCharacterStream(Column col, Joins joins)
483 throws SQLException {
484 return getCharacterStreamInternal(translate(col, joins), joins);
485 }
486
487 protected Reader getCharacterStreamInternal(Object obj, Joins joins)
488 throws SQLException {
489 Object val = checkNull(getObjectInternal(obj,
490 JavaSQLTypes.CHAR_STREAM, null, joins));
491 if (val == null)
492 return null;
493 if (val instanceof Reader)
494 return (Reader) val;
495 return new StringReader(val.toString());
496 }
497
498 public Clob getClob(Object obj)
499 throws SQLException {
500 return getClobInternal(translate(obj, null), null);
501 }
502
503 public Clob getClob(Column col, Joins joins)
504 throws SQLException {
505 return getClobInternal(translate(col, joins), joins);
506 }
507
508 protected Clob getClobInternal(Object obj, Joins joins)
509 throws SQLException {
510 return (Clob) checkNull(getObjectInternal(obj, JavaSQLTypes.CLOB,
511 null, joins));
512 }
513
514 public Date getDate(Object obj)
515 throws SQLException {
516 return getDateInternal(translate(obj, null), null);
517 }
518
519 public Date getDate(Column col, Joins joins)
520 throws SQLException {
521 return getDateInternal(translate(col, joins), joins);
522 }
523
524 protected Date getDateInternal(Object obj, Joins joins)
525 throws SQLException {
526 Object val = checkNull(getObjectInternal(obj, JavaTypes.DATE,
527 null, joins));
528 if (val == null)
529 return null;
530 if (val instanceof Date)
531 return (Date) val;
532 return new Date(val.toString());
533 }
534
535 public java.sql.Date getDate(Object obj, Calendar cal)
536 throws SQLException {
537 return getDateInternal(translate(obj, null), cal, null);
538 }
539
540 public java.sql.Date getDate(Column col, Calendar cal, Joins joins)
541 throws SQLException {
542 return getDateInternal(translate(col, joins), cal, joins);
543 }
544
545 protected java.sql.Date getDateInternal(Object obj, Calendar cal,
546 Joins joins)
547 throws SQLException {
548 return (java.sql.Date) checkNull(getObjectInternal(obj,
549 JavaSQLTypes.SQL_DATE, cal, joins));
550 }
551
552 public double getDouble(Object obj)
553 throws SQLException {
554 return getDoubleInternal(translate(obj, null), null);
555 }
556
557 public double getDouble(Column col, Joins joins)
558 throws SQLException {
559 return getDoubleInternal(translate(col, joins), joins);
560 }
561
562 protected double getDoubleInternal(Object obj, Joins joins)
563 throws SQLException {
564 Number val = (Number) checkNull(getObjectInternal(obj,
565 JavaTypes.DOUBLE, null, joins));
566 return (val == null) ? 0 : val.doubleValue();
567 }
568
569 public float getFloat(Object obj)
570 throws SQLException {
571 return getFloatInternal(translate(obj, null), null);
572 }
573
574 public float getFloat(Column col, Joins joins)
575 throws SQLException {
576 return getFloatInternal(translate(col, joins), joins);
577 }
578
579 protected float getFloatInternal(Object obj, Joins joins)
580 throws SQLException {
581 Number val = (Number) checkNull(getObjectInternal(obj,
582 JavaTypes.FLOAT, null, joins));
583 return (val == null) ? 0 : val.floatValue();
584 }
585
586 public int getInt(Object obj)
587 throws SQLException {
588 return getIntInternal(translate(obj, null), null);
589 }
590
591 public int getInt(Column col, Joins joins)
592 throws SQLException {
593 return getIntInternal(translate(col, joins), joins);
594 }
595
596 protected int getIntInternal(Object obj, Joins joins)
597 throws SQLException {
598 Number val = (Number) checkNull(getObjectInternal(obj,
599 JavaTypes.INT, null, joins));
600 return (val == null) ? 0 : val.intValue();
601 }
602
603 public Locale getLocale(Object obj)
604 throws SQLException {
605 return getLocaleInternal(translate(obj, null), null);
606 }
607
608 public Locale getLocale(Column col, Joins joins)
609 throws SQLException {
610 return getLocaleInternal(translate(col, joins), joins);
611 }
612
613 protected Locale getLocaleInternal(Object obj, Joins joins)
614 throws SQLException {
615 Object val = checkNull(getObjectInternal(obj, JavaTypes.LOCALE,
616 null, joins));
617 if (val == null)
618 return null;
619 if (val instanceof Locale)
620 return (Locale) val;
621 String[] vals = Strings.split(val.toString(), "_", 0);
622 if (vals.length < 2)
623 throw new SQLException(val.toString());
624 if (vals.length == 2)
625 return new Locale(vals[0], vals[1]);
626 return new Locale(vals[0], vals[1], vals[2]);
627 }
628
629 public long getLong(Object obj)
630 throws SQLException {
631 return getLongInternal(translate(obj, null), null);
632 }
633
634 public long getLong(Column col, Joins joins)
635 throws SQLException {
636 return getLongInternal(translate(col, joins), joins);
637 }
638
639 protected long getLongInternal(Object obj, Joins joins)
640 throws SQLException {
641 Number val = (Number) checkNull(getObjectInternal(obj,
642 JavaTypes.INT, null, joins));
643 return (val == null) ? 0 : val.intValue();
644 }
645
646 public Number getNumber(Object obj)
647 throws SQLException {
648 return getNumberInternal(translate(obj, null), null);
649 }
650
651 public Number getNumber(Column col, Joins joins)
652 throws SQLException {
653 return getNumberInternal(translate(col, joins), joins);
654 }
655
656 protected Number getNumberInternal(Object obj, Joins joins)
657 throws SQLException {
658 Object val = checkNull(getObjectInternal(obj,
659 JavaTypes.NUMBER, null, joins));
660 if (val == null)
661 return null;
662 if (val instanceof Number)
663 return (Number) val;
664 return new BigDecimal(val.toString());
665 }
666
667 public Object getObject(Object obj, int metaType, Object arg)
668 throws SQLException {
669 return getObjectInternal(translate(obj, null), metaType, arg, null);
670 }
671
672 public Object getObject(Column col, Object arg, Joins joins)
673 throws SQLException {
674 return getObjectInternal(translate(col, joins), col.getJavaType(),
675 arg, joins);
676 }
677
678 /**
679 * Return the value stored in the given id or column.
680 */
681 protected abstract Object getObjectInternal(Object obj, int metaType,
682 Object arg, Joins joins)
683 throws SQLException;
684
685 protected abstract Object getStreamInternal(JDBCStore store, Object obj,
686 int metaType, Object arg, Joins joins) throws SQLException;
687
688 public Object getSQLObject(Object obj, Map map)
689 throws SQLException {
690 return getSQLObjectInternal(translate(obj, null), map, null);
691 }
692
693 public Object getSQLObject(Column col, Map map, Joins joins)
694 throws SQLException {
695 return getSQLObjectInternal(translate(col, joins), map, joins);
696 }
697
698 protected Object getSQLObjectInternal(Object obj, Map map, Joins joins)
699 throws SQLException {
700 return checkNull(getObjectInternal(obj, JavaSQLTypes.SQL_OBJECT,
701 map, joins));
702 }
703
704 public Ref getRef(Object obj, Map map)
705 throws SQLException {
706 return getRefInternal(translate(obj, null), map, null);
707 }
708
709 public Ref getRef(Column col, Map map, Joins joins)
710 throws SQLException {
711 return getRefInternal(translate(col, joins), map, joins);
712 }
713
714 protected Ref getRefInternal(Object obj, Map map, Joins joins)
715 throws SQLException {
716 return (Ref) checkNull(getObjectInternal(obj, JavaSQLTypes.REF,
717 map, joins));
718 }
719
720 public short getShort(Object obj)
721 throws SQLException {
722 return getShortInternal(translate(obj, null), null);
723 }
724
725 public short getShort(Column col, Joins joins)
726 throws SQLException {
727 return getShortInternal(translate(col, joins), joins);
728 }
729
730 protected short getShortInternal(Object obj, Joins joins)
731 throws SQLException {
732 Number val = (Number) checkNull(getObjectInternal(obj,
733 JavaTypes.SHORT, null, joins));
734 return (val == null) ? 0 : val.shortValue();
735 }
736
737 public String getString(Object obj)
738 throws SQLException {
739 return getStringInternal(translate(obj, null), null);
740 }
741
742 public String getString(Column col, Joins joins)
743 throws SQLException {
744 return getStringInternal(translate(col, joins), joins);
745 }
746
747 protected String getStringInternal(Object obj, Joins joins)
748 throws SQLException {
749 Object val = checkNull(getObjectInternal(obj, JavaTypes.STRING,
750 null, joins));
751 return (val == null) ? null : val.toString();
752 }
753
754 public Time getTime(Object obj, Calendar cal)
755 throws SQLException {
756 return getTimeInternal(translate(obj, null), cal, null);
757 }
758
759 public Time getTime(Column col, Calendar cal, Joins joins)
760 throws SQLException {
761 return getTimeInternal(translate(col, joins), cal, joins);
762 }
763
764 protected Time getTimeInternal(Object obj, Calendar cal, Joins joins)
765 throws SQLException {
766 return (Time) checkNull(getObjectInternal(obj, JavaSQLTypes.TIME,
767 cal, joins));
768 }
769
770 public Timestamp getTimestamp(Object obj, Calendar cal)
771 throws SQLException {
772 return getTimestampInternal(translate(obj, null), cal, null);
773 }
774
775 public Timestamp getTimestamp(Column col, Calendar cal, Joins joins)
776 throws SQLException {
777 return getTimestampInternal(translate(col, joins), cal, joins);
778 }
779
780 protected Timestamp getTimestampInternal(Object obj, Calendar cal,
781 Joins joins)
782 throws SQLException {
783 return (Timestamp) checkNull(getObjectInternal(obj,
784 JavaSQLTypes.TIMESTAMP, cal, joins));
785 }
786
787 public boolean wasNull()
788 throws SQLException {
789 return _wasNull;
790 }
791
792 protected Object checkNull(Object val) {
793 _wasNull = (val == null);
794 return val;
795 }
796
797 public void setLocking(boolean locking) {
798 _locking = locking;
799 }
800
801 public boolean isLocking() {
802 return _locking;
803 }
804
805 public void startDataRequest(Object mapping) {
806 }
807
808 public void endDataRequest() {
809 }
810
811 /**
812 * Translate the user-given id or column. This method is called before
813 * delegating to any <code>get*Internal</code> methods. Return the
814 * original value by default.
815 */
816 protected Object translate(Object obj, Joins joins)
817 throws SQLException {
818 return obj;
819 }
820
821 /**
822 * Do-nothing joins implementation.
823 */
824 private static class NoOpJoins
825 implements Joins {
826
827 public boolean isEmpty() {
828 return true;
829 }
830
831 public boolean isOuter() {
832 return false;
833 }
834
835 public Joins crossJoin(Table localTable, Table foreignTable) {
836 return this;
837 }
838
839 public Joins join(ForeignKey fk, boolean inverse, boolean toMany) {
840 return this;
841 }
842
843 public Joins outerJoin(ForeignKey fk, boolean inverse, boolean toMany) {
844 return this;
845 }
846
847 public Joins joinRelation(String name, ForeignKey fk,
848 ClassMapping target, int subs, boolean inverse, boolean toMany) {
849 return this;
850 }
851
852 public Joins outerJoinRelation(String name, ForeignKey fk,
853 ClassMapping target, int subs, boolean inverse, boolean toMany) {
854 return this;
855 }
856
857 public Joins setVariable(String var) {
858 return this;
859 }
860
861 public Joins setSubselect(String alias) {
862 return this;
863 }
864
865 public void appendTo(SQLBuffer buf) {
866 }
867 }
868 }