openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r423615 [29/44] - in /incubator/openjpa/trunk: ./ openjpa-jdbc-5/ openjpa-jdbc-5/src/ openjpa-jdbc-5/src/main/ openjpa-jdbc-5/src/main/java/ openjpa-jdbc-5/src/main/java/org/ openjpa-jdbc-5/src/main/java/org/apache/ openjpa-jdbc-5/src/main/...
Date Wed, 19 Jul 2006 21:35:07 GMT
Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,847 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.openjpa.jdbc.kernel.JDBCFetchState;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.lib.util.Closeable;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.util.UnsupportedException;
+import serp.util.Strings;
+
+/**
+ * A {@link Result} implementation designed to be subclassed easily by
+ * implementations. All <code>get&lt;type&gt;</code> calls are delegated
to
+ * the {@link #getObjectInternal(Object,int,Object,Joins)} method, which
+ * should be implemented by subclasses along with {@link #nextInternal},
+ * {@link #containsInternal}, and {@link Result#size}.
+ *  Most of the methods of this class will accept return values from
+ * {@link #getObjectInternal(Object,int,Object,Joins)} that are not exactly
+ * the right type. For example, any numeric type can be returned as any
+ * {@link Number} type, and dates, locales, characters, and booleans can be
+ * returned as strings.
+ *
+ * @author Abe White
+ * @see ResultSetResult
+ */
+public abstract class AbstractResult
+    implements Result {
+
+    private static final Joins JOINS = new NoOpJoins();
+
+    private Map _eager = null;
+    private ClassMapping _base = null;
+    private int _index = 0;
+    private boolean _gotEager = false;
+    private boolean _wasNull = false;
+    private boolean _locking = false;
+    private boolean _ignoreNext = false;
+    private boolean _last = false;
+
+    public Object getEager(FieldMapping key) {
+        Map map = getEagerMap(true);
+        return (map == null) ? null : map.get(key);
+    }
+
+    public void putEager(FieldMapping key, Object res) {
+        Map map = getEagerMap(false);
+        if (map == null) {
+            map = new HashMap();
+            setEagerMap(map);
+        }
+        map.put(key, res);
+    }
+
+    /**
+     * Raw eager information. May be null.
+     *
+     * @param client whether the client is accessing eager information
+     */
+    protected Map getEagerMap(boolean client) {
+        if (client)
+            _gotEager = true;
+        return _eager;
+    }
+
+    /**
+     * Raw eager information.
+     */
+    protected void setEagerMap(Map eager) {
+        _eager = eager;
+    }
+
+    /**
+     * Closes all eager results.
+     */
+    public void close() {
+        closeEagerMap(_eager);
+    }
+
+    /**
+     * Close all results in eager map.
+     */
+    protected void closeEagerMap(Map eager) {
+        if (eager != null) {
+            Object res;
+            for (Iterator itr = eager.values().iterator(); itr.hasNext();) {
+                res = itr.next();
+                if (res != this && res instanceof Closeable)
+                    try {
+                        ((Closeable) res).close();
+                    } catch (Exception e) {
+                    }
+            }
+        }
+    }
+
+    /**
+     * Returns false by default.
+     */
+    public boolean supportsRandomAccess()
+        throws SQLException {
+        return false;
+    }
+
+    public boolean absolute(int row)
+        throws SQLException {
+        _gotEager = false;
+        return absoluteInternal(row);
+    }
+
+    /**
+     * Throws an exception by default.
+     */
+    protected boolean absoluteInternal(int row)
+        throws SQLException {
+        throw new UnsupportedException();
+    }
+
+    public boolean next()
+        throws SQLException {
+        _gotEager = false;
+        if (_ignoreNext) {
+            _ignoreNext = false;
+            return _last;
+        }
+        _last = nextInternal();
+        return _last;
+    }
+
+    /**
+     * Advance this row.
+     */
+    protected abstract boolean nextInternal()
+        throws SQLException;
+
+    public void pushBack()
+        throws SQLException {
+        _ignoreNext = true;
+    }
+
+    /**
+     * Returns a no-op joins object by default.
+     */
+    public Joins newJoins() {
+        return JOINS;
+    }
+
+    public boolean contains(Object obj)
+        throws SQLException {
+        return containsInternal(obj, null);
+    }
+
+    public boolean containsAll(Object[] objs)
+        throws SQLException {
+        return containsAllInternal(objs, null);
+    }
+
+    public boolean contains(Column col, Joins joins)
+        throws SQLException {
+        return containsInternal(col, joins);
+    }
+
+    public boolean containsAll(Column[] cols, Joins joins)
+        throws SQLException {
+        return containsAllInternal(cols, joins);
+    }
+
+    /**
+     * Return whether this result contains data for the given id or column.
+     * The id or column has not beed passed through {@link #translate}.
+     */
+    protected abstract boolean containsInternal(Object obj, Joins joins)
+        throws SQLException;
+
+    /**
+     * Return whether this result contains data for all the given ids or
+     * columns. The ids or columns have not been passed through
+     * {@link #translate}. Delegates to {@link #containsInternal} by default.
+     */
+    protected boolean containsAllInternal(Object[] objs, Joins joins)
+        throws SQLException {
+        for (int i = 0; i < objs.length; i++)
+            if (!containsInternal(objs[i], joins))
+                return false;
+        return true;
+    }
+
+    public ClassMapping getBaseMapping() {
+        // if we've returned an eager result this call might be for that eager
+        // result instead of our primary mapping, so return null
+        return (_gotEager) ? null : _base;
+    }
+
+    public void setBaseMapping(ClassMapping base) {
+        _base = base;
+    }
+
+    public int indexOf() {
+        return _index;
+    }
+
+    public void setIndexOf(int idx) {
+        _index = idx;
+    }
+
+    public Object load(ClassMapping mapping, JDBCStore store,
+        JDBCFetchState fetchState)
+        throws SQLException {
+        return load(mapping, store, fetchState, null);
+    }
+
+    public Object load(ClassMapping mapping, JDBCStore store,
+        JDBCFetchState fetchState, Joins joins)
+        throws SQLException {
+        return ((JDBCStoreManager) store).load(mapping, fetchState, null,
+            this);
+    }
+
+    public Array getArray(Object obj)
+        throws SQLException {
+        return getArrayInternal(translate(obj, null), null);
+    }
+
+    public Array getArray(Column col, Joins joins)
+        throws SQLException {
+        return getArrayInternal(translate(col, joins), joins);
+    }
+
+    protected Array getArrayInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (Array) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.SQL_ARRAY, null, joins));
+    }
+
+    public InputStream getAsciiStream(Object obj)
+        throws SQLException {
+        return getAsciiStreamInternal(translate(obj, null), null);
+    }
+
+    public InputStream getAsciiStream(Column col, Joins joins)
+        throws SQLException {
+        return getAsciiStreamInternal(translate(col, joins), joins);
+    }
+
+    protected InputStream getAsciiStreamInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (InputStream) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.ASCII_STREAM, null, joins));
+    }
+
+    public BigDecimal getBigDecimal(Object obj)
+        throws SQLException {
+        return getBigDecimalInternal(translate(obj, null), null);
+    }
+
+    public BigDecimal getBigDecimal(Column col, Joins joins)
+        throws SQLException {
+        return getBigDecimalInternal(translate(col, joins), joins);
+    }
+
+    protected BigDecimal getBigDecimalInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj,
+            JavaTypes.BIGDECIMAL, null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof BigDecimal)
+            return (BigDecimal) val;
+        return new BigDecimal(val.toString());
+    }
+
+    public BigInteger getBigInteger(Object obj)
+        throws SQLException {
+        return getBigIntegerInternal(translate(obj, null), null);
+    }
+
+    public BigInteger getBigInteger(Column col, Joins joins)
+        throws SQLException {
+        return getBigIntegerInternal(translate(col, joins), joins);
+    }
+
+    protected BigInteger getBigIntegerInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj,
+            JavaTypes.BIGINTEGER, null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof BigInteger)
+            return (BigInteger) val;
+        return new BigInteger(val.toString());
+    }
+
+    public InputStream getBinaryStream(Object obj)
+        throws SQLException {
+        return getBinaryStreamInternal(translate(obj, null), null);
+    }
+
+    public InputStream getBinaryStream(Column col, Joins joins)
+        throws SQLException {
+        return getBinaryStreamInternal(translate(col, joins), joins);
+    }
+
+    protected InputStream getBinaryStreamInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (InputStream) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.BINARY_STREAM, null, joins));
+    }
+
+    public Blob getBlob(Object obj)
+        throws SQLException {
+        return getBlobInternal(translate(obj, null), null);
+    }
+
+    public Blob getBlob(Column col, Joins joins)
+        throws SQLException {
+        return getBlobInternal(translate(col, joins), joins);
+    }
+
+    protected Blob getBlobInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (Blob) checkNull(getObjectInternal(obj, JavaSQLTypes.BLOB,
+            null, joins));
+    }
+
+    public boolean getBoolean(Object obj)
+        throws SQLException {
+        return getBooleanInternal(translate(obj, null), null);
+    }
+
+    public boolean getBoolean(Column col, Joins joins)
+        throws SQLException {
+        return getBooleanInternal(translate(col, joins), joins);
+    }
+
+    protected boolean getBooleanInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.BOOLEAN,
+            null, joins));
+        if (val == null)
+            return false;
+        return Boolean.valueOf(val.toString()).booleanValue();
+    }
+
+    public byte getByte(Object obj)
+        throws SQLException {
+        return getByteInternal(translate(obj, null), null);
+    }
+
+    public byte getByte(Column col, Joins joins)
+        throws SQLException {
+        return getByteInternal(translate(col, joins), joins);
+    }
+
+    protected byte getByteInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.BYTE, null, joins));
+        return (val == null) ? 0 : val.byteValue();
+    }
+
+    public byte[] getBytes(Object obj)
+        throws SQLException {
+        return getBytesInternal(translate(obj, null), null);
+    }
+
+    public byte[] getBytes(Column col, Joins joins)
+        throws SQLException {
+        return getBytesInternal(translate(col, joins), joins);
+    }
+
+    protected byte[] getBytesInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (byte[]) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.BYTES, null, joins));
+    }
+
+    public Calendar getCalendar(Object obj)
+        throws SQLException {
+        return getCalendarInternal(translate(obj, null), null);
+    }
+
+    public Calendar getCalendar(Column col, Joins joins)
+        throws SQLException {
+        return getCalendarInternal(translate(col, joins), joins);
+    }
+
+    protected Calendar getCalendarInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.CALENDAR,
+            null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof Calendar)
+            return (Calendar) val;
+
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date(val.toString()));
+        return cal;
+    }
+
+    public char getChar(Object obj)
+        throws SQLException {
+        return getCharInternal(translate(obj, null), null);
+    }
+
+    public char getChar(Column col, Joins joins)
+        throws SQLException {
+        return getCharInternal(translate(col, joins), joins);
+    }
+
+    protected char getCharInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.CHAR,
+            null, joins));
+        if (val == null)
+            return 0;
+        if (val instanceof Character)
+            return ((Character) val).charValue();
+
+        String str = val.toString();
+        return (str.length() == 0) ? 0 : str.charAt(0);
+    }
+
+    public Reader getCharacterStream(Object obj)
+        throws SQLException {
+        return getCharacterStreamInternal(translate(obj, null), null);
+    }
+
+    public Reader getCharacterStream(Column col, Joins joins)
+        throws SQLException {
+        return getCharacterStreamInternal(translate(col, joins), joins);
+    }
+
+    protected Reader getCharacterStreamInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj,
+            JavaSQLTypes.CHAR_STREAM, null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof Reader)
+            return (Reader) val;
+        return new StringReader(val.toString());
+    }
+
+    public Clob getClob(Object obj)
+        throws SQLException {
+        return getClobInternal(translate(obj, null), null);
+    }
+
+    public Clob getClob(Column col, Joins joins)
+        throws SQLException {
+        return getClobInternal(translate(col, joins), joins);
+    }
+
+    protected Clob getClobInternal(Object obj, Joins joins)
+        throws SQLException {
+        return (Clob) checkNull(getObjectInternal(obj, JavaSQLTypes.CLOB,
+            null, joins));
+    }
+
+    public Date getDate(Object obj)
+        throws SQLException {
+        return getDateInternal(translate(obj, null), null);
+    }
+
+    public Date getDate(Column col, Joins joins)
+        throws SQLException {
+        return getDateInternal(translate(col, joins), joins);
+    }
+
+    protected Date getDateInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.DATE,
+            null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof Date)
+            return (Date) val;
+        return new Date(val.toString());
+    }
+
+    public java.sql.Date getDate(Object obj, Calendar cal)
+        throws SQLException {
+        return getDateInternal(translate(obj, null), cal, null);
+    }
+
+    public java.sql.Date getDate(Column col, Calendar cal, Joins joins)
+        throws SQLException {
+        return getDateInternal(translate(col, joins), cal, joins);
+    }
+
+    protected java.sql.Date getDateInternal(Object obj, Calendar cal,
+        Joins joins)
+        throws SQLException {
+        return (java.sql.Date) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.SQL_DATE, cal, joins));
+    }
+
+    public double getDouble(Object obj)
+        throws SQLException {
+        return getDoubleInternal(translate(obj, null), null);
+    }
+
+    public double getDouble(Column col, Joins joins)
+        throws SQLException {
+        return getDoubleInternal(translate(col, joins), joins);
+    }
+
+    protected double getDoubleInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.DOUBLE, null, joins));
+        return (val == null) ? 0 : val.doubleValue();
+    }
+
+    public float getFloat(Object obj)
+        throws SQLException {
+        return getFloatInternal(translate(obj, null), null);
+    }
+
+    public float getFloat(Column col, Joins joins)
+        throws SQLException {
+        return getFloatInternal(translate(col, joins), joins);
+    }
+
+    protected float getFloatInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.FLOAT, null, joins));
+        return (val == null) ? 0 : val.floatValue();
+    }
+
+    public int getInt(Object obj)
+        throws SQLException {
+        return getIntInternal(translate(obj, null), null);
+    }
+
+    public int getInt(Column col, Joins joins)
+        throws SQLException {
+        return getIntInternal(translate(col, joins), joins);
+    }
+
+    protected int getIntInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.INT, null, joins));
+        return (val == null) ? 0 : val.intValue();
+    }
+
+    public Locale getLocale(Object obj)
+        throws SQLException {
+        return getLocaleInternal(translate(obj, null), null);
+    }
+
+    public Locale getLocale(Column col, Joins joins)
+        throws SQLException {
+        return getLocaleInternal(translate(col, joins), joins);
+    }
+
+    protected Locale getLocaleInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.LOCALE,
+            null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof Locale)
+            return (Locale) val;
+        String[] vals = Strings.split(val.toString(), "_", 0);
+        if (vals.length < 2)
+            throw new SQLException(val.toString());
+        if (vals.length == 2)
+            return new Locale(vals[0], vals[1]);
+        return new Locale(vals[0], vals[1], vals[2]);
+    }
+
+    public long getLong(Object obj)
+        throws SQLException {
+        return getLongInternal(translate(obj, null), null);
+    }
+
+    public long getLong(Column col, Joins joins)
+        throws SQLException {
+        return getLongInternal(translate(col, joins), joins);
+    }
+
+    protected long getLongInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.INT, null, joins));
+        return (val == null) ? 0 : val.intValue();
+    }
+
+    public Number getNumber(Object obj)
+        throws SQLException {
+        return getNumberInternal(translate(obj, null), null);
+    }
+
+    public Number getNumber(Column col, Joins joins)
+        throws SQLException {
+        return getNumberInternal(translate(col, joins), joins);
+    }
+
+    protected Number getNumberInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj,
+            JavaTypes.NUMBER, null, joins));
+        if (val == null)
+            return null;
+        if (val instanceof Number)
+            return (Number) val;
+        return new BigDecimal(val.toString());
+    }
+
+    public Object getObject(Object obj, int metaType, Object arg)
+        throws SQLException {
+        return getObjectInternal(translate(obj, null), metaType, arg, null);
+    }
+
+    public Object getObject(Column col, Object arg, Joins joins)
+        throws SQLException {
+        return getObjectInternal(translate(col, joins), col.getJavaType(),
+            arg, joins);
+    }
+
+    /**
+     * Return the value stored in the given id or column.
+     */
+    protected abstract Object getObjectInternal(Object obj, int metaType,
+        Object arg, Joins joins)
+        throws SQLException;
+
+    public Object getSQLObject(Object obj, Map map)
+        throws SQLException {
+        return getSQLObjectInternal(translate(obj, null), map, null);
+    }
+
+    public Object getSQLObject(Column col, Map map, Joins joins)
+        throws SQLException {
+        return getSQLObjectInternal(translate(col, joins), map, joins);
+    }
+
+    protected Object getSQLObjectInternal(Object obj, Map map, Joins joins)
+        throws SQLException {
+        return checkNull(getObjectInternal(obj, JavaSQLTypes.SQL_OBJECT,
+            map, joins));
+    }
+
+    public Ref getRef(Object obj, Map map)
+        throws SQLException {
+        return getRefInternal(translate(obj, null), map, null);
+    }
+
+    public Ref getRef(Column col, Map map, Joins joins)
+        throws SQLException {
+        return getRefInternal(translate(col, joins), map, joins);
+    }
+
+    protected Ref getRefInternal(Object obj, Map map, Joins joins)
+        throws SQLException {
+        return (Ref) checkNull(getObjectInternal(obj, JavaSQLTypes.REF,
+            map, joins));
+    }
+
+    public short getShort(Object obj)
+        throws SQLException {
+        return getShortInternal(translate(obj, null), null);
+    }
+
+    public short getShort(Column col, Joins joins)
+        throws SQLException {
+        return getShortInternal(translate(col, joins), joins);
+    }
+
+    protected short getShortInternal(Object obj, Joins joins)
+        throws SQLException {
+        Number val = (Number) checkNull(getObjectInternal(obj,
+            JavaTypes.SHORT, null, joins));
+        return (val == null) ? 0 : val.shortValue();
+    }
+
+    public String getString(Object obj)
+        throws SQLException {
+        return getStringInternal(translate(obj, null), null);
+    }
+
+    public String getString(Column col, Joins joins)
+        throws SQLException {
+        return getStringInternal(translate(col, joins), joins);
+    }
+
+    protected String getStringInternal(Object obj, Joins joins)
+        throws SQLException {
+        Object val = checkNull(getObjectInternal(obj, JavaTypes.STRING,
+            null, joins));
+        return (val == null) ? null : val.toString();
+    }
+
+    public Time getTime(Object obj, Calendar cal)
+        throws SQLException {
+        return getTimeInternal(translate(obj, null), cal, null);
+    }
+
+    public Time getTime(Column col, Calendar cal, Joins joins)
+        throws SQLException {
+        return getTimeInternal(translate(col, joins), cal, joins);
+    }
+
+    protected Time getTimeInternal(Object obj, Calendar cal, Joins joins)
+        throws SQLException {
+        return (Time) checkNull(getObjectInternal(obj, JavaSQLTypes.TIME,
+            cal, joins));
+    }
+
+    public Timestamp getTimestamp(Object obj, Calendar cal)
+        throws SQLException {
+        return getTimestampInternal(translate(obj, null), cal, null);
+    }
+
+    public Timestamp getTimestamp(Column col, Calendar cal, Joins joins)
+        throws SQLException {
+        return getTimestampInternal(translate(col, joins), cal, joins);
+    }
+
+    protected Timestamp getTimestampInternal(Object obj, Calendar cal,
+        Joins joins)
+        throws SQLException {
+        return (Timestamp) checkNull(getObjectInternal(obj,
+            JavaSQLTypes.TIMESTAMP, cal, joins));
+    }
+
+    public boolean wasNull()
+        throws SQLException {
+        return _wasNull;
+    }
+
+    protected Object checkNull(Object val) {
+        _wasNull = (val == null);
+        return val;
+    }
+
+    public void setLocking(boolean locking) {
+        _locking = locking;
+    }
+
+    public boolean isLocking() {
+        return _locking;
+    }
+
+    public void startDataRequest(Object mapping) {
+    }
+
+    public void endDataRequest() {
+    }
+
+    /**
+     * Translate the user-given id or column. This method is called before
+     * delegating to any <code>get*Internal</code> methods. Return the
+     * original value by default.
+     */
+    protected Object translate(Object obj, Joins joins)
+        throws SQLException {
+        return obj;
+    }
+
+    /**
+     * Do-nothing joins implementation.
+     */
+    private static class NoOpJoins
+        implements Joins {
+
+        public boolean isEmpty() {
+            return true;
+        }
+
+        public Joins crossJoin(Table localTable, Table foreignTable) {
+            return this;
+        }
+
+        public Joins join(ForeignKey fk, boolean inverse, boolean toMany) {
+            return this;
+        }
+
+        public Joins outerJoin(ForeignKey fk, boolean inverse, boolean toMany) {
+            return this;
+        }
+
+        public Joins joinRelation(String name, ForeignKey fk, boolean inverse,
+            boolean toMany) {
+            return this;
+        }
+
+        public Joins outerJoinRelation(String name, ForeignKey fk,
+            boolean inverse, boolean toMany) {
+            return this;
+        }
+
+        public Joins setVariable(String var) {
+            return this;
+        }
+
+        public Joins setSubselect(String alias) {
+            return this;
+        }
+
+        public void appendTo(SQLBuffer buf) {
+        }
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractResult.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Arrays;
+
+import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Index;
+
+/**
+ * Dictionary for the SQL Server databases (Sybase and MS SQL Server).
+ */
+public abstract class AbstractSQLServerDictionary
+    extends DBDictionary {
+
+    public AbstractSQLServerDictionary() {
+        reservedWordSet.add("FILE");
+        systemTableSet.add("DTPROPERTIES");
+        validationSQL = "SELECT GETDATE()";
+        rangePosition = RANGE_POST_DISTINCT;
+
+        supportsDeferredConstraints = false;
+        supportsSelectEndIndex = true;
+        allowsAliasInBulkClause = false;
+
+        supportsAutoAssign = true;
+        autoAssignClause = "IDENTITY";
+        lastGeneratedKeyQuery = "SELECT @@IDENTITY";
+
+        trimLeadingFunction = "LTRIM({0})";
+        trimTrailingFunction = "RTRIM({0})";
+        trimBothFunction = "LTRIM(RTRIM({0}))";
+        concatenateFunction = "({0}+{1})";
+        supportsModOperator = true;
+
+        currentDateFunction = "GETDATE()";
+        currentTimeFunction = "GETDATE()";
+        currentTimestampFunction = "GETDATE()";
+
+        useGetStringForClobs = true;
+        useSetStringForClobs = true;
+        useGetBytesForBlobs = true;
+        useSetBytesForBlobs = true;
+        binaryTypeName = "BINARY";
+        blobTypeName = "IMAGE";
+        longVarbinaryTypeName = "IMAGE";
+        clobTypeName = "TEXT";
+        longVarcharTypeName = "TEXT";
+        dateTypeName = "DATETIME";
+        timeTypeName = "DATETIME";
+        timestampTypeName = "DATETIME";
+        floatTypeName = "FLOAT(16)";
+        doubleTypeName = "FLOAT(32)";
+        integerTypeName = "INT";
+        fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{
+            "IMAGE", "TEXT", "NTEXT", "MONEY", "SMALLMONEY", "INT",
+            "DOUBLE PRECISION", "DATETIME", "SMALLDATETIME",
+            "EXTENDED TYPE", "SYSNAME", "SQL_VARIANT", "INDEX",
+        }));
+    }
+
+    public Column[] getColumns(DatabaseMetaData meta, String catalog,
+        String schemaName, String tableName, String colName, Connection conn)
+        throws SQLException {
+        Column[] cols = super.getColumns(meta, catalog, schemaName, tableName,
+            colName, conn);
+        for (int i = 0; cols != null && i < cols.length; i++)
+            if (cols[i].getType() == Types.LONGVARCHAR)
+                cols[i].setType(Types.CLOB);
+        return cols;
+    }
+
+    public String getFullName(Index idx) {
+        return getFullName(idx.getTable(), false) + "." + idx.getName();
+    }
+
+    public void setNull(PreparedStatement stmnt, int idx, int colType,
+        Column col)
+        throws SQLException {
+        // SQLServer has some problems with setNull on lobs
+        if (colType == Types.CLOB)
+            stmnt.setString(idx, null);
+        else if (colType == Types.BLOB)
+            stmnt.setBytes(idx, null);
+        else
+            super.setNull(stmnt, idx, colType, col);
+    }
+
+    protected void appendSelectRange(SQLBuffer buf, long start, long end) {
+        // cannot use a value here, since SQLServer does not support
+        // bound parameters in a "TOP" clause
+        buf.append(" TOP ").append(Long.toString(end));
+    }
+
+    public void substring(SQLBuffer buf, FilterValue str, FilterValue start,
+        FilterValue end) {
+        buf.append("SUBSTRING(");
+        str.appendTo(buf);
+        buf.append(", ");
+        start.appendTo(buf);
+        buf.append(" + 1, ");
+        if (end != null) {
+            buf.append("(");
+            end.appendTo(buf);
+            buf.append(")");
+        } else {
+            buf.append("LEN(");
+            str.appendTo(buf);
+            buf.append(")");
+        }
+        buf.append(" - (");
+        start.appendTo(buf);
+        buf.append("))");
+    }
+
+    public void indexOf(SQLBuffer buf, FilterValue str, FilterValue find,
+        FilterValue start) {
+        buf.append("(CHARINDEX(");
+        find.appendTo(buf);
+        buf.append(", ");
+        if (start != null)
+            substring(buf, str, start, null);
+        else
+            str.appendTo(buf);
+        buf.append(") - 1");
+        if (start != null) {
+            buf.append(" + ");
+            start.appendTo(buf);
+        }
+        buf.append(")");
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AbstractSQLServerDictionary.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AccessDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AccessDictionary.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AccessDictionary.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AccessDictionary.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
+import org.apache.openjpa.jdbc.schema.Column;
+
+/**
+ * Dictionary for Access via DataDirect SequeLink and DataDirect ODBC
+ * FoxPro driver. This will not work with any other combination of JDBC/ODBC
+ * server and ODBC driver.
+ */
+public class AccessDictionary
+    extends DBDictionary {
+
+    public AccessDictionary() {
+        platform = "Microsoft Access";
+        joinSyntax = SYNTAX_TRADITIONAL;
+        validationSQL = "SELECT 1";
+        reservedWordSet.add("VALUE");
+
+        supportsAutoAssign = true;
+        autoAssignTypeName = "COUNTER";
+        lastGeneratedKeyQuery = "SELECT @@identity";
+        maxTableNameLength = 64;
+        maxColumnNameLength = 64;
+        maxIndexNameLength = 64;
+        maxConstraintNameLength = 64;
+
+        useGetBytesForBlobs = true;
+        useGetBestRowIdentifierForPrimaryKeys = true;
+
+        binaryTypeName = "LONGBINARY";
+        blobTypeName = "LONGBINARY";
+        longVarbinaryTypeName = "LONGBINARY";
+        clobTypeName = "LONGCHAR";
+        longVarcharTypeName = "LONGCHAR";
+        bigintTypeName = "REAL";
+        numericTypeName = "REAL";
+        integerTypeName = "INTEGER";
+        smallintTypeName = "SMALLINT";
+        tinyintTypeName = "SMALLINT";
+
+        supportsForeignKeys = false;
+        supportsDeferredConstraints = false;
+        maxIndexesPerTable = 32;
+    }
+
+    public void setLong(PreparedStatement stmnt, int idx, long val, Column col)
+        throws SQLException {
+        // the access driver disallows setLong for some reason; use
+        // setInt if possible, otherwise use setDouble
+
+        if (val < Integer.MAX_VALUE && val > Integer.MIN_VALUE)
+            stmnt.setInt(idx, (int) val);
+        else
+            stmnt.setDouble(idx, val);
+    }
+
+    public void substring(SQLBuffer buf, FilterValue str, FilterValue start,
+        FilterValue end) {
+        buf.append("MID(");
+        str.appendTo(buf);
+        buf.append(", (");
+        start.appendTo(buf);
+        buf.append(" + 1)");
+        if (end != null) {
+            buf.append(", (");
+            end.appendTo(buf);
+            buf.append(" - ");
+            start.appendTo(buf);
+            buf.append(")");
+        }
+        buf.append(")");
+    }
+}
+

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/AccessDictionary.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/CacheDictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/CacheDictionary.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/CacheDictionary.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/CacheDictionary.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+/**
+ * Dictionary for Intersystems Cache.
+ */
+public class CacheDictionary
+    extends DBDictionary {
+
+    public CacheDictionary() {
+        platform = "Intersystems Cache";
+        supportsDeferredConstraints = false;
+        supportsSelectForUpdate = true;
+        validationSQL = "SET OPTION DUMMY=DUMMY";
+
+        bigintTypeName = "NUMERIC";
+        numericTypeName = "NUMERIC";
+        clobTypeName = "LONGVARCHAR";
+        blobTypeName = "LONGVARBINARY";
+
+        // use Cache's objectscript for assigning auto-assigned values
+        autoAssignClause = "DEFAULT OBJECTSCRIPT '$INCREMENT(^LogNumber)'";
+
+        // there is no built-in function for getting the last generated
+        // key in Cache; using MAX will have to suffice
+        lastGeneratedKeyQuery = "SELECT MAX({0}) FROM {1}";
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/CacheDictionary.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Calendard.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Calendard.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Calendard.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Calendard.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+import java.util.Calendar;
+
+/**
+ * A calendar-modified value. Used to represent both a value and its
+ * calendar for calls to {@link Row#setObject}.
+ *
+ * @author Abe White
+ */
+public class Calendard {
+
+    public final Object value;
+    public final Calendar calendar;
+
+    public Calendard(Object value, Calendar calendar) {
+        this.value = value;
+        this.calendar = calendar;
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/Calendard.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Wed Jul 19 14:34:44 2006
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.jdbc.sql;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import org.apache.openjpa.jdbc.schema.Sequence;
+
+/**
+ * Dictionary for IBM DB2 database.
+ */
+public class DB2Dictionary
+    extends AbstractDB2Dictionary {
+
+    public DB2Dictionary() {
+        platform = "DB2";
+        validationSQL = "SELECT DISTINCT(CURRENT TIMESTAMP) FROM "
+            + "SYSIBM.SYSTABLES";
+        supportsSelectEndIndex = true;
+
+        nextSequenceQuery = "SELECT NEXTVAL FOR {0}";
+
+        binaryTypeName = "BLOB(1M)";
+        longVarbinaryTypeName = "BLOB(1M)";
+        varbinaryTypeName = "BLOB(1M)";
+        clobTypeName = "CLOB(1M)";
+        longVarcharTypeName = "LONG VARCHAR";
+
+        fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{
+            "LONG VARCHAR FOR BIT DATA", "LONG VARCHAR", "LONG VARGRAPHIC",
+        }));
+
+        maxConstraintNameLength = 18;
+        maxIndexNameLength = 18;
+        maxColumnNameLength = 30;
+        supportsDeferredConstraints = false;
+        supportsDefaultDeleteAction = false;
+        supportsAlterTableWithDropColumn = false;
+
+        supportsNullTableForGetColumns = false;
+
+        reservedWordSet.addAll(Arrays.asList(new String[]{
+            "AFTER", "ALIAS", "ALLOW", "APPLICATION", "ASSOCIATE", "ASUTIME",
+            "AUDIT", "AUX", "AUXILIARY", "BEFORE", "BINARY", "BUFFERPOOL",
+            "CACHE", "CALL", "CALLED", "CAPTURE", "CARDINALITY", "CCSID",
+            "CLUSTER", "COLLECTION", "COLLID", "COMMENT", "CONCAT",
+            "CONDITION", "CONTAINS", "COUNT_BIG", "CURRENT_LC_CTYPE",
+            "CURRENT_PATH", "CURRENT_SERVER", "CURRENT_TIMEZONE", "CYCLE",
+            "DATA", "DATABASE", "DAYS", "DB2GENERAL", "DB2GENRL", "DB2SQL",
+            "DBINFO", "DEFAULTS", "DEFINITION", "DETERMINISTIC", "DISALLOW",
+            "DO", "DSNHATTR", "DSSIZE", "DYNAMIC", "EACH", "EDITPROC", "ELSEIF",
+            "ENCODING", "END-EXEC1", "ERASE", "EXCLUDING", "EXIT", "FENCED",
+            "FIELDPROC", "FILE", "FINAL", "FREE", "FUNCTION", "GENERAL",
+            "GENERATED", "GRAPHIC", "HANDLER", "HOLD", "HOURS", "IF",
+            "INCLUDING", "INCREMENT", "INDEX", "INHERIT", "INOUT", "INTEGRITY",
+            "ISOBID", "ITERATE", "JAR", "JAVA", "LABEL", "LC_CTYPE", "LEAVE",
+            "LINKTYPE", "LOCALE", "LOCATOR", "LOCATORS", "LOCK", "LOCKMAX",
+            "LOCKSIZE", "LONG", "LOOP", "MAXVALUE", "MICROSECOND",
+            "MICROSECONDS", "MINUTES", "MINVALUE", "MODE", "MODIFIES", "MONTHS",
+            "NEW", "NEW_TABLE", "NOCACHE", "NOCYCLE", "NODENAME", "NODENUMBER",
+            "NOMAXVALUE", "NOMINVALUE", "NOORDER", "NULLS", "NUMPARTS", "OBID",
+            "OLD", "OLD_TABLE", "OPTIMIZATION", "OPTIMIZE", "OUT", "OVERRIDING",
+            "PACKAGE", "PARAMETER", "PART", "PARTITION", "PATH", "PIECESIZE",
+            "PLAN", "PRIQTY", "PROGRAM", "PSID", "QUERYNO", "READS", "RECOVERY",
+            "REFERENCING", "RELEASE", "RENAME", "REPEAT", "RESET", "RESIGNAL",
+            "RESTART", "RESULT", "RESULT_SET_LOCATOR", "RETURN", "RETURNS",
+            "ROUTINE", "ROW", "RRN", "RUN", "SAVEPOINT", "SCRATCHPAD",
+            "SECONDS", "SECQTY", "SECURITY", "SENSITIVE", "SIGNAL", "SIMPLE",
+            "SOURCE", "SPECIFIC", "SQLID", "STANDARD", "START", "STATIC",
+            "STAY", "STOGROUP", "STORES", "STYLE", "SUBPAGES", "SYNONYM",
+            "SYSFUN", "SYSIBM", "SYSPROC", "SYSTEM", "TABLESPACE", "TRIGGER",
+            "TYPE", "UNDO", "UNTIL", "VALIDPROC", "VARIABLE", "VARIANT", "VCAT",
+            "VOLUMES", "WHILE", "WLM", "YEARS",
+        }));
+    }
+
+    public boolean supportsRandomAccessResultSet(Select sel,
+        boolean forUpdate) {
+        return !forUpdate
+            && super.supportsRandomAccessResultSet(sel, forUpdate);
+    }
+
+    protected void appendSelectRange(SQLBuffer buf, long start, long end) {
+        // appends the literal range string, since DB2 is unable to handle
+        // a bound parameter for it
+        buf.append(" FETCH FIRST ").append(Long.toString(end)).
+            append(" ROWS ONLY");
+    }
+
+    public String[] getCreateSequenceSQL(Sequence seq) {
+        String[] sql = super.getCreateSequenceSQL(seq);
+        if (seq.getAllocate() > 1)
+            sql[0] += " CACHE " + seq.getAllocate();
+        return sql;
+    }
+
+    protected String getSequencesSQL(String schemaName, String sequenceName) {
+        StringBuffer buf = new StringBuffer();
+        buf.append("SELECT SEQSCHEMA AS SEQUENCE_SCHEMA, ").
+            append("SEQNAME AS SEQUENCE_NAME FROM SYSCAT.SEQUENCES");
+        if (schemaName != null || sequenceName != null)
+            buf.append(" WHERE ");
+        if (schemaName != null) {
+            buf.append("SEQSCHEMA = ?");
+            if (sequenceName != null)
+                buf.append(" AND ");
+        }
+        if (sequenceName != null)
+            buf.append("SEQNAME = ?");
+        return buf.toString();
+    }
+
+    public Connection decorate(Connection conn)
+        throws SQLException {
+        // some versions of the DB2 driver seem to default to
+        // READ_UNCOMMITTED, which will prevent locking from working
+        // (multiple SELECT ... FOR UPDATE statements are allowed on
+        // the same instance); if we have not overridden the
+        // transaction isolation in the configuration, default to
+        // TRANSACTION_READ_COMMITTED
+        conn = super.decorate(conn);
+
+        if (conf.getTransactionIsolationConstant() == -1
+            && conn.getTransactionIsolation() < conn.TRANSACTION_READ_COMMITTED)
+            conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED);
+
+        return conn;
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message