More use of Preconditions.
This commit is contained in:
@@ -62,6 +62,7 @@ import com.samskivert.depot.impl.clause.UpdateClause;
|
|||||||
import com.samskivert.depot.impl.expression.ValueExp;
|
import com.samskivert.depot.impl.expression.ValueExp;
|
||||||
import com.samskivert.depot.impl.util.SeqImpl;
|
import com.samskivert.depot.impl.util.SeqImpl;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.samskivert.depot.Log.log;
|
import static com.samskivert.depot.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -275,7 +276,6 @@ public abstract class DepotRepository
|
|||||||
}
|
}
|
||||||
if (cache == CacheStrategy.BEST) {
|
if (cache == CacheStrategy.BEST) {
|
||||||
cache = (reason != null) ? CacheStrategy.NONE : CacheStrategy.SHORT_KEYS;
|
cache = (reason != null) ? CacheStrategy.NONE : CacheStrategy.SHORT_KEYS;
|
||||||
|
|
||||||
} else if (reason != null) {
|
} else if (reason != null) {
|
||||||
// if user explicitly asked for a strategy we can't do, protest
|
// if user explicitly asked for a strategy we can't do, protest
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
@@ -413,9 +413,7 @@ public abstract class DepotRepository
|
|||||||
requireNotComputed(pClass, "update");
|
requireNotComputed(pClass, "update");
|
||||||
DepotMarshaller<? extends PersistentRecord> marsh = _ctx.getMarshaller(pClass);
|
DepotMarshaller<? extends PersistentRecord> marsh = _ctx.getMarshaller(pClass);
|
||||||
Key<? extends PersistentRecord> key = marsh.getPrimaryKey(record);
|
Key<? extends PersistentRecord> key = marsh.getPrimaryKey(record);
|
||||||
if (key == null) {
|
checkArgument(key != null, "Can't update record with null primary key.");
|
||||||
throw new IllegalArgumentException("Can't update record with null primary key.");
|
|
||||||
}
|
|
||||||
return doUpdate(key, new UpdateClause(pClass, key, marsh.getColumnFieldNames(), record));
|
return doUpdate(key, new UpdateClause(pClass, key, marsh.getColumnFieldNames(), record));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,9 +434,7 @@ public abstract class DepotRepository
|
|||||||
requireNotComputed(pClass, "update");
|
requireNotComputed(pClass, "update");
|
||||||
DepotMarshaller<T> marsh = _ctx.getMarshaller(pClass);
|
DepotMarshaller<T> marsh = _ctx.getMarshaller(pClass);
|
||||||
Key<T> key = marsh.getPrimaryKey(record);
|
Key<T> key = marsh.getPrimaryKey(record);
|
||||||
if (key == null) {
|
checkArgument(key != null, "Can't update record with null primary key.");
|
||||||
throw new IllegalArgumentException("Can't update record with null primary key.");
|
|
||||||
}
|
|
||||||
return doUpdate(key, new UpdateClause(pClass, key, modifiedFields, record));
|
return doUpdate(key, new UpdateClause(pClass, key, modifiedFields, record));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,9 +663,7 @@ public abstract class DepotRepository
|
|||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked") Class<T> type = (Class<T>)record.getClass();
|
@SuppressWarnings("unchecked") Class<T> type = (Class<T>)record.getClass();
|
||||||
Key<T> primaryKey = _ctx.getMarshaller(type).getPrimaryKey(record);
|
Key<T> primaryKey = _ctx.getMarshaller(type).getPrimaryKey(record);
|
||||||
if (primaryKey == null) {
|
checkArgument(primaryKey != null, "Can't delete record with null primary key.");
|
||||||
throw new IllegalArgumentException("Can't delete record with null primary key.");
|
|
||||||
}
|
|
||||||
return delete(primaryKey);
|
return delete(primaryKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ import com.samskivert.depot.impl.operator.IsNull;
|
|||||||
import com.samskivert.depot.impl.operator.MultiOperator;
|
import com.samskivert.depot.impl.operator.MultiOperator;
|
||||||
import com.samskivert.depot.impl.operator.Not;
|
import com.samskivert.depot.impl.operator.Not;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.samskivert.Log.log;
|
import static com.samskivert.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -355,10 +356,8 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
}
|
}
|
||||||
_builder.append("select ");
|
_builder.append("select ");
|
||||||
|
|
||||||
if (_definitions.containsKey(pClass)) {
|
checkArgument(!_definitions.containsKey(pClass),
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Can not yet nest SELECTs on the same persistent record.");
|
"Can not yet nest SELECTs on the same persistent record.");
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, FieldDefinition> definitionMap = Maps.newHashMap();
|
Map<String, FieldDefinition> definitionMap = Maps.newHashMap();
|
||||||
for (FieldDefinition definition : selectClause.getFieldDefinitions()) {
|
for (FieldDefinition definition : selectClause.getFieldDefinitions()) {
|
||||||
@@ -444,10 +443,8 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
|
|
||||||
public Void visit (UpdateClause updateClause)
|
public Void visit (UpdateClause updateClause)
|
||||||
{
|
{
|
||||||
if (updateClause.getWhereClause() == null) {
|
checkArgument(updateClause.getWhereClause() != null,
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"I dare not currently perform UPDATE without a WHERE clause.");
|
"I dare not currently perform UPDATE without a WHERE clause.");
|
||||||
}
|
|
||||||
Class<? extends PersistentRecord> pClass = updateClause.getPersistentClass();
|
Class<? extends PersistentRecord> pClass = updateClause.getPersistentClass();
|
||||||
_innerClause = true;
|
_innerClause = true;
|
||||||
|
|
||||||
@@ -785,10 +782,8 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
{
|
{
|
||||||
// TODO: nix type and use the class from the supplied ColumnExp
|
// TODO: nix type and use the class from the supplied ColumnExp
|
||||||
DepotMarshaller<?> dm = _types.getMarshaller(type);
|
DepotMarshaller<?> dm = _types.getMarshaller(type);
|
||||||
if (dm == null) {
|
checkArgument(dm != null, "Unknown field on persistent record [record=%s, field=%s]",
|
||||||
throw new IllegalArgumentException(
|
type, field);
|
||||||
"Unknown field on persistent record [record=" + type + ", field=" + field + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldMarshaller<?> fm = dm.getFieldMarshaller(field.name);
|
FieldMarshaller<?> fm = dm.getFieldMarshaller(field.name);
|
||||||
appendIdentifier(fm.getColumnName());
|
appendIdentifier(fm.getColumnName());
|
||||||
@@ -800,10 +795,8 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
{
|
{
|
||||||
Class<? extends PersistentRecord> type = field.getPersistentClass();
|
Class<? extends PersistentRecord> type = field.getPersistentClass();
|
||||||
DepotMarshaller<?> dm = _types.getMarshaller(type);
|
DepotMarshaller<?> dm = _types.getMarshaller(type);
|
||||||
if (dm == null) {
|
checkArgument(dm != null, "Unknown field on persistent record [record=%s, field=%s]",
|
||||||
throw new IllegalArgumentException(
|
type, field);
|
||||||
"Unknown field on persistent record [record=" + type + ", field=" + field + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
// first, see if there's a field definition
|
// first, see if there's a field definition
|
||||||
FieldMarshaller<?> fm = dm.getFieldMarshaller(field.name);
|
FieldMarshaller<?> fm = dm.getFieldMarshaller(field.name);
|
||||||
@@ -813,15 +806,12 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
if (fieldDef != null) {
|
if (fieldDef != null) {
|
||||||
boolean useOverride;
|
boolean useOverride;
|
||||||
if (fieldDef instanceof FieldOverride) {
|
if (fieldDef instanceof FieldOverride) {
|
||||||
if (fm.getComputed() != null && dm.getComputed() != null) {
|
checkArgument(fm.getComputed() == null || dm.getComputed() == null,
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"FieldOverride cannot be used on @Computed field: " + field);
|
"FieldOverride cannot be used on @Computed field: " + field);
|
||||||
}
|
|
||||||
useOverride = _enableOverrides;
|
useOverride = _enableOverrides;
|
||||||
} else if (fm.getComputed() == null && dm.getComputed() == null) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"FieldDefinition must not be used on concrete field: " + field);
|
|
||||||
} else {
|
} else {
|
||||||
|
checkArgument(fm.getComputed() != null || dm.getComputed() != null,
|
||||||
|
"FieldDefinition must not be used on concrete field: " + field);
|
||||||
useOverride = true;
|
useOverride = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ import com.samskivert.depot.expression.ColumnExp;
|
|||||||
import com.samskivert.depot.expression.SQLExpression;
|
import com.samskivert.depot.expression.SQLExpression;
|
||||||
import com.samskivert.depot.impl.clause.CreateIndexClause;
|
import com.samskivert.depot.impl.clause.CreateIndexClause;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.samskivert.depot.Log.log;
|
import static com.samskivert.depot.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +91,7 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
{
|
{
|
||||||
_pClass = pClass;
|
_pClass = pClass;
|
||||||
|
|
||||||
Preconditions.checkArgument(!java.lang.reflect.Modifier.isAbstract(pClass.getModifiers()),
|
checkArgument(!java.lang.reflect.Modifier.isAbstract(pClass.getModifiers()),
|
||||||
"Can't handle reference to abstract record: " + pClass.getName());
|
"Can't handle reference to abstract record: " + pClass.getName());
|
||||||
|
|
||||||
Entity entity = pClass.getAnnotation(Entity.class);
|
Entity entity = pClass.getAnnotation(Entity.class);
|
||||||
@@ -173,17 +174,13 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
ftype.equals(Short.TYPE) || ftype.equals(Short.class) ||
|
ftype.equals(Short.TYPE) || ftype.equals(Short.class) ||
|
||||||
ftype.equals(Integer.TYPE) || ftype.equals(Integer.class) ||
|
ftype.equals(Integer.TYPE) || ftype.equals(Integer.class) ||
|
||||||
ftype.equals(Long.TYPE) || ftype.equals(Long.class));
|
ftype.equals(Long.TYPE) || ftype.equals(Long.class));
|
||||||
if (!isNumeric) {
|
checkArgument(isNumeric, "Cannot use @GeneratedValue on non-numeric column: %s",
|
||||||
throw new IllegalArgumentException(
|
field.getName());
|
||||||
"Cannot use @GeneratedValue on non-numeric column: " + field.getName());
|
|
||||||
}
|
|
||||||
switch(gv.strategy()) {
|
switch(gv.strategy()) {
|
||||||
case AUTO:
|
case AUTO:
|
||||||
case IDENTITY:
|
case IDENTITY:
|
||||||
if (seenIdentityGenerator) {
|
checkArgument(!seenIdentityGenerator, "Persistent records can have at " +
|
||||||
throw new IllegalArgumentException(
|
"most one AUTO/IDENTITY generator.");
|
||||||
"Persistent records can have at most one AUTO/IDENTITY generator.");
|
|
||||||
}
|
|
||||||
_valueGenerators.put(field.getName(), new IdentityValueGenerator(gv, this, fm));
|
_valueGenerators.put(field.getName(), new IdentityValueGenerator(gv, this, fm));
|
||||||
seenIdentityGenerator = true;
|
seenIdentityGenerator = true;
|
||||||
break;
|
break;
|
||||||
@@ -191,10 +188,7 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
case TABLE:
|
case TABLE:
|
||||||
String name = gv.generator();
|
String name = gv.generator();
|
||||||
generator = context.tableGenerators.get(name);
|
generator = context.tableGenerators.get(name);
|
||||||
if (generator == null) {
|
checkArgument(generator != null, "Unknown generator [generator=" + name + "]");
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown generator [generator=" + name + "]");
|
|
||||||
}
|
|
||||||
_valueGenerators.put(
|
_valueGenerators.put(
|
||||||
field.getName(), new TableValueGenerator(generator, gv, this, fm));
|
field.getName(), new TableValueGenerator(generator, gv, this, fm));
|
||||||
break;
|
break;
|
||||||
@@ -212,12 +206,11 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
Tuple<SQLExpression, Order> entry =
|
Tuple<SQLExpression, Order> entry =
|
||||||
new Tuple<SQLExpression, Order>(fieldColumn, Order.ASC);
|
new Tuple<SQLExpression, Order>(fieldColumn, Order.ASC);
|
||||||
if (index.unique()) {
|
if (index.unique()) {
|
||||||
Preconditions.checkArgument(!namedFieldIndices.containsKey(index.name()),
|
checkArgument(!namedFieldIndices.containsKey(index.name()),
|
||||||
"All @Index for a particular name must be unique or non-unique");
|
"All @Index for a particular name must be unique or non-unique");
|
||||||
uniqueNamedFieldIndices.put(name, entry);
|
uniqueNamedFieldIndices.put(name, entry);
|
||||||
} else {
|
} else {
|
||||||
Preconditions.checkArgument(
|
checkArgument(!uniqueNamedFieldIndices.containsKey(index.name()),
|
||||||
!uniqueNamedFieldIndices.containsKey(index.name()),
|
|
||||||
"All @Index for a particular name must be unique or non-unique");
|
"All @Index for a particular name must be unique or non-unique");
|
||||||
namedFieldIndices.put(name, entry);
|
namedFieldIndices.put(name, entry);
|
||||||
}
|
}
|
||||||
@@ -258,10 +251,7 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
int ii = 0;
|
int ii = 0;
|
||||||
for (String field : constraint.fields()) {
|
for (String field : constraint.fields()) {
|
||||||
FieldMarshaller<?> fm = _fields.get(field);
|
FieldMarshaller<?> fm = _fields.get(field);
|
||||||
if (fm == null) {
|
checkArgument(fm != null, "Unknown unique constraint field: " + field);
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unknown unique constraint field: " + field);
|
|
||||||
}
|
|
||||||
colExps[ii ++] = new ColumnExp<Object>(_pClass, field);
|
colExps[ii ++] = new ColumnExp<Object>(_pClass, field);
|
||||||
}
|
}
|
||||||
_indexes.add(buildIndex(constraint.name(), true, colExps));
|
_indexes.add(buildIndex(constraint.name(), true, colExps));
|
||||||
@@ -338,10 +328,8 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
public FullTextIndex getFullTextIndex (String name)
|
public FullTextIndex getFullTextIndex (String name)
|
||||||
{
|
{
|
||||||
FullTextIndex fti = _fullTextIndexes.get(name);
|
FullTextIndex fti = _fullTextIndexes.get(name);
|
||||||
if (fti == null) {
|
checkArgument(fti != null, "Persistent class missing full text index " +
|
||||||
throw new IllegalStateException("Persistent class missing full text index " +
|
|
||||||
"[class=" + _pClass + ", index=" + name + "]");
|
"[class=" + _pClass + ", index=" + name + "]");
|
||||||
}
|
|
||||||
return fti;
|
return fti;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,10 +474,9 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
Comparable<?>[] values = new Comparable<?>[_pkColumns.size()];
|
Comparable<?>[] values = new Comparable<?>[_pkColumns.size()];
|
||||||
for (int ii = 0; ii < _pkColumns.size(); ii++) {
|
for (int ii = 0; ii < _pkColumns.size(); ii++) {
|
||||||
Object keyValue = _pkColumns.get(ii).getFromSet(rs);
|
Object keyValue = _pkColumns.get(ii).getFromSet(rs);
|
||||||
if (!(keyValue instanceof Comparable<?>)) {
|
checkArgument((keyValue instanceof Comparable<?>),
|
||||||
throw new IllegalArgumentException("Key field must be Comparable<?> [field=" +
|
"Key field must be Comparable<?> [field=%s]",
|
||||||
_pkColumns.get(ii).getColumnName() + "]");
|
_pkColumns.get(ii).getColumnName());
|
||||||
}
|
|
||||||
values[ii] = (Comparable<?>) keyValue;
|
values[ii] = (Comparable<?>) keyValue;
|
||||||
}
|
}
|
||||||
return new Key<T>(_pClass, values);
|
return new Key<T>(_pClass, values);
|
||||||
@@ -999,10 +986,8 @@ public class DepotMarshaller<T extends PersistentRecord> implements QueryMarshal
|
|||||||
String[] columns = new String[fields.length];
|
String[] columns = new String[fields.length];
|
||||||
for (int ii = 0; ii < columns.length; ii ++) {
|
for (int ii = 0; ii < columns.length; ii ++) {
|
||||||
FieldMarshaller<?> fm = _fields.get(fields[ii].name);
|
FieldMarshaller<?> fm = _fields.get(fields[ii].name);
|
||||||
if (fm == null) {
|
checkArgument(fm != null, "Unknown field on record [field=%s, class=%s]",
|
||||||
throw new IllegalArgumentException(
|
fields[ii], _pClass);
|
||||||
"Unknown field on record [field=" + fields[ii] + ", class=" + _pClass + "]");
|
|
||||||
}
|
|
||||||
columns[ii] = fm.getColumnName();
|
columns[ii] = fm.getColumnName();
|
||||||
}
|
}
|
||||||
return columns;
|
return columns;
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import com.samskivert.depot.PersistentRecord;
|
|||||||
import com.samskivert.depot.clause.QueryClause;
|
import com.samskivert.depot.clause.QueryClause;
|
||||||
import com.samskivert.depot.expression.SQLExpression;
|
import com.samskivert.depot.expression.SQLExpression;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintains a record of the persistent classes brought into the context of the associated SQL,
|
* Maintains a record of the persistent classes brought into the context of the associated SQL,
|
||||||
* i.e. any class associated with a concrete table that would appear in FROM or JOIN clauses or as
|
* i.e. any class associated with a concrete table that would appear in FROM or JOIN clauses or as
|
||||||
@@ -121,9 +123,7 @@ public class DepotTypes
|
|||||||
{
|
{
|
||||||
if (_useTableAbbreviations) {
|
if (_useTableAbbreviations) {
|
||||||
Integer ix = _classIx.get(cl);
|
Integer ix = _classIx.get(cl);
|
||||||
if (ix == null) {
|
checkArgument(ix != null, "Unknown persistence class: " + cl);
|
||||||
throw new IllegalArgumentException("Unknown persistence class: " + cl);
|
|
||||||
}
|
|
||||||
return "T" + (ix+1);
|
return "T" + (ix+1);
|
||||||
}
|
}
|
||||||
return getTableName(cl);
|
return getTableName(cl);
|
||||||
@@ -140,10 +140,7 @@ public class DepotTypes
|
|||||||
public String getColumnName (Class<? extends PersistentRecord> cl, String field)
|
public String getColumnName (Class<? extends PersistentRecord> cl, String field)
|
||||||
{
|
{
|
||||||
FieldMarshaller<?> fm = getMarshaller(cl).getFieldMarshaller(field);
|
FieldMarshaller<?> fm = getMarshaller(cl).getFieldMarshaller(field);
|
||||||
if (fm == null) {
|
checkArgument(fm != null, "Field not known on class [field=%s, class=%s]", field, cl);
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Field not known on class [field=" + field + ", class=" + cl + "]");
|
|
||||||
}
|
|
||||||
return fm.getColumnName();
|
return fm.getColumnName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,9 +153,7 @@ public class DepotTypes
|
|||||||
public DepotMarshaller<?> getMarshaller (Class<? extends PersistentRecord> cl)
|
public DepotMarshaller<?> getMarshaller (Class<? extends PersistentRecord> cl)
|
||||||
{
|
{
|
||||||
DepotMarshaller<?> marsh = _classMap.get(cl);
|
DepotMarshaller<?> marsh = _classMap.get(cl);
|
||||||
if (marsh == null) {
|
checkArgument(marsh != null, "Persistent class not known: " + cl);
|
||||||
throw new IllegalArgumentException("Persistent class not known: " + cl);
|
|
||||||
}
|
|
||||||
return marsh;
|
return marsh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import com.samskivert.util.ByteEnumUtil;
|
|||||||
import com.samskivert.util.Logger;
|
import com.samskivert.util.Logger;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the marshalling and unmarshalling of a particular field of a persistent object.
|
* Handles the marshalling and unmarshalling of a particular field of a persistent object.
|
||||||
*
|
*
|
||||||
@@ -91,9 +93,7 @@ public abstract class FieldMarshaller<T>
|
|||||||
|
|
||||||
// finally look for an @Transform annotation on the field type (expensive)
|
// finally look for an @Transform annotation on the field type (expensive)
|
||||||
xform = findTransformAnnotation(field.getType());
|
xform = findTransformAnnotation(field.getType());
|
||||||
if (xform == null) {
|
checkArgument(xform != null, "Cannot marshall " + field + ".");
|
||||||
throw new IllegalArgumentException("Cannot marshall " + field + ".");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -116,12 +116,9 @@ public abstract class FieldMarshaller<T>
|
|||||||
final Transformer<F,T> xformer, Field field, Transform annotation)
|
final Transformer<F,T> xformer, Field field, Transform annotation)
|
||||||
{
|
{
|
||||||
Class<?> pojoType = getTransformerType(xformer, "from");
|
Class<?> pojoType = getTransformerType(xformer, "from");
|
||||||
if (!pojoType.isAssignableFrom(field.getType())) {
|
checkArgument(pojoType.isAssignableFrom(field.getType()),
|
||||||
throw new IllegalArgumentException(
|
"@Transform error on %s.%s: %s cannot convert %s", field.getType().getName(),
|
||||||
"@Transform error on " + field.getType().getName() + "." +
|
field.getName(), xformer.getClass().getName(), field.getType().getName());
|
||||||
field.getName() + ": " + xformer.getClass().getName() + " cannot convert " +
|
|
||||||
field.getType().getName());
|
|
||||||
}
|
|
||||||
xformer.init(field.getGenericType(), annotation);
|
xformer.init(field.getGenericType(), annotation);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") final FieldMarshaller<T> delegate =
|
@SuppressWarnings("unchecked") final FieldMarshaller<T> delegate =
|
||||||
@@ -455,11 +452,8 @@ public abstract class FieldMarshaller<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ttype == null) {
|
checkArgument(ttype != null, "Transformer lacks %sPersistent() method!? [xclass=%s]",
|
||||||
throw new IllegalArgumentException(
|
which, xformer.getClass());
|
||||||
Logger.format("Transformer lacks " + which + "Persistent() method!?",
|
|
||||||
"xclass", xformer.getClass()));
|
|
||||||
}
|
|
||||||
return ttype;
|
return ttype;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,11 +739,9 @@ public abstract class FieldMarshaller<T>
|
|||||||
@Override public void create (Field field) {
|
@Override public void create (Field field) {
|
||||||
super.create(field);
|
super.create(field);
|
||||||
// do some sanity checking so that the unsafe business we do below is safer
|
// do some sanity checking so that the unsafe business we do below is safer
|
||||||
if (!Enum.class.isAssignableFrom(_eclass)) {
|
checkArgument(Enum.class.isAssignableFrom(_eclass),
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"ByteEnum not implemented by real Enum: " + field);
|
"ByteEnum not implemented by real Enum: " + field);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getByteType(length);
|
return typer.getByteType(length);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import com.samskivert.depot.expression.ColumnExp;
|
|||||||
import com.samskivert.depot.impl.operator.In;
|
import com.samskivert.depot.impl.operator.In;
|
||||||
import com.samskivert.jdbc.DatabaseLiaison;
|
import com.samskivert.jdbc.DatabaseLiaison;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.samskivert.depot.Log.log;
|
import static com.samskivert.depot.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,16 +87,12 @@ public abstract class FindAllQuery<T extends PersistentRecord,R>
|
|||||||
{
|
{
|
||||||
super(ctx, type);
|
super(ctx, type);
|
||||||
|
|
||||||
if (_dmarsh.getComputed() != null) {
|
checkArgument(_dmarsh.getComputed() == null,
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"This algorithm doesn't work on @Computed records.");
|
"This algorithm doesn't work on @Computed records.");
|
||||||
}
|
|
||||||
for (QueryClause clause : clauses) {
|
for (QueryClause clause : clauses) {
|
||||||
if (clause instanceof FieldOverride) {
|
checkArgument(!(clause instanceof FieldOverride),
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"This algorithm doesn't work with FieldOverrides.");
|
"This algorithm doesn't work with FieldOverrides.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_select = new SelectClause(_type, _dmarsh.getPrimaryKeyFields(), clauses);
|
_select = new SelectClause(_type, _dmarsh.getPrimaryKeyFields(), clauses);
|
||||||
switch(strategy) {
|
switch(strategy) {
|
||||||
|
|||||||
@@ -289,8 +289,7 @@ public class PostgreSQLBuilder
|
|||||||
case English:
|
case English:
|
||||||
return "pg_catalog.english";
|
return "pg_catalog.english";
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Unknown full text configuration: " + configuration);
|
||||||
"Unknown full text configuration: " + configuration);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import com.samskivert.depot.clause.QueryClause;
|
|||||||
import com.samskivert.jdbc.ColumnDefinition;
|
import com.samskivert.jdbc.ColumnDefinition;
|
||||||
import com.samskivert.util.ByteEnum;
|
import com.samskivert.util.ByteEnum;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static com.samskivert.depot.Log.log;
|
import static com.samskivert.depot.Log.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,9 +76,7 @@ public abstract class SQLBuilder
|
|||||||
public PreparedStatement prepare (Connection conn)
|
public PreparedStatement prepare (Connection conn)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
if (_buildVisitor == null) {
|
checkState(_buildVisitor != null, "Cannot prepare query until it's been built.");
|
||||||
throw new IllegalArgumentException("Cannot prepare query until it's been built.");
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement stmt = conn.prepareStatement(_buildVisitor.getQuery());
|
PreparedStatement stmt = conn.prepareStatement(_buildVisitor.getQuery());
|
||||||
|
|
||||||
@@ -136,10 +136,8 @@ public abstract class SQLBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sanity check nullability
|
// sanity check nullability
|
||||||
if (coldef.nullable && field.getType().isPrimitive()) {
|
checkArgument(!coldef.nullable || !field.getType().isPrimitive(),
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Primitive Java type cannot be nullable [field=" + field.getName() + "]");
|
"Primitive Java type cannot be nullable [field=" + field.getName() + "]");
|
||||||
}
|
|
||||||
|
|
||||||
return coldef;
|
return coldef;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ import com.google.common.collect.Maps;
|
|||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.util.Tuple;
|
import com.samskivert.util.Tuple;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates functions that map persistent records to runtime counterparts and vice versa. A few bits
|
* Creates functions that map persistent records to runtime counterparts and vice versa. A few bits
|
||||||
* of magic are provided to help in mapping from the persistent world to the runtime work. Namely:
|
* of magic are provided to help in mapping from the persistent world to the runtime work. Namely:
|
||||||
@@ -176,12 +178,9 @@ public class RuntimeUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we have no persistent field for the runtime field, we're now out of luck
|
// if we have no persistent field for the runtime field, we're now out of luck
|
||||||
if (pfield == null) {
|
checkArgument(pfield != null,
|
||||||
throw new IllegalArgumentException(
|
"Cannot create mapping for %s. Neither %s.%s nor %s %s() exist.",
|
||||||
"Cannot create mapping for " + rfield + ". Neither " +
|
rfield, pclass.getSimpleName(), rfield.getName(), rfield.getType(), getter);
|
||||||
pclass.getSimpleName() + "." + rfield.getName() + " nor " +
|
|
||||||
rfield.getType() + " " + getter + "() exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the fields match exactly, return a getter that just gets the field
|
// if the fields match exactly, return a getter that just gets the field
|
||||||
if (rfield.getType().equals(pfield.getType())) {
|
if (rfield.getType().equals(pfield.getType())) {
|
||||||
@@ -222,10 +221,8 @@ public class RuntimeUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we have no persistent field for this runtime field, we're now out of luck
|
// if we have no persistent field for this runtime field, we're now out of luck
|
||||||
if (pfield == null) {
|
checkArgument(pfield != null, "Cannot create setter for " + rfield + ". " +
|
||||||
throw new IllegalArgumentException("Cannot create setter for " + rfield + ". " +
|
|
||||||
"No corresponding field exists in " + pclass + ".");
|
"No corresponding field exists in " + pclass + ".");
|
||||||
}
|
|
||||||
|
|
||||||
// if the fields match exactly, return a setter that just sets the field
|
// if the fields match exactly, return a setter that just sets the field
|
||||||
if (rfield.getType().equals(pfield.getType())) {
|
if (rfield.getType().equals(pfield.getType())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user