More toString()ery. Changed KeyUtil to DepotUtil so I could jam some more

useful stuff in it.
This commit is contained in:
Michael Bayne
2008-11-21 03:15:47 +00:00
parent e98ad09588
commit e347f4ac17
7 changed files with 32 additions and 11 deletions
@@ -99,7 +99,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
public void visit (Key.Expression<? extends PersistentRecord> key)
{
Class<? extends PersistentRecord> pClass = key.getPersistentClass();
String[] keyFields = KeyUtil.getKeyFields(pClass);
String[] keyFields = DepotUtil.getKeyFields(pClass);
List<Comparable<?>> values = key.getValues();
for (int ii = 0; ii < keyFields.length; ii ++) {
if (ii > 0) {
@@ -78,8 +78,7 @@ public class DepotMarshaller<T extends PersistentRecord>
_computed = pClass.getAnnotation(Computed.class);
if (_computed == null) {
// if not, this class has a corresponding SQL table
_tableName = _pClass.getName();
_tableName = _tableName.substring(_tableName.lastIndexOf(".")+1);
_tableName = DepotUtil.justClassName(_pClass);
// see if there are Entity values specified
if (entity != null) {
@@ -30,9 +30,9 @@ import com.google.common.collect.Maps;
import com.samskivert.depot.annotation.Id;
/**
* Simple utility methods used by {@link Key} and {@link KeySet}.
* Simple utility methods used by various things.
*/
public class KeyUtil
public class DepotUtil
{
/**
* Returns an array containing the names of the primary key fields for the supplied persistent
@@ -54,6 +54,14 @@ public class KeyUtil
return fields;
}
/**
* Returns the name of the supplied class minus its package.
*/
public static String justClassName (Class<?> clazz)
{
return clazz.getName().substring(clazz.getName().lastIndexOf(".")+1);
}
/** 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 = Maps.newHashMap();
+2 -2
View File
@@ -112,7 +112,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
}
// look up the cached primary key fields for this object
String[] keyFields = KeyUtil.getKeyFields(pClass);
String[] keyFields = DepotUtil.getKeyFields(pClass);
// now extract the values in field order and ensure none are extra or missing
_values = Lists.newArrayList();
@@ -204,7 +204,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
*/
public void toShortString (StringBuilder builder)
{
String[] keyFields = KeyUtil.getKeyFields(_pClass);
String[] keyFields = DepotUtil.getKeyFields(_pClass);
for (int ii = 0; ii < keyFields.length; ii ++) {
if (ii > 0) {
builder.append(":");
@@ -25,6 +25,7 @@ import java.util.List;
import com.google.common.collect.Lists;
import com.samskivert.depot.DepotUtil;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ExpressionVisitor;
@@ -67,6 +68,19 @@ public class FromOverride extends QueryClause
builder.visit(this);
}
@Override // from Object
public String toString ()
{
StringBuilder builder = new StringBuilder();
for (Class<? extends PersistentRecord> clazz : _fromClasses) {
if (builder.length() > 0) {
builder.append(", ");
}
builder.append(DepotUtil.justClassName(clazz));
}
return builder.toString();
}
/** The classes of the tables we're selecting from. */
protected List<Class<? extends PersistentRecord>> _fromClasses = Lists.newArrayList();
}
@@ -22,6 +22,7 @@ package com.samskivert.depot.clause;
import java.util.Collection;
import com.samskivert.depot.DepotUtil;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.expression.ColumnExp;
import com.samskivert.depot.expression.ExpressionVisitor;
@@ -95,8 +96,7 @@ public class Join extends QueryClause
@Override // from Object
public String toString ()
{
String jclass = _joinClass.getName();
return jclass.substring(jclass.lastIndexOf(".")+1) + ":" + _type + ":" + _joinCondition;
return DepotUtil.justClassName(_joinClass) + ":" + _type + ":" + _joinCondition;
}
/** Indicates the type of join to be performed. */
@@ -50,6 +50,7 @@ import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import com.samskivert.depot.DepotUtil;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.Transient;
@@ -249,8 +250,7 @@ public class GenRecordTask extends Task
}
// get the unqualified class name
String rname = rclass.getName();
rname = rname.substring(rname.lastIndexOf(".")+1);
String rname = DepotUtil.justClassName(rclass);
// generate our fields section
StringBuilder fsection = new StringBuilder();