From 8f2cf98c17c9d1811f8b364307ee1d299e548de1 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 30 Jul 2008 13:53:24 +0000 Subject: [PATCH] Le metric crapload of generics cleanup. --- .../samskivert/jdbc/depot/BindVisitor.java | 15 +++---- .../samskivert/jdbc/depot/BuildVisitor.java | 20 ++++----- .../jdbc/depot/DepotMarshaller.java | 38 ++++++++--------- .../jdbc/depot/DepotRepository.java | 42 ++++++++++--------- .../com/samskivert/jdbc/depot/DepotTypes.java | 9 ++-- .../jdbc/depot/EntityMigration.java | 6 +-- .../jdbc/depot/FieldMarshaller.java | 4 +- .../samskivert/jdbc/depot/FindAllQuery.java | 2 +- .../jdbc/depot/IdentityValueGenerator.java | 2 +- src/java/com/samskivert/jdbc/depot/Key.java | 31 +++++++------- .../com/samskivert/jdbc/depot/MultiKey.java | 25 +++++------ .../samskivert/jdbc/depot/MySQLBuilder.java | 2 +- .../jdbc/depot/PersistenceContext.java | 10 ++--- .../jdbc/depot/PostgreSQLBuilder.java | 2 +- .../com/samskivert/jdbc/depot/SQLBuilder.java | 4 +- .../samskivert/jdbc/depot/SimpleCacheKey.java | 2 +- .../jdbc/depot/TableValueGenerator.java | 3 +- .../samskivert/jdbc/depot/ValueGenerator.java | 10 ++--- .../samskivert/jdbc/depot/clause/Where.java | 22 +++++----- .../depot/expression/ExpressionVisitor.java | 2 +- .../jdbc/depot/operator/Arithmetic.java | 12 +++--- .../jdbc/depot/operator/Conditionals.java | 30 ++++++------- .../jdbc/depot/operator/SQLOperator.java | 2 +- .../jdbc/depot/tools/GenRecordTask.java | 2 +- 24 files changed, 152 insertions(+), 145 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/BindVisitor.java b/src/java/com/samskivert/jdbc/depot/BindVisitor.java index eab550a..3d2b290 100644 --- a/src/java/com/samskivert/jdbc/depot/BindVisitor.java +++ b/src/java/com/samskivert/jdbc/depot/BindVisitor.java @@ -73,14 +73,14 @@ public class BindVisitor implements ExpressionVisitor public void visit (WhereCondition whereCondition) throws Exception { - for (Comparable value : whereCondition.getValues()) { + for (Comparable value : whereCondition.getValues()) { if (value != null) { _stmt.setObject(_argIdx ++, value); } } } - public void visit (Key key) + public void visit (Key key) throws Exception { key.condition.accept(this); @@ -89,12 +89,13 @@ public class BindVisitor implements ExpressionVisitor public void visit (MultiKey key) throws Exception { - for (Map.Entry entry : key.getSingleFieldsMap().entrySet()) { + + for (Map.Entry> entry : key.getSingleFieldsMap().entrySet()) { if (entry.getValue() != null) { _stmt.setObject(_argIdx ++, entry.getValue()); } } - Comparable[] values = key.getMultiValues(); + Comparable[] values = key.getMultiValues(); for (int ii = 0; ii < values.length; ii++) { _stmt.setObject(_argIdx ++, values[ii]); } @@ -130,7 +131,7 @@ public class BindVisitor implements ExpressionVisitor public void visit (In in) throws Exception { - Comparable[] values = in.getValues(); + Comparable[] values = in.getValues(); for (int ii = 0; ii < values.length; ii++) { _stmt.setObject(_argIdx ++, values[ii]); } @@ -229,7 +230,7 @@ public class BindVisitor implements ExpressionVisitor public void visit (UpdateClause updateClause) throws Exception { - DepotMarshaller marsh = _types.getMarshaller(updateClause.getPersistentClass()); + DepotMarshaller marsh = _types.getMarshaller(updateClause.getPersistentClass()); // bind the update arguments String[] fields = updateClause.getFields(); @@ -251,7 +252,7 @@ public class BindVisitor implements ExpressionVisitor public void visit (InsertClause insertClause) throws Exception { - DepotMarshaller marsh = _types.getMarshaller(insertClause.getPersistentClass()); + DepotMarshaller marsh = _types.getMarshaller(insertClause.getPersistentClass()); Object pojo = insertClause.getPojo(); Set idFields = insertClause.getIdentityFields(); diff --git a/src/java/com/samskivert/jdbc/depot/BuildVisitor.java b/src/java/com/samskivert/jdbc/depot/BuildVisitor.java index 8344499..7816c9b 100644 --- a/src/java/com/samskivert/jdbc/depot/BuildVisitor.java +++ b/src/java/com/samskivert/jdbc/depot/BuildVisitor.java @@ -98,7 +98,7 @@ public abstract class BuildVisitor implements ExpressionVisitor { Class pClass = whereCondition.getPersistentClass(); String[] keyFields = Key.getKeyFields(pClass); - List values = whereCondition.getValues(); + List> values = whereCondition.getValues(); for (int ii = 0; ii < keyFields.length; ii ++) { if (ii > 0) { _builder.append(" and "); @@ -113,7 +113,7 @@ public abstract class BuildVisitor implements ExpressionVisitor } } - public void visit (Key key) + public void visit (Key key) throws Exception { _builder.append(" where "); @@ -125,7 +125,7 @@ public abstract class BuildVisitor implements ExpressionVisitor { _builder.append(" where "); boolean first = true; - for (Map.Entry entry : key.getSingleFieldsMap().entrySet()) { + for (Map.Entry> entry : key.getSingleFieldsMap().entrySet()) { if (first) { first = false; } else { @@ -145,7 +145,7 @@ public abstract class BuildVisitor implements ExpressionVisitor appendRhsColumn(key.getPersistentClass(), key.getMultiField()); _builder.append(" in ("); - Comparable[] values = key.getMultiValues(); + Comparable[] values = key.getMultiValues(); for (int ii = 0; ii < values.length; ii ++) { if (ii > 0) { _builder.append(", "); @@ -206,7 +206,7 @@ public abstract class BuildVisitor implements ExpressionVisitor { in.getColumn().accept(this); _builder.append(" in ("); - Comparable[] values = in.getValues(); + Comparable[] values = in.getValues(); for (int ii = 0; ii < values.length; ii ++) { if (ii > 0) { _builder.append(", "); @@ -465,7 +465,7 @@ public abstract class BuildVisitor implements ExpressionVisitor throws Exception { Class pClass = insertClause.getPersistentClass(); - DepotMarshaller marsh = _types.getMarshaller(pClass); + DepotMarshaller marsh = _types.getMarshaller(pClass); _innerClause = true; String[] fields = marsh.getColumnFieldNames(); @@ -514,8 +514,8 @@ public abstract class BuildVisitor implements ExpressionVisitor protected void appendLhsColumn (Class type, String field) throws Exception { - DepotMarshaller dm = _types.getMarshaller(type); - FieldMarshaller fm = dm.getFieldMarshaller(field); + DepotMarshaller dm = _types.getMarshaller(type); + FieldMarshaller fm = dm.getFieldMarshaller(field); if (dm == null) { throw new IllegalArgumentException( "Unknown field on persistent record [record=" + type + ", field=" + field + "]"); @@ -529,8 +529,8 @@ public abstract class BuildVisitor implements ExpressionVisitor protected void appendRhsColumn (Class type, String field) throws Exception { - DepotMarshaller dm = _types.getMarshaller(type); - FieldMarshaller fm = dm.getFieldMarshaller(field); + DepotMarshaller dm = _types.getMarshaller(type); + FieldMarshaller fm = dm.getFieldMarshaller(field); if (dm == null) { throw new IllegalArgumentException( "Unknown field on persistent record [record=" + type + ", field=" + field + "]"); diff --git a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java index 2915bf0..7991103 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/DepotMarshaller.java @@ -120,14 +120,14 @@ public class DepotMarshaller continue; } - FieldMarshaller fm = FieldMarshaller.createMarshaller(field); + FieldMarshaller fm = FieldMarshaller.createMarshaller(field); _fields.put(field.getName(), fm); fields.add(field.getName()); // check to see if this is our primary key if (field.getAnnotation(Id.class) != null) { if (_pkColumns == null) { - _pkColumns = new ArrayList(); + _pkColumns = new ArrayList>(); } _pkColumns.add(fm); } @@ -194,7 +194,7 @@ public class DepotMarshaller String[] conFields = constraint.fieldNames(); Set colSet = new HashSet(); for (int ii = 0; ii < conFields.length; ii ++) { - FieldMarshaller fm = _fields.get(conFields[ii]); + FieldMarshaller fm = _fields.get(conFields[ii]); if (fm == null) { throw new IllegalArgumentException( "Unknown unique constraint field: " + conFields[ii]); @@ -287,7 +287,7 @@ public class DepotMarshaller /** * Returns the {@link FieldMarshaller} for a named field on our persistent class. */ - public FieldMarshaller getFieldMarshaller (String fieldName) + public FieldMarshaller getFieldMarshaller (String fieldName) { return _fields.get(fieldName); } @@ -349,11 +349,11 @@ public class DepotMarshaller } try { - Comparable[] values = new Comparable[_pkColumns.size()]; + Comparable[] values = new Comparable[_pkColumns.size()]; int nulls = 0; for (int ii = 0; ii < _pkColumns.size(); ii++) { - FieldMarshaller field = _pkColumns.get(ii); - if ((values[ii] = (Comparable)field.getField().get(object)) == null) { + FieldMarshaller field = _pkColumns.get(ii); + if ((values[ii] = (Comparable)field.getField().get(object)) == null) { nulls++; } } @@ -383,7 +383,7 @@ public class DepotMarshaller * Creates a primary key record for the type of object handled by this marshaller, using the * supplied primary key value. */ - public Key makePrimaryKey (Comparable... values) + public Key makePrimaryKey (Comparable... values) { if (!hasPrimaryKey()) { throw new UnsupportedOperationException( @@ -407,14 +407,14 @@ public class DepotMarshaller throw new UnsupportedOperationException( getClass().getName() + " does not define a primary key"); } - Comparable[] values = new Comparable[_pkColumns.size()]; + Comparable[] values = new Comparable[_pkColumns.size()]; for (int ii = 0; ii < _pkColumns.size(); ii++) { Object keyValue = _pkColumns.get(ii).getFromSet(rs); - if (!(keyValue instanceof Comparable)) { - throw new IllegalArgumentException("Key field must be Comparable [field=" + + if (!(keyValue instanceof Comparable)) { + throw new IllegalArgumentException("Key field must be Comparable [field=" + _pkColumns.get(ii).getColumnName() + "]"); } - values[ii] = (Comparable) keyValue; + values[ii] = (Comparable) keyValue; } return makePrimaryKey(values); } @@ -445,7 +445,7 @@ public class DepotMarshaller // then create and populate the persistent object T po = _pClass.newInstance(); - for (FieldMarshaller fm : _fields.values()) { + for (FieldMarshaller fm : _fields.values()) { if (!fields.contains(fm.getColumnName())) { // this field was not in the result set, make sure that's OK if (fm.getComputed() != null && !fm.getComputed().required()) { @@ -530,7 +530,7 @@ public class DepotMarshaller final SQLBuilder builder = ctx.getSQLBuilder(new DepotTypes(ctx, _pClass)); // perform the context-sensitive initialization of the field marshallers - for (FieldMarshaller fm : _fields.values()) { + for (FieldMarshaller fm : _fields.values()) { fm.init(builder); } @@ -545,7 +545,7 @@ public class DepotMarshaller ColumnDefinition[] declarations = new ColumnDefinition[_allFields.length]; int jj = 0; for (int ii = 0; ii < _allFields.length; ii++) { - FieldMarshaller fm = _fields.get(_allFields[ii]); + FieldMarshaller fm = _fields.get(_allFields[ii]); // include all persistent non-computed fields ColumnDefinition colDef = fm.getColumnDefinition(); if (colDef != null) { @@ -684,7 +684,7 @@ public class DepotMarshaller // add any missing columns for (String fname : _columnFields) { - final FieldMarshaller fmarsh = _fields.get(fname); + final FieldMarshaller fmarsh = _fields.get(fname); if (metaData.tableColumns.remove(fmarsh.getColumnName())) { continue; } @@ -873,7 +873,7 @@ public class DepotMarshaller throws PersistenceException { for (String fname : _columnFields) { - FieldMarshaller fmarsh = _fields.get(fname); + FieldMarshaller fmarsh = _fields.get(fname); meta.tableColumns.remove(fmarsh.getColumnName()); } for (String column : meta.tableColumns) { @@ -977,11 +977,11 @@ public class DepotMarshaller protected Map _valueGenerators = new HashMap(); /** A field marshaller for each persistent field in our object. */ - protected Map _fields = new HashMap(); + protected Map> _fields = new HashMap>(); /** The field marshallers for our persistent object's primary key columns or null if it did not * define a primary key. */ - protected ArrayList _pkColumns; + protected ArrayList> _pkColumns; /** The persisent fields of our object, in definition order. */ protected String[] _allFields; diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 4360542..ece90f4 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -78,7 +78,7 @@ public abstract class DepotRepository /** * Loads the persistent object that matches the specified primary key. */ - protected T load (Class type, Comparable primaryKey, + protected T load (Class type, Comparable primaryKey, QueryClause... clauses) throws PersistenceException { @@ -89,7 +89,7 @@ public abstract class DepotRepository /** * Loads the persistent object that matches the specified primary key. */ - protected T load (Class type, String ix, Comparable val, + protected T load (Class type, String ix, Comparable val, QueryClause... clauses) throws PersistenceException { @@ -100,8 +100,8 @@ public abstract class DepotRepository /** * Loads the persistent object that matches the specified two-column primary key. */ - protected T load (Class type, String ix1, Comparable val1, - String ix2, Comparable val2, + protected T load (Class type, String ix1, Comparable val1, + String ix2, Comparable val2, QueryClause... clauses) throws PersistenceException { @@ -112,9 +112,9 @@ public abstract class DepotRepository /** * Loads the persistent object that matches the specified three-column primary key. */ - protected T load (Class type, String ix1, Comparable val1, - String ix2, Comparable val2, String ix3, - Comparable val3, QueryClause... clauses) + protected T load (Class type, String ix1, Comparable val1, + String ix2, Comparable val2, String ix3, + Comparable val3, QueryClause... clauses) throws PersistenceException { clauses = ArrayUtil.append(clauses, new Key(type, ix1, val1, ix2, val2, ix3, val3)); @@ -231,7 +231,7 @@ public abstract class DepotRepository requireNotComputed(pClass, "update"); DepotMarshaller marsh = _ctx.getMarshaller(pClass); - Key key = marsh.getPrimaryKey(record); + Key key = marsh.getPrimaryKey(record); if (key == null) { throw new IllegalArgumentException("Can't update record with null primary key."); } @@ -269,7 +269,8 @@ public abstract class DepotRepository requireNotComputed(pClass, "updatePartial"); DepotMarshaller marsh = _ctx.getMarshaller(pClass); - Key key = marsh.getPrimaryKey(record); + + Key key = marsh.getPrimaryKey(record); if (key == null) { throw new IllegalArgumentException("Can't update record with null primary key."); @@ -305,7 +306,7 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updatePartial ( - Class type, Comparable primaryKey, Map updates) + Class type, Comparable primaryKey, Map updates) throws PersistenceException { Object[] fieldsValues = new Object[updates.size()*2]; @@ -328,7 +329,7 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updatePartial ( - Class type, Comparable primaryKey, Object... fieldsValues) + Class type, Comparable primaryKey, Object... fieldsValues) throws PersistenceException { return updatePartial(_ctx.getMarshaller(type).makePrimaryKey(primaryKey), fieldsValues); @@ -346,7 +347,7 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updatePartial ( - Class type, String ix1, Comparable val1, String ix2, Comparable val2, + Class type, String ix1, Comparable val1, String ix2, Comparable val2, Object... fieldsValues) throws PersistenceException { @@ -365,8 +366,8 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updatePartial ( - Class type, String ix1, Comparable val1, String ix2, Comparable val2, - String ix3, Comparable val3, Object... fieldsValues) + Class type, String ix1, Comparable val1, String ix2, Comparable val2, + String ix3, Comparable val3, Object... fieldsValues) throws PersistenceException { return updatePartial(new Key(type, ix1, val1, ix2, val2, ix3, val3), fieldsValues); @@ -452,7 +453,7 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updateLiteral ( - Class type, Comparable primaryKey, Map fieldsToValues) + Class type, Comparable primaryKey, Map fieldsToValues) throws PersistenceException { Key key = _ctx.getMarshaller(type).makePrimaryKey(primaryKey); @@ -477,7 +478,7 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updateLiteral ( - Class type, String ix1, Comparable val1, String ix2, Comparable val2, + Class type, String ix1, Comparable val1, String ix2, Comparable val2, Map fieldsToValues) throws PersistenceException { @@ -503,8 +504,8 @@ public abstract class DepotRepository * @return the number of rows modified by this action. */ protected int updateLiteral ( - Class type, String ix1, Comparable val1, String ix2, Comparable val2, - String ix3, Comparable val3, Map fieldsToValues) + Class type, String ix1, Comparable val1, String ix2, Comparable val2, + String ix3, Comparable val3, Map fieldsToValues) throws PersistenceException { Key key = new Key(type, ix1, val1, ix2, val2, ix3, val3); @@ -662,7 +663,8 @@ public abstract class DepotRepository * * @return the number of rows deleted by this action. */ - protected int delete (Class type, Comparable primaryKeyValue) + protected int delete ( + Class type, Comparable primaryKeyValue) throws PersistenceException { return delete(type, _ctx.getMarshaller(type).makePrimaryKey(primaryKeyValue)); @@ -714,7 +716,7 @@ public abstract class DepotRepository protected void requireNotComputed (Class type, String action) throws PersistenceException { - DepotMarshaller marsh = _ctx.getMarshaller(type); + DepotMarshaller marsh = _ctx.getMarshaller(type); if (marsh == null) { throw new PersistenceException("Unknown persistent type [class=" + type + "]"); } diff --git a/src/java/com/samskivert/jdbc/depot/DepotTypes.java b/src/java/com/samskivert/jdbc/depot/DepotTypes.java index 681e133..d99f69c 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotTypes.java +++ b/src/java/com/samskivert/jdbc/depot/DepotTypes.java @@ -152,9 +152,9 @@ public class DepotTypes * * @exception IllegalArgumentException thrown if the specified class is not known. */ - public DepotMarshaller getMarshaller (Class cl) + public DepotMarshaller getMarshaller (Class cl) { - DepotMarshaller marsh = _classMap.get(cl); + DepotMarshaller marsh = _classMap.get(cl); if (marsh == null) { throw new IllegalArgumentException("Persistent class not known: " + cl); } @@ -202,10 +202,11 @@ public class DepotTypes } /** Classes mapped to integers, used for table abbreviation indexing. */ - protected Map _classIx = new HashMap(); + protected Map, Integer> _classIx = new HashMap, Integer>(); /** Classes mapped to marshallers, used for table names and field lists. */ - protected Map _classMap = new HashMap(); + protected Map, DepotMarshaller> _classMap = + new HashMap, DepotMarshaller>(); /** When false, override the normal table abbreviations and return full table names instead. */ protected boolean _useTableAbbreviations = true; diff --git a/src/java/com/samskivert/jdbc/depot/EntityMigration.java b/src/java/com/samskivert/jdbc/depot/EntityMigration.java index f48da57..18593fd 100644 --- a/src/java/com/samskivert/jdbc/depot/EntityMigration.java +++ b/src/java/com/samskivert/jdbc/depot/EntityMigration.java @@ -101,7 +101,7 @@ public abstract class EntityMigration extends Modifier return true; } - protected void init (String tableName, Map marshallers) { + protected void init (String tableName, Map> marshallers) { super.init(tableName, marshallers); _newColumnDef = marshallers.get(_newColumnName).getColumnDefinition(); } @@ -133,7 +133,7 @@ public abstract class EntityMigration extends Modifier return false; } - protected void init (String tableName, Map marshallers) { + protected void init (String tableName, Map> marshallers) { super.init(tableName, marshallers); _columnName = marshallers.get(_fieldName).getColumnName(); _newColumnDef = marshallers.get(_fieldName).getColumnDefinition(); @@ -174,7 +174,7 @@ public abstract class EntityMigration extends Modifier * migration has been determined to be runnable so one cannot rely on this method having been * called in {@link #shouldRunMigration}. */ - protected void init (String tableName, Map marshallers) + protected void init (String tableName, Map> marshallers) { _tableName = tableName; } diff --git a/src/java/com/samskivert/jdbc/depot/FieldMarshaller.java b/src/java/com/samskivert/jdbc/depot/FieldMarshaller.java index 2358f58..6b9d3e0 100644 --- a/src/java/com/samskivert/jdbc/depot/FieldMarshaller.java +++ b/src/java/com/samskivert/jdbc/depot/FieldMarshaller.java @@ -52,10 +52,10 @@ public abstract class FieldMarshaller * Creates and returns a field marshaller for the specified field. Throws an exception if the * field in question cannot be marshalled. */ - public static FieldMarshaller createMarshaller (Field field) + public static FieldMarshaller createMarshaller (Field field) { Class ftype = field.getType(); - FieldMarshaller marshaller; + FieldMarshaller marshaller; // primitive types if (ftype.equals(Boolean.TYPE)) { diff --git a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java index fad7685..4784d97 100644 --- a/src/java/com/samskivert/jdbc/depot/FindAllQuery.java +++ b/src/java/com/samskivert/jdbc/depot/FindAllQuery.java @@ -117,7 +117,7 @@ public abstract class FindAllQuery if (_marsh.getPrimaryKeyFields().length == 1) { // Single-column keys result in the compact IN(keyVal1, keyVal2, ...) - Comparable[] keyFieldValues = new Comparable[fetchKeys.size()]; + Comparable[] keyFieldValues = new Comparable[fetchKeys.size()]; int ii = 0; for (Key key : fetchKeys) { keyFieldValues[ii ++] = key.condition.getValues().get(0); diff --git a/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java b/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java index 7b85b2c..9870661 100644 --- a/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java +++ b/src/java/com/samskivert/jdbc/depot/IdentityValueGenerator.java @@ -31,7 +31,7 @@ import com.samskivert.jdbc.depot.annotation.GeneratedValue; */ public class IdentityValueGenerator extends ValueGenerator { - public IdentityValueGenerator (GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) + public IdentityValueGenerator (GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) { super(gv, dm, fm); } diff --git a/src/java/com/samskivert/jdbc/depot/Key.java b/src/java/com/samskivert/jdbc/depot/Key.java index 1b81ca7..4466438 100644 --- a/src/java/com/samskivert/jdbc/depot/Key.java +++ b/src/java/com/samskivert/jdbc/depot/Key.java @@ -24,6 +24,7 @@ import java.io.Serializable; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.HashMap; import java.util.Map; @@ -46,7 +47,7 @@ public class Key extends WhereClause public static class WhereCondition implements SQLExpression, Serializable { - public WhereCondition (Class pClass, ArrayList values) + public WhereCondition (Class pClass, ArrayList> values) { _pClass = pClass; _values = values; @@ -69,7 +70,7 @@ public class Key extends WhereClause return _pClass; } - public ArrayList getValues () + public ArrayList> getValues () { return _values; } @@ -83,7 +84,7 @@ public class Key extends WhereClause if (obj == null || getClass() != obj.getClass()) { return false; } - WhereCondition other = (WhereCondition) obj; + WhereCondition other = (WhereCondition) obj; return _pClass == other._pClass && _values.equals(other.getValues()); } @@ -94,7 +95,7 @@ public class Key extends WhereClause } protected Class _pClass; - protected ArrayList _values; + protected ArrayList> _values; // List is not Serializable } /** The expression that identifies our row. */ @@ -103,7 +104,7 @@ public class Key extends WhereClause /** * Constructs a new single-column {@code Key} with the given value. */ - public Key (Class pClass, String ix, Comparable val) + public Key (Class pClass, String ix, Comparable val) { this(pClass, new String[] { ix }, new Comparable[] { val }); } @@ -111,8 +112,8 @@ public class Key extends WhereClause /** * Constructs a new two-column {@code Key} with the given values. */ - public Key (Class pClass, String ix1, Comparable val1, - String ix2, Comparable val2) + public Key (Class pClass, String ix1, Comparable val1, + String ix2, Comparable val2) { this(pClass, new String[] { ix1, ix2 }, new Comparable[] { val1, val2 }); } @@ -120,8 +121,8 @@ public class Key extends WhereClause /** * Constructs a new three-column {@code Key} with the given values. */ - public Key (Class pClass, String ix1, Comparable val1, - String ix2, Comparable val2, String ix3, Comparable val3) + public Key (Class pClass, String ix1, Comparable val1, + String ix2, Comparable val2, String ix3, Comparable val3) { this(pClass, new String[] { ix1, ix2, ix3 }, new Comparable[] { val1, val2, val3 }); } @@ -129,14 +130,14 @@ public class Key extends WhereClause /** * Constructs a new multi-column {@code Key} with the given values. */ - public Key (Class pClass, String[] fields, Comparable[] values) + public Key (Class pClass, String[] fields, Comparable[] values) { if (fields.length != values.length) { throw new IllegalArgumentException("Field and Value arrays must be of equal length."); } // build a local map of field name -> field value - Map map = new HashMap(); + Map> map = new HashMap>(); for (int i = 0; i < fields.length; i ++) { map.put(fields[i], values[i]); } @@ -145,9 +146,9 @@ public class Key extends WhereClause String[] keyFields = getKeyFields(pClass); // now extract the values in field order and ensure none are extra or missing - ArrayList newValues = new ArrayList(); + ArrayList> newValues = new ArrayList>(); for (int ii = 0; ii < keyFields.length; ii++) { - Comparable nugget = map.remove(keyFields[ii]); + Comparable nugget = map.remove(keyFields[ii]); if (nugget == null) { // make sure we were provided with a value for this primary key field throw new IllegalArgumentException("Missing value for key field: " + keyFields[ii]); @@ -227,7 +228,7 @@ public class Key extends WhereClause if (obj == null || getClass() != obj.getClass()) { return false; } - return condition.equals(((Key) obj).condition); + return condition.equals(((Key) obj).condition); } @Override @@ -260,7 +261,7 @@ public class Key extends WhereClause { String[] fields = _keyFields.get(pClass); if (fields == null) { - ArrayList kflist = new ArrayList(); + List kflist = new ArrayList(); for (Field field : pClass.getFields()) { // look for @Id fields if (field.getAnnotation(Id.class) != null) { diff --git a/src/java/com/samskivert/jdbc/depot/MultiKey.java b/src/java/com/samskivert/jdbc/depot/MultiKey.java index 75205f3..c9f0a0d 100644 --- a/src/java/com/samskivert/jdbc/depot/MultiKey.java +++ b/src/java/com/samskivert/jdbc/depot/MultiKey.java @@ -38,7 +38,7 @@ public class MultiKey extends WhereClause /** * Constructs a new single-column {@code MultiKey} with the given value range. */ - public MultiKey (Class pClass, String ix, Comparable... val) + public MultiKey (Class pClass, String ix, Comparable... val) { this(pClass, new String[0], new Comparable[0], ix, val); } @@ -46,7 +46,8 @@ public class MultiKey extends WhereClause /** * Constructs a new two-column {@code MultiKey} with the given value range. */ - public MultiKey (Class pClass, String ix1, Comparable val1, String ix2, Comparable... val2) + public MultiKey (Class pClass, String ix1, Comparable val1, String ix2, + Comparable... val2) { this(pClass, new String[] { ix1 }, new Comparable[] { val1 }, ix2, val2); } @@ -54,8 +55,8 @@ public class MultiKey extends WhereClause /** * Constructs a new three-column {@code MultiKey} with the given value range. */ - public MultiKey (Class pClass, String ix1, Comparable val1, String ix2, Comparable val2, - String ix3, Comparable... val3) + public MultiKey (Class pClass, String ix1, Comparable val1, + String ix2, Comparable val2, String ix3, Comparable... val3) { this(pClass, new String[] { ix1, ix2 }, new Comparable[] { val1, val2 }, ix3, val3); } @@ -64,8 +65,8 @@ public class MultiKey extends WhereClause * Constructs a new multi-column {@code MultiKey} with the given value range. * @TODO: See {@link Key#Key(Class, String[], Comparable[]) for somewhat relevant comments. */ - public MultiKey (Class pClass, String[] sFields, Comparable[] sValues, - String mField, Comparable[] mValues) + public MultiKey (Class pClass, String[] sFields, Comparable[] sValues, + String mField, Comparable[] mValues) { if (sFields.length != sValues.length) { throw new IllegalArgumentException( @@ -74,7 +75,7 @@ public class MultiKey extends WhereClause _pClass = pClass; _mField = mField; _mValues = mValues; - _map = new HashMap(); + _map = new HashMap>(); for (int i = 0; i < sFields.length; i ++) { _map.put(sFields[i], sValues[i]); } @@ -85,7 +86,7 @@ public class MultiKey extends WhereClause return _pClass; } - public Map getSingleFieldsMap () + public Map> getSingleFieldsMap () { return _map; } @@ -95,7 +96,7 @@ public class MultiKey extends WhereClause return _mField; } - public Comparable[] getMultiValues () + public Comparable[] getMultiValues () { return _mValues; } @@ -126,7 +127,7 @@ public class MultiKey extends WhereClause // from CacheInvalidator public void invalidate (PersistenceContext ctx) { - HashMap newMap = new HashMap(_map); + HashMap> newMap = new HashMap>(_map); for (int i = 0; i < _mValues.length; i ++) { newMap.put(_mField, _mValues[i]); ctx.cacheInvalidate(new SimpleCacheKey(_pClass, newMap)); @@ -141,7 +142,7 @@ public class MultiKey extends WhereClause } protected String _mField; - protected Comparable[] _mValues; + protected Comparable[] _mValues; protected Class _pClass; - protected HashMap _map; + protected HashMap> _map; } diff --git a/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java b/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java index e778095..6f6e164 100644 --- a/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java +++ b/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java @@ -205,7 +205,7 @@ public class MySQLBuilder } @Override - protected String getColumnType (FieldMarshaller fm, int length) + protected String getColumnType (FieldMarshaller fm, int length) { if (fm instanceof ByteMarshaller) { return "TINYINT"; diff --git a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java index 518ccfd..0e376a0 100644 --- a/src/java/com/samskivert/jdbc/depot/PersistenceContext.java +++ b/src/java/com/samskivert/jdbc/depot/PersistenceContext.java @@ -316,9 +316,8 @@ public class PersistenceContext log.debug("storing [key=" + key + ", value=" + entry + "]"); CacheAdapter.CacheBin bin = _cache.getCache(key.getCacheId()); - CacheAdapter.CachedValue element = bin.lookup(key.getCacheKey()); - @SuppressWarnings("unchecked") T oldEntry = - (element != null ? (T) element.getValue() : null); + CacheAdapter.CachedValue element = bin.lookup(key.getCacheKey()); + T oldEntry = (element != null ? element.getValue() : null); // update the cache bin.store(key.getCacheKey(), entry); @@ -353,7 +352,7 @@ public class PersistenceContext * Evicts the cache entry indexed under the given class and cache key, if there is one. The * eviction may trigger further cache invalidations. */ - public void cacheInvalidate (Class pClass, Serializable cacheKey) + public void cacheInvalidate (Class pClass, Serializable cacheKey) { cacheInvalidate(pClass.getName(), cacheKey); } @@ -397,7 +396,8 @@ public class PersistenceContext * Brutally iterates over the entire contents of the cache associated with the given class, * invoking the callback for each cache entry. */ - public void cacheTraverse (Class pClass, CacheTraverser filter) + public void cacheTraverse ( + Class pClass, CacheTraverser filter) { cacheTraverse(pClass.getName(), filter); } diff --git a/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java b/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java index 210c0b0..bdd4a1d 100644 --- a/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java +++ b/src/java/com/samskivert/jdbc/depot/PostgreSQLBuilder.java @@ -212,7 +212,7 @@ public class PostgreSQLBuilder } @Override - protected String getColumnType (FieldMarshaller fm, int length) + protected String getColumnType (FieldMarshaller fm, int length) { if (fm instanceof ByteMarshaller) { return "SMALLINT"; diff --git a/src/java/com/samskivert/jdbc/depot/SQLBuilder.java b/src/java/com/samskivert/jdbc/depot/SQLBuilder.java index 0911179..9e20fe8 100644 --- a/src/java/com/samskivert/jdbc/depot/SQLBuilder.java +++ b/src/java/com/samskivert/jdbc/depot/SQLBuilder.java @@ -109,7 +109,7 @@ public abstract class SQLBuilder * TODO: This method should be split into several parts that are more easily overridden on a * case-by-case basis in the dialectal subclasses. */ - public ColumnDefinition buildColumnDefinition (FieldMarshaller fm) + public ColumnDefinition buildColumnDefinition (FieldMarshaller fm) { // if this field is @Computed, it has no SQL definition if (fm.getComputed() != null) { @@ -228,7 +228,7 @@ public abstract class SQLBuilder * Overridden by subclasses to figure the dialect-specific SQL type of the given field. * @param length */ - protected abstract String getColumnType (FieldMarshaller fm, int length); + protected abstract String getColumnType (FieldMarshaller fm, int length); /** The class that maps persistent classes to marshallers. */ protected DepotTypes _types; diff --git a/src/java/com/samskivert/jdbc/depot/SimpleCacheKey.java b/src/java/com/samskivert/jdbc/depot/SimpleCacheKey.java index 636912a..823b86f 100644 --- a/src/java/com/samskivert/jdbc/depot/SimpleCacheKey.java +++ b/src/java/com/samskivert/jdbc/depot/SimpleCacheKey.java @@ -42,7 +42,7 @@ public class SimpleCacheKey * Construct a {@link SimpleCacheKey} associated with the given persistent class with * the given cache key. */ - public SimpleCacheKey (Class cacheClass, Serializable cacheKey) + public SimpleCacheKey (Class cacheClass, Serializable cacheKey) { this(cacheClass.getName(), cacheKey); } diff --git a/src/java/com/samskivert/jdbc/depot/TableValueGenerator.java b/src/java/com/samskivert/jdbc/depot/TableValueGenerator.java index b488f81..c060630 100644 --- a/src/java/com/samskivert/jdbc/depot/TableValueGenerator.java +++ b/src/java/com/samskivert/jdbc/depot/TableValueGenerator.java @@ -37,7 +37,8 @@ import com.samskivert.jdbc.JDBCUtil; */ public class TableValueGenerator extends ValueGenerator { - public TableValueGenerator (TableGenerator tg, GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) + public TableValueGenerator ( + TableGenerator tg, GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) { super(gv, dm, fm); _valueTable = defStr(tg.table(), "IdSequences"); diff --git a/src/java/com/samskivert/jdbc/depot/ValueGenerator.java b/src/java/com/samskivert/jdbc/depot/ValueGenerator.java index ce18496..c8bca36 100644 --- a/src/java/com/samskivert/jdbc/depot/ValueGenerator.java +++ b/src/java/com/samskivert/jdbc/depot/ValueGenerator.java @@ -36,7 +36,7 @@ import static com.samskivert.jdbc.depot.Log.log; */ public abstract class ValueGenerator { - public ValueGenerator (GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) + public ValueGenerator (GeneratedValue gv, DepotMarshaller dm, FieldMarshaller fm) { _allocationSize = gv.allocationSize(); _initialValue = gv.initialValue(); @@ -101,12 +101,12 @@ public abstract class ValueGenerator } } - public DepotMarshaller getDepotMarshaller () + public DepotMarshaller getDepotMarshaller () { return _dm; } - public FieldMarshaller getFieldMarshaller () + public FieldMarshaller getFieldMarshaller () { return _fm; } @@ -115,6 +115,6 @@ public abstract class ValueGenerator protected int _allocationSize; protected boolean _migrateIfExists; - protected DepotMarshaller _dm; - protected FieldMarshaller _fm; + protected DepotMarshaller _dm; + protected FieldMarshaller _fm; } diff --git a/src/java/com/samskivert/jdbc/depot/clause/Where.java b/src/java/com/samskivert/jdbc/depot/clause/Where.java index a6a7fa3..71ff4b3 100644 --- a/src/java/com/samskivert/jdbc/depot/clause/Where.java +++ b/src/java/com/samskivert/jdbc/depot/clause/Where.java @@ -38,26 +38,26 @@ import com.samskivert.jdbc.depot.operator.Logic.And; */ public class Where extends WhereClause { - public Where (ColumnExp column, Comparable value) + public Where (ColumnExp column, Comparable value) { - this(new ColumnExp[] { column }, new Comparable[] { value }); + this(new ColumnExp[] { column }, new Comparable[] { value }); } - public Where (ColumnExp index1, Comparable value1, - ColumnExp index2, Comparable value2) + public Where (ColumnExp index1, Comparable value1, + ColumnExp index2, Comparable value2) { - this(new ColumnExp[] { index1, index2 }, new Comparable[] { value1, value2 }); + this(new ColumnExp[] { index1, index2 }, new Comparable[] { value1, value2 }); } - public Where (ColumnExp index1, Comparable value1, - ColumnExp index2, Comparable value2, - ColumnExp index3, Comparable value3) + public Where (ColumnExp index1, Comparable value1, + ColumnExp index2, Comparable value2, + ColumnExp index3, Comparable value3) { this(new ColumnExp[] { index1, index2, index3 }, - new Comparable[] { value1, value2, value3 }); + new Comparable[] { value1, value2, value3 }); } - public Where (ColumnExp[] columns, Comparable[] values) + public Where (ColumnExp[] columns, Comparable[] values) { this(toCondition(columns, values)); } @@ -84,7 +84,7 @@ public class Where extends WhereClause _condition.addClasses(classSet); } - protected static SQLExpression toCondition (ColumnExp[] columns, Comparable[] values) + protected static SQLExpression toCondition (ColumnExp[] columns, Comparable[] values) { SQLExpression[] comparisons = new SQLExpression[columns.length]; for (int ii = 0; ii < columns.length; ii ++) { diff --git a/src/java/com/samskivert/jdbc/depot/expression/ExpressionVisitor.java b/src/java/com/samskivert/jdbc/depot/expression/ExpressionVisitor.java index 9fa59fb..6b7740e 100644 --- a/src/java/com/samskivert/jdbc/depot/expression/ExpressionVisitor.java +++ b/src/java/com/samskivert/jdbc/depot/expression/ExpressionVisitor.java @@ -55,7 +55,7 @@ public interface ExpressionVisitor throws Exception; public void visit (WhereCondition whereCondition) throws Exception; - public void visit (Key key) + public void visit (Key key) throws Exception; public void visit (MultiKey key) throws Exception; diff --git a/src/java/com/samskivert/jdbc/depot/operator/Arithmetic.java b/src/java/com/samskivert/jdbc/depot/operator/Arithmetic.java index b658cec..d5a807e 100644 --- a/src/java/com/samskivert/jdbc/depot/operator/Arithmetic.java +++ b/src/java/com/samskivert/jdbc/depot/operator/Arithmetic.java @@ -32,7 +32,7 @@ public abstract class Arithmetic /** The SQL '+' operator. */ public static class Add extends BinaryOperator { - public Add (SQLExpression column, Comparable value) + public Add (SQLExpression column, Comparable value) { super(column, value); } @@ -52,7 +52,7 @@ public abstract class Arithmetic /** The SQL '-' operator. */ public static class Sub extends BinaryOperator { - public Sub (SQLExpression column, Comparable value) + public Sub (SQLExpression column, Comparable value) { super(column, value); } @@ -72,7 +72,7 @@ public abstract class Arithmetic /** The SQL '*' operator. */ public static class Mul extends BinaryOperator { - public Mul (SQLExpression column, Comparable value) + public Mul (SQLExpression column, Comparable value) { super(column, value); } @@ -92,7 +92,7 @@ public abstract class Arithmetic /** The SQL '/' operator. */ public static class Div extends BinaryOperator { - public Div (SQLExpression column, Comparable value) + public Div (SQLExpression column, Comparable value) { super(column, value); } @@ -112,7 +112,7 @@ public abstract class Arithmetic /** The SQL '&' operator. */ public static class BitAnd extends BinaryOperator { - public BitAnd (SQLExpression column, Comparable value) + public BitAnd (SQLExpression column, Comparable value) { super(column, value); } @@ -132,7 +132,7 @@ public abstract class Arithmetic /** The SQL '|' operator. */ public static class BitOr extends BinaryOperator { - public BitOr (SQLExpression column, Comparable value) + public BitOr (SQLExpression column, Comparable value) { super(column, value); } diff --git a/src/java/com/samskivert/jdbc/depot/operator/Conditionals.java b/src/java/com/samskivert/jdbc/depot/operator/Conditionals.java index 1279658..1d593b3 100644 --- a/src/java/com/samskivert/jdbc/depot/operator/Conditionals.java +++ b/src/java/com/samskivert/jdbc/depot/operator/Conditionals.java @@ -75,7 +75,7 @@ public abstract class Conditionals /** The SQL '=' operator. */ public static class Equals extends SQLOperator.BinaryOperator { - public Equals (SQLExpression column, Comparable value) + public Equals (SQLExpression column, Comparable value) { super(column, value); } @@ -95,7 +95,7 @@ public abstract class Conditionals /** The SQL '!=' operator. */ public static class NotEquals extends SQLOperator.BinaryOperator { - public NotEquals (SQLExpression column, Comparable value) + public NotEquals (SQLExpression column, Comparable value) { super(column, value); } @@ -115,7 +115,7 @@ public abstract class Conditionals /** The SQL '<' operator. */ public static class LessThan extends SQLOperator.BinaryOperator { - public LessThan (SQLExpression column, Comparable value) + public LessThan (SQLExpression column, Comparable value) { super(column, value); } @@ -135,7 +135,7 @@ public abstract class Conditionals /** The SQL '<=' operator. */ public static class LessThanEquals extends SQLOperator.BinaryOperator { - public LessThanEquals (SQLExpression column, Comparable value) + public LessThanEquals (SQLExpression column, Comparable value) { super(column, value); } @@ -155,7 +155,7 @@ public abstract class Conditionals /** The SQL '>' operator. */ public static class GreaterThan extends SQLOperator.BinaryOperator { - public GreaterThan (SQLExpression column, Comparable value) + public GreaterThan (SQLExpression column, Comparable value) { super(column, value); } @@ -175,7 +175,7 @@ public abstract class Conditionals /** The SQL '>=' operator. */ public static class GreaterThanEquals extends SQLOperator.BinaryOperator { - public GreaterThanEquals (SQLExpression column, Comparable value) + public GreaterThanEquals (SQLExpression column, Comparable value) { super(column, value); } @@ -196,18 +196,18 @@ public abstract class Conditionals public static class In implements SQLOperator { - public In (Class pClass, String pColumn, Comparable... values) + public In (Class pClass, String pColumn, Comparable... values) { this(new ColumnExp(pClass, pColumn), values); } public In (Class pClass, String pColumn, - Collection values) + Collection> values) { - this(new ColumnExp(pClass, pColumn), values.toArray(new Comparable[values.size()])); + this(new ColumnExp(pClass, pColumn), values.toArray(new Comparable[values.size()])); } - public In (ColumnExp column, Comparable... values) + public In (ColumnExp column, Comparable... values) { if (values.length == 0) { throw new IllegalArgumentException("In() condition needs at least one value."); @@ -216,9 +216,9 @@ public abstract class Conditionals _values = values; } - public In (ColumnExp pColumn, Collection values) + public In (ColumnExp pColumn, Collection> values) { - this(pColumn, values.toArray(new Comparable[values.size()])); + this(pColumn, values.toArray(new Comparable[values.size()])); } public ColumnExp getColumn () @@ -226,7 +226,7 @@ public abstract class Conditionals return _column; } - public Comparable[] getValues () + public Comparable[] getValues () { return _values; } @@ -244,13 +244,13 @@ public abstract class Conditionals } protected ColumnExp _column; - protected Comparable[] _values; + protected Comparable[] _values; } /** The SQL ' like ' operator. */ public static class Like extends SQLOperator.BinaryOperator { - public Like (SQLExpression column, Comparable value) + public Like (SQLExpression column, Comparable value) { super(column, value); } diff --git a/src/java/com/samskivert/jdbc/depot/operator/SQLOperator.java b/src/java/com/samskivert/jdbc/depot/operator/SQLOperator.java index d1af066..7f4e4ce 100644 --- a/src/java/com/samskivert/jdbc/depot/operator/SQLOperator.java +++ b/src/java/com/samskivert/jdbc/depot/operator/SQLOperator.java @@ -83,7 +83,7 @@ public interface SQLOperator extends SQLExpression _rhs = rhs; } - public BinaryOperator (SQLExpression lhs, Comparable rhs) + public BinaryOperator (SQLExpression lhs, Comparable rhs) { this(lhs, new ValueExp(rhs)); } diff --git a/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java b/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java index 744c2bf..d076116 100644 --- a/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java +++ b/src/java/com/samskivert/jdbc/depot/tools/GenRecordTask.java @@ -140,7 +140,7 @@ public class GenRecordTask extends Task } /** Processes a resolved persistent record class instance. */ - protected void processRecord (File source, Class rclass) + protected void processRecord (File source, Class rclass) { // make sure we extend persistent record if (!_prclass.isAssignableFrom(rclass)) {