Google Collectivised.
This commit is contained in:
@@ -20,11 +20,12 @@
|
||||
|
||||
package com.samskivert.depot;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.depot.annotation.Computed;
|
||||
import com.samskivert.depot.clause.DeleteClause;
|
||||
import com.samskivert.depot.clause.FieldDefinition;
|
||||
@@ -310,7 +311,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
||||
"Can not yet nest SELECTs on the same persistent record.");
|
||||
}
|
||||
|
||||
Map<String, FieldDefinition> definitionMap = new HashMap<String, FieldDefinition>();
|
||||
Map<String, FieldDefinition> definitionMap = Maps.newHashMap();
|
||||
for (FieldDefinition definition : selectClause.getFieldDefinitions()) {
|
||||
definitionMap.put(definition.getField(), definition);
|
||||
}
|
||||
@@ -600,7 +601,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
||||
|
||||
/** A mapping of field overrides per persistent record. */
|
||||
protected Map<Class<? extends PersistentRecord>, Map<String, FieldDefinition>> _definitions=
|
||||
new HashMap<Class<? extends PersistentRecord>, Map<String,FieldDefinition>>();
|
||||
Maps.newHashMap();
|
||||
|
||||
/** A flag that's set to true for inner SELECT's */
|
||||
protected boolean _innerClause = false;
|
||||
|
||||
@@ -30,12 +30,14 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.depot.annotation.Computed;
|
||||
import com.samskivert.depot.annotation.Entity;
|
||||
import com.samskivert.depot.annotation.FullTextIndex;
|
||||
@@ -97,7 +99,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
boolean seenIdentityGenerator = false;
|
||||
|
||||
// introspect on the class and create marshallers for persistent fields
|
||||
ArrayList<String> fields = new ArrayList<String>();
|
||||
List<String> fields = Lists.newArrayList();
|
||||
for (Field field : _pClass.getFields()) {
|
||||
int mods = field.getModifiers();
|
||||
|
||||
@@ -125,7 +127,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
// check to see if this is our primary key
|
||||
if (field.getAnnotation(Id.class) != null) {
|
||||
if (_pkColumns == null) {
|
||||
_pkColumns = new ArrayList<FieldMarshaller<?>>();
|
||||
_pkColumns = Lists.newArrayList();
|
||||
}
|
||||
_pkColumns.add(fm);
|
||||
}
|
||||
@@ -197,7 +199,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
if (entity != null) {
|
||||
for (UniqueConstraint constraint : entity.uniqueConstraints()) {
|
||||
String[] conFields = constraint.fieldNames();
|
||||
Set<String> colSet = new HashSet<String>();
|
||||
Set<String> colSet = Sets.newHashSet();
|
||||
for (int ii = 0; ii < conFields.length; ii ++) {
|
||||
FieldMarshaller<?> fm = _fields.get(conFields[ii]);
|
||||
if (fm == null) {
|
||||
@@ -453,7 +455,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
{
|
||||
try {
|
||||
// first, build a set of the fields that we actually received
|
||||
Set<String> fields = new HashSet<String>();
|
||||
Set<String> fields = Sets.newHashSet();
|
||||
ResultSetMetaData metadata = rs.getMetaData();
|
||||
for (int ii = 1; ii <= metadata.getColumnCount(); ii ++) {
|
||||
fields.add(metadata.getColumnName(ii));
|
||||
@@ -497,7 +499,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
public Set<String> generateFieldValues (
|
||||
Connection conn, DatabaseLiaison liaison, Object po, boolean postFactum)
|
||||
{
|
||||
Set<String> idFields = new HashSet<String>();
|
||||
Set<String> idFields = Sets.newHashSet();
|
||||
|
||||
for (ValueGenerator vg : _valueGenerators.values()) {
|
||||
if (!postFactum && vg instanceof IdentityValueGenerator) {
|
||||
@@ -752,14 +754,14 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
}
|
||||
|
||||
// this is a little silly, but we need a copy for name disambiguation later
|
||||
Set<String> indicesCopy = new HashSet<String>(metaData.indexColumns.keySet());
|
||||
Set<String> indicesCopy = Sets.newHashSet(metaData.indexColumns.keySet());
|
||||
|
||||
// figure out which columns we have in the table now, so that when all is said and done we
|
||||
// can see what new columns we have in the table and run the creation code for any value
|
||||
// generators that are defined on those columns (we can't just track the columns we add in
|
||||
// our automatic migrations because someone might register custom migrations that add
|
||||
// columns specially)
|
||||
Set<String> preMigrateColumns = new HashSet<String>(metaData.tableColumns);
|
||||
Set<String> preMigrateColumns = Sets.newHashSet(metaData.tableColumns);
|
||||
|
||||
// add any missing columns
|
||||
for (String fname : _columnFields) {
|
||||
@@ -842,7 +844,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
}
|
||||
|
||||
// now check if there are any @Entity(uniqueConstraints) that need to be created
|
||||
Set<Set<String>> uniqueIndices = new HashSet<Set<String>>(metaData.indexColumns.values());
|
||||
Set<Set<String>> uniqueIndices = Sets.newHashSet(metaData.indexColumns.values());
|
||||
|
||||
// unique constraints are unordered and may be unnamed, so we view them only as column sets
|
||||
for (Set<String> colSet : _uniqueConstraints) {
|
||||
@@ -877,7 +879,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
|
||||
// next we create any full text search indexes that exist on the record but not in the
|
||||
// table, first step being to do a dialect-sensitive enumeration of existing indexes
|
||||
Set<String> tableFts = new HashSet<String>();
|
||||
Set<String> tableFts = Sets.newHashSet();
|
||||
builder.getFtsIndexes(metaData.tableColumns, metaData.indexColumns.keySet(), tableFts);
|
||||
|
||||
// then iterate over what should be there
|
||||
@@ -1024,10 +1026,10 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
protected static class TableMetaData
|
||||
{
|
||||
public boolean tableExists;
|
||||
public Set<String> tableColumns = new HashSet<String>();
|
||||
public Map<String, Set<String>> indexColumns = new HashMap<String, Set<String>>();
|
||||
public Set<String> tableColumns = Sets.newHashSet();
|
||||
public Map<String, Set<String>> indexColumns = Maps.newHashMap();
|
||||
public String pkName;
|
||||
public Set<String> pkColumns = new HashSet<String>();
|
||||
public Set<String> pkColumns = Sets.newHashSet();
|
||||
|
||||
public static TableMetaData load (PersistenceContext ctx, final String tableName)
|
||||
throws DatabaseException
|
||||
@@ -1066,7 +1068,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
} else {
|
||||
// for unique indices we collect the column names
|
||||
if (set == null) {
|
||||
set = new HashSet<String>();
|
||||
set = Sets.newHashSet();
|
||||
indexColumns.put(indexName, set);
|
||||
}
|
||||
set.add(rs.getString("COLUMN_NAME"));
|
||||
@@ -1091,14 +1093,14 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
protected Computed _computed;
|
||||
|
||||
/** A mapping of field names to value generators for that field. */
|
||||
protected Map<String, ValueGenerator> _valueGenerators = new HashMap<String, ValueGenerator>();
|
||||
protected Map<String, ValueGenerator> _valueGenerators = Maps.newHashMap();
|
||||
|
||||
/** A field marshaller for each persistent field in our object. */
|
||||
protected Map<String, FieldMarshaller<?>> _fields = new HashMap<String, FieldMarshaller<?>>();
|
||||
protected Map<String, FieldMarshaller<?>> _fields = Maps.newHashMap();
|
||||
|
||||
/** The field marshallers for our persistent object's primary key columns or null if it did not
|
||||
* define a primary key. */
|
||||
protected ArrayList<FieldMarshaller<?>> _pkColumns;
|
||||
protected List<FieldMarshaller<?>> _pkColumns;
|
||||
|
||||
/** The persisent fields of our object, in definition order. */
|
||||
protected String[] _allFields;
|
||||
@@ -1107,12 +1109,12 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
protected String[] _columnFields;
|
||||
|
||||
/** The indexes defined in @Entity annotations for this record. */
|
||||
protected Map<String, Index> _indexes = new HashMap<String, Index>();
|
||||
protected Map<String, Index> _indexes = Maps.newHashMap();
|
||||
|
||||
/** The unique constraints defined in @Entity annotations for this record. */
|
||||
protected Set<Set<String>> _uniqueConstraints = new HashSet<Set<String>>();
|
||||
protected Set<Set<String>> _uniqueConstraints = Sets.newHashSet();
|
||||
|
||||
protected Map<String, FullTextIndex> _fullTextIndexes = new HashMap<String, FullTextIndex>();
|
||||
protected Map<String, FullTextIndex> _fullTextIndexes = Maps.newHashMap();
|
||||
|
||||
/** The version of our persistent object schema as specified in the class definition. */
|
||||
protected int _schemaVersion = -1;
|
||||
@@ -1121,7 +1123,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
||||
protected boolean _initialized;
|
||||
|
||||
/** A list of hand registered schema migrations to run prior to doing the default migration. */
|
||||
protected ArrayList<SchemaMigration> _schemaMigs = new ArrayList<SchemaMigration>();
|
||||
protected List<SchemaMigration> _schemaMigs = Lists.newArrayList();
|
||||
|
||||
/** The name of the table we use to track schema versions. */
|
||||
protected static final String SCHEMA_VERSION_TABLE = "DepotSchemaVersion";
|
||||
|
||||
@@ -26,15 +26,16 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
|
||||
import com.samskivert.jdbc.ConnectionProvider;
|
||||
@@ -92,8 +93,7 @@ public abstract class DepotRepository
|
||||
protected void resolveRecords ()
|
||||
throws DatabaseException
|
||||
{
|
||||
Set<Class<? extends PersistentRecord>> classes =
|
||||
new HashSet<Class<? extends PersistentRecord>>();
|
||||
Set<Class<? extends PersistentRecord>> classes = Sets.newHashSet();
|
||||
getManagedRecords(classes);
|
||||
for (Class<? extends PersistentRecord> rclass : classes) {
|
||||
_ctx.getMarshaller(rclass);
|
||||
@@ -214,7 +214,7 @@ public abstract class DepotRepository
|
||||
{
|
||||
// convert the raw keys into real key records
|
||||
DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
|
||||
List<Key<T>> keys = new ArrayList<Key<T>>();
|
||||
List<Key<T>> keys = Lists.newArrayList();
|
||||
for (Comparable<?> key : primaryKeys) {
|
||||
keys.add(marsh.makePrimaryKey(key));
|
||||
}
|
||||
@@ -311,7 +311,7 @@ public abstract class DepotRepository
|
||||
Class<T> type, boolean forUpdate, Collection<? extends QueryClause> clauses)
|
||||
throws DatabaseException
|
||||
{
|
||||
final List<Key<T>> keys = new ArrayList<Key<T>>();
|
||||
final List<Key<T>> keys = Lists.newArrayList();
|
||||
final DepotMarshaller<T> marsh = _ctx.getMarshaller(type);
|
||||
SelectClause<T> select = new SelectClause<T>(type, marsh.getPrimaryKeyFields(), clauses);
|
||||
final SQLBuilder builder = _ctx.getSQLBuilder(DepotTypes.getDepotTypes(_ctx, select));
|
||||
@@ -984,5 +984,5 @@ public abstract class DepotRepository
|
||||
}
|
||||
|
||||
protected PersistenceContext _ctx;
|
||||
protected List<DataMigration> _dataMigs = new ArrayList<DataMigration>();
|
||||
protected List<DataMigration> _dataMigs = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@@ -24,11 +24,12 @@ import java.sql.SQLException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.depot.clause.QueryClause;
|
||||
import com.samskivert.depot.expression.SQLExpression;
|
||||
|
||||
@@ -57,8 +58,7 @@ public class DepotTypes
|
||||
PersistenceContext ctx, Collection<? extends QueryClause> clauses)
|
||||
throws DatabaseException
|
||||
{
|
||||
Set<Class<? extends PersistentRecord>> classSet =
|
||||
new HashSet<Class<? extends PersistentRecord>>();
|
||||
Set<Class<? extends PersistentRecord>> classSet = Sets.newHashSet();
|
||||
for (QueryClause clause : clauses) {
|
||||
if (clause != null) {
|
||||
clause.addClasses(classSet);
|
||||
@@ -210,11 +210,10 @@ public class DepotTypes
|
||||
}
|
||||
|
||||
/** Classes mapped to integers, used for table abbreviation indexing. */
|
||||
protected Map<Class<?>, Integer> _classIx = new HashMap<Class<?>, Integer>();
|
||||
protected Map<Class<?>, Integer> _classIx = Maps.newHashMap();
|
||||
|
||||
/** Classes mapped to marshallers, used for table names and field lists. */
|
||||
protected Map<Class<?>, DepotMarshaller<?>> _classMap =
|
||||
new HashMap<Class<?>, DepotMarshaller<?>>();
|
||||
protected Map<Class<?>, DepotMarshaller<?>> _classMap = Maps.newHashMap();
|
||||
|
||||
/** When false, override the normal table abbreviations and return full table names instead. */
|
||||
protected boolean _useTableAbbreviations = true;
|
||||
|
||||
@@ -25,15 +25,16 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.jdbc.DatabaseLiaison;
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
|
||||
@@ -83,9 +84,9 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
public List<T> invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws SQLException
|
||||
{
|
||||
Map<Key<T>, T> entities = new HashMap<Key<T>, T>();
|
||||
List<Key<T>> allKeys = new ArrayList<Key<T>>();
|
||||
Set<Key<T>> fetchKeys = new HashSet<Key<T>>();
|
||||
Map<Key<T>, T> entities = Maps.newHashMap();
|
||||
List<Key<T>> allKeys = Lists.newArrayList();
|
||||
Set<Key<T>> fetchKeys = Sets.newHashSet();
|
||||
|
||||
PreparedStatement stmt = _builder.prepare(conn);
|
||||
String stmtString = stmt.toString(); // for debugging
|
||||
@@ -134,8 +135,8 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
public List<T> invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws SQLException
|
||||
{
|
||||
Map<Key<T>, T> entities = new HashMap<Key<T>, T>();
|
||||
Set<Key<T>> fetchKeys = new HashSet<Key<T>>();
|
||||
Map<Key<T>, T> entities = Maps.newHashMap();
|
||||
Set<Key<T>> fetchKeys = Sets.newHashSet();
|
||||
for (Key<T> key : _keys) {
|
||||
// TODO: All this cache fiddling needs to move to PersistenceContext?
|
||||
CacheAdapter.CachedValue<T> hit = _ctx.cacheLookup(key);
|
||||
@@ -175,7 +176,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
public List<T> invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws SQLException
|
||||
{
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = Lists.newArrayList();
|
||||
PreparedStatement stmt = _builder.prepare(conn);
|
||||
try {
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
@@ -219,7 +220,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
return bits;
|
||||
}
|
||||
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = Lists.newArrayList();
|
||||
for (T bit : bits) {
|
||||
if (bit != null) {
|
||||
@SuppressWarnings("unchecked") T cbit = (T) bit.clone();
|
||||
@@ -240,7 +241,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
if (fetchKeys.size() > In.MAX_KEYS) {
|
||||
int keyCount = fetchKeys.size();
|
||||
do {
|
||||
Set<Key<T>> keys = new HashSet<Key<T>>();
|
||||
Set<Key<T>> keys = Sets.newHashSet();
|
||||
Iterator<Key<T>> iter = fetchKeys.iterator();
|
||||
for (int ii = 0; ii < Math.min(keyCount, In.MAX_KEYS); ii++) {
|
||||
keys.add(iter.next());
|
||||
@@ -254,7 +255,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
loadRecords(conn, fetchKeys, entities, origStmt);
|
||||
}
|
||||
|
||||
List<T> result = new ArrayList<T>();
|
||||
List<T> result = Lists.newArrayList();
|
||||
for (Key<T> key : allKeys) {
|
||||
T value = entities.get(key);
|
||||
if (value != null) {
|
||||
@@ -272,7 +273,7 @@ public abstract class FindAllQuery<T extends PersistentRecord>
|
||||
new KeySet<T>(_type, keys)));
|
||||
PreparedStatement stmt = _builder.prepare(conn);
|
||||
try {
|
||||
Set<Key<T>> got = new HashSet<Key<T>>();
|
||||
Set<Key<T>> got = Sets.newHashSet();
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
int cnt = 0, dups = 0;
|
||||
while (rs.next()) {
|
||||
|
||||
@@ -23,10 +23,12 @@ package com.samskivert.depot;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||
import com.samskivert.depot.expression.SQLExpression;
|
||||
import com.samskivert.util.StringUtil;
|
||||
@@ -104,7 +106,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
||||
_pClass = pClass;
|
||||
|
||||
// build a local map of field name -> field value
|
||||
Map<String, Comparable<?>> map = new HashMap<String, Comparable<?>>();
|
||||
Map<String, Comparable<?>> map = Maps.newHashMap();
|
||||
for (int i = 0; i < fields.length; i ++) {
|
||||
map.put(fields[i], values[i]);
|
||||
}
|
||||
@@ -113,7 +115,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
||||
String[] keyFields = KeyUtil.getKeyFields(pClass);
|
||||
|
||||
// now extract the values in field order and ensure none are extra or missing
|
||||
_values = new ArrayList<Comparable<?>>();
|
||||
_values = Lists.newArrayList();
|
||||
for (int ii = 0; ii < keyFields.length; ii++) {
|
||||
Comparable<?> nugget = map.remove(keyFields[ii]);
|
||||
if (nugget == null) {
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
package com.samskivert.depot;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.depot.annotation.Id;
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,7 @@ public class KeyUtil
|
||||
{
|
||||
String[] fields = _keyFields.get(pClass);
|
||||
if (fields == null) {
|
||||
List<String> kflist = new ArrayList<String>();
|
||||
List<String> kflist = Lists.newArrayList();
|
||||
for (Field field : pClass.getFields()) {
|
||||
// look for @Id fields
|
||||
if (field.getAnnotation(Id.class) != null) {
|
||||
@@ -55,5 +56,5 @@ public class KeyUtil
|
||||
|
||||
/** A (never expiring) cache of primary key field names for all persistent classes (of which
|
||||
* there are merely dozens, so we don't need to worry about expiring). */
|
||||
protected static Map<Class<?>,String[]> _keyFields = new HashMap<Class<?>,String[]>();
|
||||
protected static Map<Class<?>,String[]> _keyFields = Maps.newHashMap();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.depot.clause.Where;
|
||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||
import com.samskivert.depot.expression.SQLExpression;
|
||||
@@ -76,7 +78,7 @@ public class MultiKey<T extends PersistentRecord> extends WhereClause
|
||||
_pClass = pClass;
|
||||
_mField = mField;
|
||||
_mValues = mValues;
|
||||
_map = new HashMap<String, Comparable<?>>();
|
||||
_map = Maps.newHashMap();
|
||||
for (int i = 0; i < sFields.length; i ++) {
|
||||
_map.put(sFields[i], sValues[i]);
|
||||
}
|
||||
@@ -134,9 +136,10 @@ public class MultiKey<T extends PersistentRecord> extends WhereClause
|
||||
// from CacheInvalidator
|
||||
public void invalidate (PersistenceContext ctx)
|
||||
{
|
||||
HashMap<String, Comparable<?>> newMap = new HashMap<String, Comparable<?>>(_map);
|
||||
for (int i = 0; i < _mValues.length; i ++) {
|
||||
newMap.put(_mField, _mValues[i]);
|
||||
// must be a hashmap for serializability
|
||||
HashMap<String, Comparable<?>> newMap = Maps.newHashMap(_map);
|
||||
for (Comparable<?> value : _mValues) {
|
||||
newMap.put(_mField, value);
|
||||
ctx.cacheInvalidate(new SimpleCacheKey(_pClass, newMap));
|
||||
}
|
||||
}
|
||||
@@ -151,5 +154,5 @@ public class MultiKey<T extends PersistentRecord> extends WhereClause
|
||||
protected String _mField;
|
||||
protected Comparable<?>[] _mValues;
|
||||
protected Class<T> _pClass;
|
||||
protected HashMap<String, Comparable<?>> _map;
|
||||
protected Map<String, Comparable<?>> _map;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.sql.Timestamp;
|
||||
import java.util.Set;
|
||||
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
|
||||
import com.samskivert.depot.FieldMarshaller.BooleanMarshaller;
|
||||
import com.samskivert.depot.FieldMarshaller.ByteArrayMarshaller;
|
||||
import com.samskivert.depot.FieldMarshaller.ByteEnumMarshaller;
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
|
||||
package com.samskivert.depot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -31,6 +28,10 @@ import java.io.Serializable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.io.PersistenceException;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
@@ -53,7 +54,7 @@ public class PersistenceContext
|
||||
public static final boolean DEBUG = Boolean.getBoolean("com.samskivert.depot.debug");
|
||||
|
||||
/** Map {@link TableGenerator} instances by name. */
|
||||
public HashMap<String, TableGenerator> tableGenerators = new HashMap<String, TableGenerator>();
|
||||
public Map<String, TableGenerator> tableGenerators = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* A cache listener is notified when cache entries change. Its purpose is typically to do
|
||||
@@ -453,7 +454,7 @@ public class PersistenceContext
|
||||
{
|
||||
Set<CacheListener<?>> listenerSet = _listenerSets.get(cacheId);
|
||||
if (listenerSet == null) {
|
||||
listenerSet = new HashSet<CacheListener<?>>();
|
||||
listenerSet = Sets.newHashSet();
|
||||
_listenerSets.put(cacheId, listenerSet);
|
||||
}
|
||||
listenerSet.add(listener);
|
||||
@@ -595,13 +596,11 @@ public class PersistenceContext
|
||||
protected CacheAdapter _cache;
|
||||
|
||||
/** Tracks repositories during the pre-initialization phase. */
|
||||
protected List<DepotRepository> _repositories = new ArrayList<DepotRepository>();
|
||||
protected List<DepotRepository> _repositories = Lists.newArrayList();
|
||||
|
||||
/** A mapping from persistent record class to resolved marshaller. */
|
||||
protected Map<Class<?>, DepotMarshaller<?>> _marshallers =
|
||||
new HashMap<Class<?>, DepotMarshaller<?>>();
|
||||
protected Map<Class<?>, DepotMarshaller<?>> _marshallers = Maps.newHashMap();
|
||||
|
||||
/** A mapping of cache listeners by cache id. */
|
||||
protected Map<String, Set<CacheListener<?>>> _listenerSets =
|
||||
new HashMap<String, Set<CacheListener<?>>>();
|
||||
protected Map<String, Set<CacheListener<?>>> _listenerSets = Maps.newHashMap();
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ import java.util.Set;
|
||||
import com.samskivert.jdbc.DatabaseLiaison;
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
import com.samskivert.jdbc.LiaisonRegistry;
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.samskivert.depot.FieldMarshaller.BooleanMarshaller;
|
||||
import com.samskivert.depot.FieldMarshaller.ByteArrayMarshaller;
|
||||
import com.samskivert.depot.FieldMarshaller.ByteEnumMarshaller;
|
||||
@@ -48,8 +51,6 @@ import com.samskivert.depot.FieldMarshaller.ShortMarshaller;
|
||||
import com.samskivert.depot.annotation.FullTextIndex;
|
||||
import com.samskivert.depot.expression.EpochSeconds;
|
||||
import com.samskivert.depot.operator.Conditionals.FullTextMatch;
|
||||
import com.samskivert.util.ArrayUtil;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import static com.samskivert.Log.log;
|
||||
|
||||
|
||||
@@ -50,10 +50,10 @@ public class SimpleCacheKey
|
||||
/**
|
||||
* Construct a {@link SimpleCacheKey} for the given cache id with the given cache key.
|
||||
*/
|
||||
public SimpleCacheKey (String cacheId, Serializable value)
|
||||
public SimpleCacheKey (String cacheId, Serializable cacheKey)
|
||||
{
|
||||
_cacheId = cacheId;
|
||||
_cacheKey = value;
|
||||
_cacheKey = cacheKey;
|
||||
}
|
||||
|
||||
// from CacheKey
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
|
||||
package com.samskivert.depot.clause;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.samskivert.depot.PersistentRecord;
|
||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||
|
||||
@@ -67,6 +68,5 @@ public class FromOverride extends QueryClause
|
||||
}
|
||||
|
||||
/** The classes of the tables we're selecting from. */
|
||||
protected List<Class<? extends PersistentRecord>> _fromClasses =
|
||||
new ArrayList<Class<? extends PersistentRecord>>();
|
||||
protected List<Class<? extends PersistentRecord>> _fromClasses = Lists.newArrayList();
|
||||
}
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
|
||||
package com.samskivert.depot.clause;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import com.samskivert.depot.PersistentRecord;
|
||||
import com.samskivert.depot.WhereClause;
|
||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||
@@ -195,7 +196,7 @@ public class SelectClause<T extends PersistentRecord> extends QueryClause
|
||||
}
|
||||
|
||||
/** Persistent class fields mapped to field override clauses. */
|
||||
protected Map<String, FieldDefinition> _disMap = new HashMap<String, FieldDefinition>();
|
||||
protected Map<String, FieldDefinition> _disMap = Maps.newHashMap();
|
||||
|
||||
/** The persistent class this select defines. */
|
||||
protected Class<T> _pClass;
|
||||
@@ -210,7 +211,7 @@ public class SelectClause<T extends PersistentRecord> extends QueryClause
|
||||
protected WhereClause _where;
|
||||
|
||||
/** A list of join clauses, each potentially referencing a new class. */
|
||||
protected List<Join> _joinClauses = new ArrayList<Join>();
|
||||
protected List<Join> _joinClauses = Lists.newArrayList();
|
||||
|
||||
/** The order by clause, if any. */
|
||||
protected OrderBy _orderBy;
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.sql.Timestamp;
|
||||
// import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.util.RandomUtil;
|
||||
|
||||
import com.samskivert.jdbc.StaticConnectionProvider;
|
||||
@@ -115,7 +117,7 @@ public class TestRepository extends DepotRepository
|
||||
System.out.println("Now have " + repo.findAll(TestRecord.class).size() + " records.");
|
||||
repo.deleteAll(TestRecord.class, new Where(new LiteralExp("true")));
|
||||
// // TODO: try to break our In() clause
|
||||
// Set<Key<TestRecord>> ids = new HashSet<Key<TestRecord>>();
|
||||
// Set<Key<TestRecord>> ids = Sets.newHashSet();
|
||||
// for (int ii = 1; ii <= Conditionals.In.MAX_KEYS*2+3; ii++) {
|
||||
// ids.add(TestRecord.getKey(ii));
|
||||
// }
|
||||
|
||||
@@ -32,13 +32,14 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Task;
|
||||
@@ -148,7 +149,7 @@ public class GenRecordTask extends Task
|
||||
boolean isAbstract = Modifier.isAbstract(rclass.getModifiers());
|
||||
|
||||
// determine our primary key fields for getKey() generation (if we're not an abstract)
|
||||
List<Field> kflist = new ArrayList<Field>();
|
||||
List<Field> kflist = Lists.newArrayList();
|
||||
if (!isAbstract) {
|
||||
// determine which fields make up our primary key; we'd just use Class.getFields() but
|
||||
// that returns things in a random order whereas ClassUtil returns fields in
|
||||
@@ -162,13 +163,13 @@ public class GenRecordTask extends Task
|
||||
}
|
||||
|
||||
// determine which fields we need to generate constants for
|
||||
List<Field> flist = new ArrayList<Field>();
|
||||
List<Field> flist = Lists.newArrayList();
|
||||
for (Field field : rclass.getFields()) {
|
||||
if (isPersistentField(field)) {
|
||||
flist.add(field);
|
||||
}
|
||||
}
|
||||
Set<Field> declared = new HashSet<Field>();
|
||||
Set<Field> declared = Sets.newHashSet();
|
||||
for (Field field : rclass.getDeclaredFields()) {
|
||||
if (isPersistentField(field)) {
|
||||
declared.add(field);
|
||||
@@ -179,7 +180,7 @@ public class GenRecordTask extends Task
|
||||
String[] lines = null;
|
||||
try {
|
||||
BufferedReader bin = new BufferedReader(new FileReader(source));
|
||||
ArrayList<String> llist = new ArrayList<String>();
|
||||
List<String> llist = Lists.newArrayList();
|
||||
String line = null;
|
||||
while ((line = bin.readLine()) != null) {
|
||||
llist.add(line);
|
||||
@@ -456,7 +457,7 @@ public class GenRecordTask extends Task
|
||||
}
|
||||
|
||||
/** A list of filesets that contain tile images. */
|
||||
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
|
||||
protected List<FileSet> _filesets = Lists.newArrayList();
|
||||
|
||||
/** Used to do our own classpath business. */
|
||||
protected ClassLoader _cloader;
|
||||
|
||||
Reference in New Issue
Block a user