Tighten up a few places where we return null to callers who really never want to see nulls -- throw exceptions instead.

This commit is contained in:
Par Winzell
2007-08-14 17:40:00 +00:00
parent 79024ea85a
commit 4b40140d2d
3 changed files with 21 additions and 20 deletions
@@ -342,10 +342,7 @@ public abstract class BuildVisitor implements ExpressionVisitor
// handle the field-level @Computed annotation, if there is one // handle the field-level @Computed annotation, if there is one
FieldMarshaller fm = _types.getMarshaller(pClass).getFieldMarshaller(field); FieldMarshaller fm = _types.getMarshaller(pClass).getFieldMarshaller(field);
if (fm == null) {
throw new IllegalArgumentException(
"could not find marshaller for field: " + field);
}
Computed fieldComputed = fm.getComputed(); Computed fieldComputed = fm.getComputed();
if (fieldComputed != null) { if (fieldComputed != null) {
// check if the computed field has a literal SQL definition // check if the computed field has a literal SQL definition
@@ -22,7 +22,6 @@ package com.samskivert.jdbc.depot;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -96,7 +95,7 @@ public class DepotTypes
*/ */
public String getTableName (Class<? extends PersistentRecord> cl) public String getTableName (Class<? extends PersistentRecord> cl)
{ {
return _classMap.get(cl).getTableName(); return getMarshaller(cl).getTableName();
} }
/** /**
@@ -107,6 +106,9 @@ public class DepotTypes
public String getTableAbbreviation (Class<? extends PersistentRecord> cl) public String getTableAbbreviation (Class<? extends PersistentRecord> cl)
{ {
if (_useTableAbbreviations) { if (_useTableAbbreviations) {
if (!_classIx.containsKey(cl)) {
throw new RuntimeException("Persistent class not known: " + cl);
}
Integer ix = _classIx.get(cl); Integer ix = _classIx.get(cl);
if (ix == null) { if (ix == null) {
throw new IllegalArgumentException("Unknown persistence class: " + cl); throw new IllegalArgumentException("Unknown persistence class: " + cl);
@@ -118,28 +120,30 @@ public class DepotTypes
/** /**
* Return the associated database column of the given field of the given persistent class, * Return the associated database column of the given field of the given persistent class,
* or null if there is no associated marshaller, or if the field is unknown on the class, or * throwing an exception if the record has not been registered with this object, or if the
* if the field does not directly associate with a column. * field is unknown on the record.
*/ */
public String getColumnName (Class<? extends PersistentRecord> cl, String field) public String getColumnName (Class<? extends PersistentRecord> cl, String field)
{ {
DepotMarshaller dm = getMarshaller(cl); FieldMarshaller<?> fm = getMarshaller(cl).getFieldMarshaller(field);
if (dm != null) { if (fm == null) {
FieldMarshaller<?> fm = dm.getFieldMarshaller(field); throw new RuntimeException(
if (fm != null) { "Field not known on class [field=" + field + ", class=" + cl + "]");
return fm.getColumnName();
}
} }
return null; return fm.getColumnName();
} }
/** /**
* Return the {@link DepotMarshaller} associated with the given persistent class, or null * Return the {@link DepotMarshaller} associated with the given persistent class, if it's
* if the class has not been previously registered with this object. * been registered with this object, otherwise throw an exception.
*/ */
public DepotMarshaller getMarshaller (Class<? extends PersistentRecord> cl) public DepotMarshaller getMarshaller (Class<? extends PersistentRecord> cl)
{ {
return _classMap.get(cl); DepotMarshaller marsh = _classMap.get(cl);
if (marsh == null) {
throw new RuntimeException("Persistent class not known: " + cl);
}
return marsh;
} }
/** /**
@@ -61,8 +61,8 @@ public class MySQLBuilder
{ {
_builder.append("match("); _builder.append("match(");
Class<? extends PersistentRecord> pClass = match.getPersistentRecord(); Class<? extends PersistentRecord> pClass = match.getPersistentRecord();
FullTextIndex fts = _types.getMarshaller(pClass).getFullTextIndex(match.getName()); String[] fields =
String[] fields = fts.fieldNames(); _types.getMarshaller(pClass).getFullTextIndex(match.getName()).fieldNames();
for (int ii = 0; ii < fields.length; ii ++) { for (int ii = 0; ii < fields.length; ii ++) {
if (ii > 0) { if (ii > 0) {
_builder.append(", "); _builder.append(", ");