Author: tv Date: Thu Dec 20 12:33:43 2018 New Revision: 1849379 URL: http://svn.apache.org/viewvc?rev=1849379&view=rev Log: Generify ObjectKey (template adjustments follow)
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ComboKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/DateKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/NumberKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectModel.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/StringKey.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/objectbuilder/ObjectOrColumnPsPartBuilder.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestManager.java db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestPersistent.java db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java Thu Dec 20 12:33:43 2018 @@ -63,7 +63,7 @@ implements Serializable protected static final Log log = LogFactory.getLog(AbstractBaseManager.class); /** used to cache the om objects. cache is set by the region property */ - protected transient CacheAccess<ObjectKey, T> cache; + protected transient CacheAccess<ObjectKey<?>, T> cache; /** used to cache the method result objects. cache is set by the region property */ protected transient GroupCacheAccess<MethodCacheKey, Object> groupCache; @@ -195,7 +195,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected T getOMInstance(final ObjectKey id) + protected T getOMInstance(final ObjectKey<?> id) throws TorqueException { return getOMInstance(id, true); @@ -210,7 +210,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected T getOMInstance(final ObjectKey key, final boolean fromCache) + protected T getOMInstance(final ObjectKey<?> key, final boolean fromCache) throws TorqueException { T om = null; @@ -237,7 +237,7 @@ implements Serializable * @param key the primary key of the object * @return the object from cache */ - protected T cacheGet(final ObjectKey key) + protected T cacheGet(final ObjectKey<?> key) { T om = null; if (cache != null) @@ -301,7 +301,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected T removeInstanceImpl(final ObjectKey key) + protected T removeInstanceImpl(final ObjectKey<?> key) throws TorqueException { T oldOm = null; @@ -325,7 +325,7 @@ implements Serializable protected T putInstanceImpl(final T om) throws TorqueException { - ObjectKey key = om.getPrimaryKey(); + ObjectKey<?> key = om.getPrimaryKey(); return putInstanceImpl(key, om); } @@ -339,7 +339,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected T putInstanceImpl(final ObjectKey key, final T om) + protected T putInstanceImpl(final ObjectKey<?> key, final T om) throws TorqueException { if (getOMClass() != null && !getOMClass().isInstance(om)) @@ -366,7 +366,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected abstract T retrieveStoredOM(ObjectKey id) + protected abstract T retrieveStoredOM(ObjectKey<?> id) throws TorqueException; /** @@ -377,7 +377,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected List<T> getOMs(final ObjectKey ...ids) + protected List<T> getOMs(final ObjectKey<?> ...ids) throws TorqueException { return getOMs(Arrays.asList(ids)); @@ -391,7 +391,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected List<T> getOMs(final List<? extends ObjectKey> ids) + protected List<T> getOMs(final List<? extends ObjectKey<?>> ids) throws TorqueException { return getOMs(ids, true); @@ -408,15 +408,15 @@ implements Serializable * rethrown wrapped into a TorqueException. */ protected List<T> getOMs( - final List<? extends ObjectKey> ids, + final List<? extends ObjectKey<?>> ids, final boolean fromCache) throws TorqueException { if (ids != null && ids.size() > 0) { // start a new list where we will replace the id's with om's - Map<ObjectKey, T> omsMap = new HashMap<>(); - List<ObjectKey> newIds = new ArrayList<>(ids); + Map<ObjectKey<?>, T> omsMap = new HashMap<>(); + List<ObjectKey<?>> newIds = new ArrayList<>(ids); if (fromCache) { @@ -458,7 +458,7 @@ implements Serializable * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - protected abstract List<T> retrieveStoredOMs(List<? extends ObjectKey> ids) + protected abstract List<T> retrieveStoredOMs(List<? extends ObjectKey<?>> ids) throws TorqueException; /** Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/BooleanKey.java Thu Dec 20 12:33:43 2018 @@ -29,7 +29,7 @@ import java.sql.Types; * @author <a href="mailto:jmcna...@apache.org">John McNally</a> * @version $Id$ */ -public class BooleanKey extends SimpleKey +public class BooleanKey extends SimpleKey<Boolean> { /** * Serial version @@ -37,97 +37,64 @@ public class BooleanKey extends SimpleKe private static final long serialVersionUID = 5109588772086713341L; /** - * Creates an SimpleKey whose internal representation will be - * set later, through a set method + * Initializes the internal key value to <code>null</code>. */ public BooleanKey() { - // empty + super(); } /** - * Creates a BooleanKey whose internal representation is a Boolean + * Creates an BooleanKey and set its internal representation * - * @param key the key value + * @param key the key value as String */ - public BooleanKey(Boolean key) + public BooleanKey(String key) { - this.key = key; + super(); + setValue(key); } /** - * Creates a BooleanKey that is equivalent to key. + * Creates an BooleanKey and set its internal representation * * @param key the key value */ - public BooleanKey(BooleanKey key) - { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; - } - } - - /** - * Sets the internal representation to a String. - * - * @param key the key value - */ - @Override - public void setValue(String key) + public BooleanKey(Boolean key) { - if (key == null) - { - this.key = null; - } - else - { - this.key = Boolean.parseBoolean(key); - } + super(); + setValue(key); } /** - * Sets the internal representation to a Boolean. + * Creates a BooleanKey that is equivalent to key. * * @param key the key value */ - public void setValue(Boolean key) + public BooleanKey(BooleanKey key) { - this.key = key; + super(); + setValue(key); } /** - * Sets the internal representation to the same object used by key. + * Sets the internal representation to a String. * * @param key the key value */ - public void setValue(BooleanKey key) + public void setValue(String key) { - if (key != null) + if (key == null) { - this.key = key.getValue(); + setValue((Boolean)null); } else { - this.key = null; + setValue(Boolean.parseBoolean(key)); } } /** - * Access the underlying Boolean object. - * - * @return a <code>Boolean</code> value - */ - public Boolean getBoolean() - { - return (Boolean) key; - } - - /** * Returns the JDBC type of the key * as defined in <code>java.sql.Types</code>. * @@ -138,20 +105,4 @@ public class BooleanKey extends SimpleKe { return Types.BIT; } - - /** - * Get a String representation of this key. - * - * @return a String representation of this key, - * or an empty String if the value is null. - */ - @Override - public String toString() - { - if (key != null) - { - return key.toString(); - } - return ""; - } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ComboKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ComboKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ComboKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ComboKey.java Thu Dec 20 12:33:43 2018 @@ -35,7 +35,7 @@ import org.apache.commons.lang.ObjectUti * @author <a href="mailto:drf...@cox.net">J. Russell Smyth</a> * @version $Id$ */ -public class ComboKey extends ObjectKey +public class ComboKey extends ObjectKey<SimpleKey<?>[]> { /** * Serial version @@ -50,48 +50,45 @@ public class ComboKey extends ObjectKey /** The single character used to separate key values in a string. */ public static final String SEPARATOR_STRING = ":"; - /** The array of the keys */ - private SimpleKey[] key; - /** - * Creates an ComboKey whose internal representation will be - * set later, through a set method + * Initializes the internal key value to <code>null</code>. */ public ComboKey() { - // empty + super(); } /** - * Creates a ComboKey whose internal representation is an - * array of SimpleKeys. + * Creates an ComboKey and set its internal representation * - * @param keys the key values + * @param key the key value as String */ - public ComboKey(SimpleKey[] keys) + public ComboKey(String key) { - setValue(keys); + super(); + setValue(key); } /** - * Sets the internal representation to a String array. + * Creates an ComboKey and set its internal representation * - * @param keys the key values - * @see #toString() + * @param key the key value */ - public ComboKey(String keys) + public ComboKey(SimpleKey<?>[] key) { - setValue(keys); + super(); + setValue(key); } /** - * Sets the internal representation using a SimpleKey array. + * Creates a ComboKey that is equivalent to key. * - * @param keys the key values + * @param key the key value */ - public void setValue(SimpleKey[] keys) + public ComboKey(ComboKey key) { - this.key = keys; + super(); + setValue(key); } /** @@ -100,12 +97,11 @@ public class ComboKey extends ObjectKey * * @param keys the key values */ - @Override public void setValue(String keys) { int startPtr = 0; int indexOfSep = keys.indexOf(SEPARATOR); - List<SimpleKey> tmpKeys = new ArrayList<>(); + List<SimpleKey<?>> tmpKeys = new ArrayList<>(); while (indexOfSep != -1) { if (indexOfSep == startPtr) @@ -117,7 +113,7 @@ public class ComboKey extends ObjectKey char keyType = keys.charAt(startPtr); String keyString = keys.substring(startPtr + 1, indexOfSep); - SimpleKey newKey = null; + SimpleKey<?> newKey = null; switch(keyType) { case 'N': @@ -145,32 +141,13 @@ public class ComboKey extends ObjectKey indexOfSep = keys.indexOf(SEPARATOR, startPtr); } - this.key = new SimpleKey[tmpKeys.size()]; - for (int i = 0; i < this.key.length; i++) + SimpleKey<?>[] key = new SimpleKey[tmpKeys.size()]; + for (int i = 0; i < key.length; i++) { - this.key[i] = tmpKeys.get(i); + key[i] = tmpKeys.get(i); } - } - - /** - * Sets the internal representation using a ComboKey. - * - * @param keys the key values - */ - public void setValue(ComboKey keys) - { - setValue((SimpleKey[]) keys.getValue()); - } - - /** - * Get the underlying object. - * - * @return the underlying object - */ - @Override - public Object getValue() - { - return key; + + setValue(key); } /** @@ -196,15 +173,15 @@ public class ComboKey extends ObjectKey public boolean equals(Object keyObj) { boolean isEqual = false; + SimpleKey<?>[] key = getValue(); if (key != null) { // check that all keys are not null isEqual = true; - SimpleKey[] keys = key; - for (int i = 0; i < keys.length && isEqual; i++) + for (int i = 0; i < key.length && isEqual; i++) { - isEqual &= keys[i] != null && keys[i].getValue() != null; + isEqual &= key[i] != null && key[i].getValue() != null; } isEqual &= looseEquals(keyObj); @@ -234,6 +211,7 @@ public class ComboKey extends ObjectKey public boolean looseEquals(Object keyObj) { boolean isEqual = false; + SimpleKey<?>[] key = getValue(); if (key != null) { @@ -249,25 +227,23 @@ public class ComboKey extends ObjectKey // internal keys equivalent. else if (keyObj instanceof ComboKey) { - SimpleKey[] obj = (SimpleKey[]) + SimpleKey<?>[] obj = (SimpleKey[]) ((ComboKey) keyObj).getValue(); - SimpleKey[] keys1 = key; - SimpleKey[] keys2 = obj; - isEqual = keys1.length == keys2.length; - for (int i = 0; i < keys1.length && isEqual; i++) + SimpleKey<?>[] keys2 = obj; + isEqual = key.length == keys2.length; + for (int i = 0; i < key.length && isEqual; i++) { - isEqual &= ObjectUtils.equals(keys1[i], keys2[i]); + isEqual &= ObjectUtils.equals(key[i], keys2[i]); } } else if (keyObj instanceof SimpleKey[]) { - SimpleKey[] keys1 = key; - SimpleKey[] keys2 = (SimpleKey[]) keyObj; - isEqual = keys1.length == keys2.length; - for (int i = 0; i < keys1.length && isEqual; i++) + SimpleKey<?>[] keys2 = (SimpleKey[]) keyObj; + isEqual = key.length == keys2.length; + for (int i = 0; i < key.length && isEqual; i++) { - isEqual &= ObjectUtils.equals(keys1[i], keys2[i]); + isEqual &= ObjectUtils.equals(key[i], keys2[i]); } } } @@ -282,22 +258,22 @@ public class ComboKey extends ObjectKey @Override public void appendTo(StringBuilder sb) { + SimpleKey<?>[] key = getValue(); if (key != null) { - SimpleKey[] keys = key; - for (int i = 0; i < keys.length; i++) + for (int i = 0; i < key.length; i++) { - if (keys[i] != null) + if (key[i] != null) { - if (keys[i] instanceof StringKey) + if (key[i] instanceof StringKey) { sb.append("S"); } - else if (keys[i] instanceof NumberKey) + else if (key[i] instanceof NumberKey) { sb.append("N"); } - else if (keys[i] instanceof DateKey) + else if (key[i] instanceof DateKey) { sb.append("D"); } @@ -306,7 +282,7 @@ public class ComboKey extends ObjectKey // unknown type sb.append("U"); } - keys[i].appendTo(sb); + key[i].appendTo(sb); } // MUST BE ADDED AFTER EACH KEY, IN CASE OF NULL KEY! sb.append(SEPARATOR); @@ -324,12 +300,13 @@ public class ComboKey extends ObjectKey @Override public int hashCode() { + SimpleKey<?>[] key = getValue(); if (key == null) { return super.hashCode(); } - SimpleKey sk = key[0]; + SimpleKey<?> sk = key[0]; if (sk == null) { return super.hashCode(); Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/DateKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/DateKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/DateKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/DateKey.java Thu Dec 20 12:33:43 2018 @@ -29,7 +29,7 @@ import java.util.Date; * @author <a href="mailto:jmcna...@apache.org">John McNally</a> * @version $Id$ */ -public class DateKey extends SimpleKey +public class DateKey extends SimpleKey<Date> { /** * Serial version @@ -37,41 +37,33 @@ public class DateKey extends SimpleKey private static final long serialVersionUID = 3102583536685348517L; /** - * Creates an DateKey whose internal representation will be - * set later, through a set method + * Initializes the internal key value to <code>null</code>. */ public DateKey() { - // empty + super(); } /** - * Creates a DateKey whose internal representation is a Date - * given by the long number given by the String + * Creates an DateKey and set its internal representation * - * @param key the key value - * @throws NumberFormatException if key is not valid + * @param key the key value as String */ public DateKey(String key) { - if (key != null) - { - this.key = new Date(Long.parseLong(key)); - } - else - { - this.key = null; - } + super(); + setValue(key); } /** - * Creates a DateKey + * Creates an DateKey and set its internal representation * * @param key the key value */ public DateKey(Date key) { - this.key = key; + super(); + setValue(key); } /** @@ -81,14 +73,8 @@ public class DateKey extends SimpleKey */ public DateKey(DateKey key) { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; - } + super(); + setValue(key); } /** @@ -96,33 +82,15 @@ public class DateKey extends SimpleKey * * @param key the key value */ - @Override public void setValue(String key) { if (key != null) { - this.key = new Date(Long.parseLong(key)); + setValue(new Date(Long.parseLong(key))); } else { - this.key = null; - } - } - - /** - * Sets the internal representation to the same object used by key. - * - * @param key the key value - */ - public void setValue(DateKey key) - { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; + setValue((Date)null); } } @@ -139,16 +107,6 @@ public class DateKey extends SimpleKey } /** - * Access the underlying Date object. - * - * @return a <code>Date</code> value - */ - public Date getDate() - { - return (Date) key; - } - - /** * Get a String representation for this key. * * @return a String representation of the Date or an empty String if the @@ -157,7 +115,7 @@ public class DateKey extends SimpleKey @Override public String toString() { - Date dt = getDate(); + Date dt = getValue(); return (dt == null ? "" : Long.toString(dt.getTime())); } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/NumberKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/NumberKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/NumberKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/NumberKey.java Thu Dec 20 12:33:43 2018 @@ -32,7 +32,7 @@ import java.sql.Types; * @author <a href="mailto:r...@onepercentsoftware.com">Runako Godfrey</a> * @version $Id$ */ -public class NumberKey extends SimpleKey +public class NumberKey extends SimpleKey<BigDecimal> { /** * Serial version @@ -40,56 +40,44 @@ public class NumberKey extends SimpleKey private static final long serialVersionUID = -5566819786708264162L; /** - * Creates a NumberKey whose internal representation will be - * set later, through a set method + * Initializes the internal key value to <code>null</code>. */ public NumberKey() { - // empty + super(); } /** - * Creates a NumberKey equivalent to <code>key</code>. + * Creates an NumberKey and set its internal representation * - * @param key the key value + * @param key the key value as String */ public NumberKey(String key) { - if (key != null) - { - this.key = new BigDecimal(key); - } - else - { - this.key = null; - } + super(); + setValue(key); } /** - * Creates a NumberKey equivalent to <code>key</code>. + * Creates an NumberKey and set its internal representation * * @param key the key value */ public NumberKey(BigDecimal key) { - this.key = key; + super(); + setValue(key); } /** - * Creates a NumberKey equivalent to <code>key</code>. + * Creates a NumberKey that is equivalent to key. * * @param key the key value */ public NumberKey(NumberKey key) { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; - } + super(); + setValue(key); } /** @@ -99,7 +87,7 @@ public class NumberKey extends SimpleKey */ public NumberKey(long key) { - this.key = BigDecimal.valueOf(key); + setValue(BigDecimal.valueOf(key)); } /** @@ -109,7 +97,7 @@ public class NumberKey extends SimpleKey */ public NumberKey(double key) { - this.key = new BigDecimal(key); + setValue(new BigDecimal(key)); } /** @@ -133,11 +121,11 @@ public class NumberKey extends SimpleKey { if (key != null) { - this.key = new BigDecimal(key.toString()); + setValue(new BigDecimal(key.toString())); } else { - this.key = null; + setValue((BigDecimal)null); } } @@ -148,40 +136,19 @@ public class NumberKey extends SimpleKey * @param key the key value * @throws NumberFormatException if key is not a valid number */ - @Override public void setValue(String key) { if (key != null) { - this.key = new BigDecimal(key); + setValue(new BigDecimal(key)); } else { - this.key = null; + setValue((BigDecimal)null); } } /** - * Sets the underlying object. - * - * @param key the key value. - */ - public void setValue(BigDecimal key) - { - this.key = key; - } - - /** - * Sets the internal representation to the same object used by key. - * - * @param key the key value - */ - public void setValue(NumberKey key) - { - this.key = (key == null ? null : key.getValue()); - } - - /** * Returns the JDBC type of the key * as defined in <code>java.sql.Types</code>. * @@ -194,55 +161,13 @@ public class NumberKey extends SimpleKey } /** - * Access the underlying BigDecimal object. - * - * @return a <code>BigDecimal</code> value - */ - public BigDecimal getBigDecimal() - { - return (BigDecimal) key; - } - - /** - * @return a hash code based on the value - */ - @Override - public int hashCode() - { - if (getValue() == null) - { - return super.hashCode(); - } - else - { - return getValue().hashCode(); - } - } - - /** * @param o the comparison value * @return a numeric comparison of the two values */ @Override public int compareTo(Object o) { - return getBigDecimal().compareTo(((NumberKey) o).getBigDecimal()); - } - - /** - * Get a String representation of this key. - * - * @return a String representation of this key, - * or an empty String if the value is null. - */ - @Override - public String toString() - { - if (key != null) - { - return key.toString(); - } - return ""; + return getValue().compareTo(((NumberKey) o).getValue()); } /** @@ -254,7 +179,7 @@ public class NumberKey extends SimpleKey */ public byte byteValue() { - return getBigDecimal().byteValue(); + return getValue().byteValue(); } /** @@ -271,7 +196,7 @@ public class NumberKey extends SimpleKey */ public int intValue() { - return getBigDecimal().intValue(); + return getValue().intValue(); } /** @@ -288,7 +213,7 @@ public class NumberKey extends SimpleKey */ public short shortValue() { - return getBigDecimal().shortValue(); + return getValue().shortValue(); } /** @@ -300,7 +225,7 @@ public class NumberKey extends SimpleKey */ public long longValue() { - return getBigDecimal().longValue(); + return getValue().longValue(); } /** @@ -315,7 +240,7 @@ public class NumberKey extends SimpleKey */ public float floatValue() { - return getBigDecimal().floatValue(); + return getValue().floatValue(); } /** @@ -330,6 +255,6 @@ public class NumberKey extends SimpleKey */ public double doubleValue() { - return getBigDecimal().doubleValue(); + return getValue().doubleValue(); } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectKey.java Thu Dec 20 12:33:43 2018 @@ -20,19 +20,18 @@ package org.apache.torque.om; */ import java.io.Serializable; - -import org.apache.torque.TorqueException; +import java.util.Objects; /** * This class can be used to uniquely identify an object within * an application. There are four subclasses: StringKey, NumberKey, * and DateKey, and ComboKey which is a Key made up of a combination - * ofthe first three. + * of the first three. * * @author <a href="mailto:jmcna...@apache.org">John McNally</a> * @version $Id$ */ -public abstract class ObjectKey implements Serializable, Comparable<Object> +public abstract class ObjectKey<T> implements Serializable, Comparable<Object> { /** Version id for serializing. */ private static final long serialVersionUID = 1L; @@ -40,12 +39,12 @@ public abstract class ObjectKey implemen /** * The underlying key value. */ - protected Object key; + private T key; /** * Initializes the internal key value to <code>null</code>. */ - protected ObjectKey() + public ObjectKey() { key = null; } @@ -93,7 +92,7 @@ public abstract class ObjectKey implemen return false; } - ObjectKey objectKey = (ObjectKey) obj; + ObjectKey<?> objectKey = (ObjectKey<?>) obj; if (key == null) { return false; @@ -106,7 +105,7 @@ public abstract class ObjectKey implemen * * @return the underlying object */ - public Object getValue() + public T getValue() { return key; } @@ -119,6 +118,14 @@ public abstract class ObjectKey implemen */ public abstract int getJdbcType(); +// /** +// * Returns the JDBC type of the key +// * as defined in <code>java.sql.Types</code>. +// * +// * @return the JDBC type of the key. +// */ +// public abstract JDBCType getJdbcType(); + /** * Appends a String representation of the key to a buffer. * @@ -142,10 +149,41 @@ public abstract class ObjectKey implemen } /** - * Reset the underlying object using a String. + * Sets the internal representation. * - * @param s a <code>String</code> value - * @exception TorqueException if an error occurs + * @param key the key value */ - public abstract void setValue(String s) throws TorqueException; + public void setValue(T key) + { + this.key = key; + } + + /** + * Sets the internal representation to the same object used by key. + * + * @param key the key value + */ + public <O extends ObjectKey<T>> void setValue(O key) + { + if (key != null) + { + this.key = key.getValue(); + } + else + { + this.key = null; + } + } + + /** + * Get a String representation of this key. + * + * @return a String representation of this key, + * or an empty String if the value is null. + */ + @Override + public String toString() + { + return Objects.toString(key, ""); + } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectModel.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectModel.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectModel.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/ObjectModel.java Thu Dec 20 12:33:43 2018 @@ -34,7 +34,7 @@ public interface ObjectModel * * @return the object primaryKey as an Object */ - ObjectKey getPrimaryKey(); + ObjectKey<?> getPrimaryKey(); /** * Sets the PrimaryKey for the object. @@ -42,7 +42,7 @@ public interface ObjectModel * @param primaryKey The new PrimaryKey for the object. * @throws TorqueException This method might throw an exception */ - void setPrimaryKey(ObjectKey primaryKey) throws TorqueException; + void setPrimaryKey(ObjectKey<?> primaryKey) throws TorqueException; /** * Sets the PrimaryKey for the object. Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/SimpleKey.java Thu Dec 20 12:33:43 2018 @@ -27,7 +27,7 @@ package org.apache.torque.om; * @author <a href="mailto:drf...@cox.net">J. Russell Smyth</a> * @version $Id$ */ -public abstract class SimpleKey extends ObjectKey +public abstract class SimpleKey<T> extends ObjectKey<T> { /** Version id for serializing. */ private static final long serialVersionUID = 1L; Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/StringKey.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/StringKey.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/StringKey.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/om/StringKey.java Thu Dec 20 12:33:43 2018 @@ -29,7 +29,7 @@ import java.sql.Types; * @author <a href="mailto:jmcna...@apache.org">John McNally</a> * @version $Id$ */ -public class StringKey extends SimpleKey +public class StringKey extends SimpleKey<String> { /** * Serial version @@ -37,22 +37,22 @@ public class StringKey extends SimpleKey private static final long serialVersionUID = 5109588772086713341L; /** - * Creates an SimpleKey whose internal representation will be - * set later, through a set method + * Initializes the internal key value to <code>null</code>. */ public StringKey() { - // empty + super(); } /** - * Creates a StringKey whose internal representation is a String + * Creates an StringKey and set its internal representation * - * @param key the key value + * @param key the key value as String */ public StringKey(String key) { - this.key = key; + super(); + setValue(key); } /** @@ -62,52 +62,8 @@ public class StringKey extends SimpleKey */ public StringKey(StringKey key) { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; - } - } - - /** - * Sets the internal representation to a String - * - * @param key the key value - */ - @Override - public void setValue(String key) - { - this.key = key; - } - - /** - * Sets the internal representation to the same object used by key. - * - * @param key the key value - */ - public void setValue(StringKey key) - { - if (key != null) - { - this.key = key.getValue(); - } - else - { - this.key = null; - } - } - - /** - * Access the underlying String object. - * - * @return a <code>String</code> value - */ - public String getString() - { - return (String) key; + super(); + setValue(key); } /** @@ -121,20 +77,4 @@ public class StringKey extends SimpleKey { return Types.VARCHAR; } - - /** - * Get a String representation of this key. - * - * @return a String representation of this key, - * or an empty String if the value is null. - */ - @Override - public String toString() - { - if (key != null) - { - return (String) key; - } - return ""; - } } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/objectbuilder/ObjectOrColumnPsPartBuilder.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/objectbuilder/ObjectOrColumnPsPartBuilder.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/objectbuilder/ObjectOrColumnPsPartBuilder.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/objectbuilder/ObjectOrColumnPsPartBuilder.java Thu Dec 20 12:33:43 2018 @@ -93,7 +93,7 @@ public class ObjectOrColumnPsPartBuilder // If rValue is an ObjectKey, take the value of that ObjectKey. if (toBuildFrom instanceof ObjectKey) { - toBuildFrom = ((ObjectKey) toBuildFrom).getValue(); + toBuildFrom = ((ObjectKey<?>) toBuildFrom).getValue(); } // handle ignoreCase Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java Thu Dec 20 12:33:43 2018 @@ -127,7 +127,7 @@ public class NullValueBuilder extends Ab Object rValue = whereClauseExpression.getRValue(); if (rValue != null && (!(rValue instanceof ObjectKey) - || ((ObjectKey) rValue).getValue() != null)) + || ((ObjectKey<?>) rValue).getValue() != null)) { return false; } Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java Thu Dec 20 12:33:43 2018 @@ -89,7 +89,7 @@ public abstract class AbstractPeerImpl<T * * @param pk the primary key value to build the criteria from, not null. */ - public Criteria buildCriteria(ObjectKey pk) + public Criteria buildCriteria(ObjectKey<?> pk) { throw new RuntimeException("buildCriteria(ObjectKey) called on table without primary key"); } @@ -160,7 +160,7 @@ public abstract class AbstractPeerImpl<T * rethrown wrapped into a TorqueException. */ @Override - public ObjectKey doInsert(ColumnValues columnValues, Connection con) + public ObjectKey<?> doInsert(ColumnValues columnValues, Connection con) throws TorqueException { correctBooleans(columnValues); @@ -175,7 +175,7 @@ public abstract class AbstractPeerImpl<T */ public void doInsert(T obj) throws TorqueException { - ObjectKey primaryKey = doInsert(buildColumnValues(obj)); + ObjectKey<?> primaryKey = doInsert(buildColumnValues(obj)); if (primaryKey != null) { obj.setPrimaryKey(primaryKey); @@ -197,7 +197,7 @@ public abstract class AbstractPeerImpl<T public void doInsert(T obj, Connection con) throws TorqueException { - ObjectKey primaryKey = doInsert(buildColumnValues(obj), con); + ObjectKey<?> primaryKey = doInsert(buildColumnValues(obj), con); if (primaryKey != null) { obj.setPrimaryKey(primaryKey); @@ -258,7 +258,7 @@ public abstract class AbstractPeerImpl<T * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - public int doDelete(ObjectKey pk) throws TorqueException + public int doDelete(ObjectKey<?> pk) throws TorqueException { try (TorqueConnection connection = Transaction.begin(getDatabaseName())) { @@ -281,7 +281,7 @@ public abstract class AbstractPeerImpl<T * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ - public int doDelete(ObjectKey pk, Connection con) + public int doDelete(ObjectKey<?> pk, Connection con) throws TorqueException { return doDelete(buildCriteria(pk), con); Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Thu Dec 20 12:33:43 2018 @@ -318,7 +318,7 @@ public class BasePeerImpl<T> implements * * @throws TorqueException if a database error occurs. */ - public ObjectKey doInsert(final ColumnValues insertValues) + public ObjectKey<?> doInsert(final ColumnValues insertValues) throws TorqueException { String databaseNameFromInsertValues = insertValues.getDbName(); @@ -328,7 +328,7 @@ public class BasePeerImpl<T> implements } try (TorqueConnection connection = Transaction.begin(databaseNameFromInsertValues)) { - ObjectKey id = doInsert(insertValues, connection); + ObjectKey<?> id = doInsert(insertValues, connection); Transaction.commit(connection); return id; } @@ -356,7 +356,7 @@ public class BasePeerImpl<T> implements * * @throws TorqueException if a database error occurs. */ - public ObjectKey doInsert( + public ObjectKey<?> doInsert( final ColumnValues insertValues, final Connection connection) throws TorqueException @@ -379,7 +379,7 @@ public class BasePeerImpl<T> implements IdGenerator keyGen = database.getIdGenerator( getTableMap().getPrimaryKeyMethod()); - SimpleKey id = null; + SimpleKey<?> id = null; // can currently generate only single column pks, therefore a single // columnMap is ok ColumnMap primaryKey = null; @@ -735,14 +735,14 @@ public class BasePeerImpl<T> implements * @return A simple Key representing the new Id value * @throws TorqueException Possible errors get wrapped in here. */ - private SimpleKey getId( + private SimpleKey<?> getId( final ColumnMap pk, final IdGenerator keyGen, final Connection con, final Object keyInfo) throws TorqueException { - SimpleKey id = null; + SimpleKey<?> id = null; if (pk != null && keyGen != null) { @@ -1783,7 +1783,7 @@ public class BasePeerImpl<T> implements } else if (param instanceof NumberKey) { - BigDecimal bigDecimal = ((NumberKey) param).getBigDecimal(); + BigDecimal bigDecimal = ((NumberKey) param).getValue(); statement.setBigDecimal(i, bigDecimal); result.add(bigDecimal); } Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/AbstractBaseManagerTest.java Thu Dec 20 12:33:43 2018 @@ -45,7 +45,7 @@ import org.junit.Test; public class AbstractBaseManagerTest implements CacheListener<TestPersistent> { - private static final ObjectKey TEST_PRIMARY_KEY = SimpleKey.keyFor("testID"); + private static final ObjectKey<?> TEST_PRIMARY_KEY = SimpleKey.keyFor("testID"); private static final String CACHE_REGION = "testCache1"; private TestManager manager; Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestManager.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestManager.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestManager.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestManager.java Thu Dec 20 12:33:43 2018 @@ -35,7 +35,7 @@ public class TestManager extends Abstrac private static final long serialVersionUID = 1021912588603493352L; @Override - protected TestPersistent retrieveStoredOM(ObjectKey id) + protected TestPersistent retrieveStoredOM(ObjectKey<?> id) throws TorqueException { TestPersistent test = new TestPersistent(); @@ -45,11 +45,11 @@ public class TestManager extends Abstrac @Override protected List<TestPersistent> retrieveStoredOMs( - List<? extends ObjectKey> ids) throws TorqueException + List<? extends ObjectKey<?>> ids) throws TorqueException { List<TestPersistent> testList = new ArrayList<>(ids.size()); - for (ObjectKey id : ids) + for (ObjectKey<?> id : ids) { testList.add(retrieveStoredOM(id)); } Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestPersistent.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestPersistent.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestPersistent.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/manager/TestPersistent.java Thu Dec 20 12:33:43 2018 @@ -36,7 +36,7 @@ public class TestPersistent implements P /** Serial ID */ private static final long serialVersionUID = 738162496580951932L; - private ObjectKey primaryKey; + private ObjectKey<?> primaryKey; private boolean isNew = true; private boolean modified; @@ -44,7 +44,7 @@ public class TestPersistent implements P * @see org.apache.torque.om.Persistent#getPrimaryKey() */ @Override - public ObjectKey getPrimaryKey() + public ObjectKey<?> getPrimaryKey() { return primaryKey; } @@ -53,7 +53,7 @@ public class TestPersistent implements P * @see org.apache.torque.om.Persistent#setPrimaryKey(org.apache.torque.om.ObjectKey) */ @Override - public void setPrimaryKey(ObjectKey primaryKey) throws TorqueException + public void setPrimaryKey(ObjectKey<?> primaryKey) throws TorqueException { this.primaryKey = primaryKey; } Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java?rev=1849379&r1=1849378&r2=1849379&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/BasePeerImplTest.java Thu Dec 20 12:33:43 2018 @@ -375,7 +375,7 @@ public class BasePeerImplTest extends Ba insertValues.put(integerColumnMap, new JdbcTypedValue(42, Types.INTEGER)); // execute - ObjectKey result = basePeerImpl.doInsert(insertValues); + ObjectKey<?> result = basePeerImpl.doInsert(insertValues); // verify mock (verification order not relevant) verify(connection).prepareStatement( @@ -499,7 +499,7 @@ public class BasePeerImplTest extends Ba insertValues.put(stringColumnMap, new JdbcTypedValue("value", Types.VARCHAR)); // execute - ObjectKey result = basePeerImpl.doInsert(insertValues); + ObjectKey<?> result = basePeerImpl.doInsert(insertValues); // verify mock (verification order not relevant) verify(connection).prepareStatement( --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org