diff --git a/src/main/java/com/samskivert/depot/impl/DepotTypes.java b/src/main/java/com/samskivert/depot/impl/DepotTypes.java index 2034607..6427f58 100644 --- a/src/main/java/com/samskivert/depot/impl/DepotTypes.java +++ b/src/main/java/com/samskivert/depot/impl/DepotTypes.java @@ -150,9 +150,10 @@ 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); + @SuppressWarnings("unchecked") DepotMarshaller marsh = + (DepotMarshaller)_classMap.get(cl); checkArgument(marsh != null, "Persistent class not known: " + cl); return marsh; } diff --git a/src/main/java/com/samskivert/depot/impl/FindAllQuery.java b/src/main/java/com/samskivert/depot/impl/FindAllQuery.java index 909264a..98a8aa1 100644 --- a/src/main/java/com/samskivert/depot/impl/FindAllQuery.java +++ b/src/main/java/com/samskivert/depot/impl/FindAllQuery.java @@ -271,9 +271,10 @@ public abstract class FindAllQuery Iterable clauses) throws DatabaseException { - super(cset.ptype, new ColumnSetQueryMarshaller(ctx, cset), - new NonCloningCloner()); + super(cset.ptype, null, new NonCloningCloner()); _select = new SelectClause(cset.ptype, cset.columns, clauses); + _types = DepotTypes.getDepotTypes(ctx, _select); + _marsh = new ColumnSetQueryMarshaller(cset, _types); } @Override // from Query @@ -286,7 +287,7 @@ public abstract class FindAllQuery public List invoke (PersistenceContext ctx, Connection conn, DatabaseLiaison liaison) throws SQLException { - SQLBuilder builder = ctx.getSQLBuilder(DepotTypes.getDepotTypes(ctx, _select)); + SQLBuilder builder = ctx.getSQLBuilder(_types); builder.newQuery(_select); ResultSet rs = builder.prepare(conn).executeQuery(); List result = Lists.newArrayList(); @@ -297,26 +298,19 @@ public abstract class FindAllQuery } protected SelectClause _select; + protected DepotTypes _types; } protected static class ColumnSetQueryMarshaller implements QueryMarshaller { - public ColumnSetQueryMarshaller (PersistenceContext ctx, ColumnSet cset) { + public ColumnSetQueryMarshaller (ColumnSet cset, DepotTypes types) { _cset = cset; - _cmarsh = ctx.getMarshaller(cset.ptype); - _marshes = Maps.newHashMap(); - _marshes.put(cset.ptype, _cmarsh); - for (ColumnExp cexp : cset.columns) { - Class cclass = cexp.getPersistentClass(); - if (!_marshes.containsKey(cclass)) { - _marshes.put(cclass, ctx.getMarshaller(cexp.getPersistentClass())); - } - } + _types = types; } public String getTableName () { - return _cmarsh.getTableName(); + return _types.getTableName(_cset.ptype); } public ColumnExp[] getFieldNames () { @@ -324,22 +318,21 @@ public abstract class FindAllQuery } public Key getPrimaryKey (Object object) { - return _cmarsh.getPrimaryKey(object); + return _types.getMarshaller(_cset.ptype).getPrimaryKey(object); } public R createObject (ResultSet rs) throws SQLException { Object[] data = new Object[_cset.columns.length]; for (int ii = 0; ii < data.length; ii++) { ColumnExp col = _cset.columns[ii]; - data[ii] = _marshes.get(col.getPersistentClass()). + data[ii] = _types.getMarshaller(col.getPersistentClass()). getFieldMarshaller(col.name).getFromSet(rs, ii+1); } return _cset.createObject(data); } protected ColumnSet _cset; - protected DepotMarshaller _cmarsh; - protected Map, DepotMarshaller> _marshes; + protected DepotTypes _types; } // from Query