More toString()ery. Changed KeyUtil to DepotUtil so I could jam some more
useful stuff in it.
This commit is contained in:
@@ -99,7 +99,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
|
|||||||
public void visit (Key.Expression<? extends PersistentRecord> key)
|
public void visit (Key.Expression<? extends PersistentRecord> key)
|
||||||
{
|
{
|
||||||
Class<? extends PersistentRecord> pClass = key.getPersistentClass();
|
Class<? extends PersistentRecord> pClass = key.getPersistentClass();
|
||||||
String[] keyFields = KeyUtil.getKeyFields(pClass);
|
String[] keyFields = DepotUtil.getKeyFields(pClass);
|
||||||
List<Comparable<?>> values = key.getValues();
|
List<Comparable<?>> values = key.getValues();
|
||||||
for (int ii = 0; ii < keyFields.length; ii ++) {
|
for (int ii = 0; ii < keyFields.length; ii ++) {
|
||||||
if (ii > 0) {
|
if (ii > 0) {
|
||||||
|
|||||||
@@ -78,8 +78,7 @@ public class DepotMarshaller<T extends PersistentRecord>
|
|||||||
_computed = pClass.getAnnotation(Computed.class);
|
_computed = pClass.getAnnotation(Computed.class);
|
||||||
if (_computed == null) {
|
if (_computed == null) {
|
||||||
// if not, this class has a corresponding SQL table
|
// if not, this class has a corresponding SQL table
|
||||||
_tableName = _pClass.getName();
|
_tableName = DepotUtil.justClassName(_pClass);
|
||||||
_tableName = _tableName.substring(_tableName.lastIndexOf(".")+1);
|
|
||||||
|
|
||||||
// see if there are Entity values specified
|
// see if there are Entity values specified
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
|
|||||||
+10
-2
@@ -30,9 +30,9 @@ import com.google.common.collect.Maps;
|
|||||||
import com.samskivert.depot.annotation.Id;
|
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
|
* Returns an array containing the names of the primary key fields for the supplied persistent
|
||||||
@@ -54,6 +54,14 @@ public class KeyUtil
|
|||||||
return fields;
|
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
|
/** 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). */
|
* there are merely dozens, so we don't need to worry about expiring). */
|
||||||
protected static Map<Class<?>,String[]> _keyFields = Maps.newHashMap();
|
protected static Map<Class<?>,String[]> _keyFields = Maps.newHashMap();
|
||||||
@@ -112,7 +112,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
}
|
}
|
||||||
|
|
||||||
// look up the cached primary key fields for this object
|
// 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
|
// now extract the values in field order and ensure none are extra or missing
|
||||||
_values = Lists.newArrayList();
|
_values = Lists.newArrayList();
|
||||||
@@ -204,7 +204,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
*/
|
*/
|
||||||
public void toShortString (StringBuilder builder)
|
public void toShortString (StringBuilder builder)
|
||||||
{
|
{
|
||||||
String[] keyFields = KeyUtil.getKeyFields(_pClass);
|
String[] keyFields = DepotUtil.getKeyFields(_pClass);
|
||||||
for (int ii = 0; ii < keyFields.length; ii ++) {
|
for (int ii = 0; ii < keyFields.length; ii ++) {
|
||||||
if (ii > 0) {
|
if (ii > 0) {
|
||||||
builder.append(":");
|
builder.append(":");
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import com.samskivert.depot.DepotUtil;
|
||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||||
|
|
||||||
@@ -67,6 +68,19 @@ public class FromOverride extends QueryClause
|
|||||||
builder.visit(this);
|
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. */
|
/** The classes of the tables we're selecting from. */
|
||||||
protected List<Class<? extends PersistentRecord>> _fromClasses = Lists.newArrayList();
|
protected List<Class<? extends PersistentRecord>> _fromClasses = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package com.samskivert.depot.clause;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import com.samskivert.depot.DepotUtil;
|
||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.depot.expression.ColumnExp;
|
import com.samskivert.depot.expression.ColumnExp;
|
||||||
import com.samskivert.depot.expression.ExpressionVisitor;
|
import com.samskivert.depot.expression.ExpressionVisitor;
|
||||||
@@ -95,8 +96,7 @@ public class Join extends QueryClause
|
|||||||
@Override // from Object
|
@Override // from Object
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
String jclass = _joinClass.getName();
|
return DepotUtil.justClassName(_joinClass) + ":" + _type + ":" + _joinCondition;
|
||||||
return jclass.substring(jclass.lastIndexOf(".")+1) + ":" + _type + ":" + _joinCondition;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Indicates the type of join to be performed. */
|
/** 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.VelocityContext;
|
||||||
import org.apache.velocity.app.VelocityEngine;
|
import org.apache.velocity.app.VelocityEngine;
|
||||||
|
|
||||||
|
import com.samskivert.depot.DepotUtil;
|
||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.depot.annotation.Id;
|
import com.samskivert.depot.annotation.Id;
|
||||||
import com.samskivert.depot.annotation.Transient;
|
import com.samskivert.depot.annotation.Transient;
|
||||||
@@ -249,8 +250,7 @@ public class GenRecordTask extends Task
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the unqualified class name
|
// get the unqualified class name
|
||||||
String rname = rclass.getName();
|
String rname = DepotUtil.justClassName(rclass);
|
||||||
rname = rname.substring(rname.lastIndexOf(".")+1);
|
|
||||||
|
|
||||||
// generate our fields section
|
// generate our fields section
|
||||||
StringBuilder fsection = new StringBuilder();
|
StringBuilder fsection = new StringBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user