From 4b40140d2de946e8ad7b096450df9fccadab882c Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Tue, 14 Aug 2007 17:40:00 +0000 Subject: [PATCH] Tighten up a few places where we return null to callers who really never want to see nulls -- throw exceptions instead. --- .../samskivert/jdbc/depot/BuildVisitor.java | 5 +-- .../com/samskivert/jdbc/depot/DepotTypes.java | 32 +++++++++++-------- .../samskivert/jdbc/depot/MySQLBuilder.java | 4 +-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/BuildVisitor.java b/src/java/com/samskivert/jdbc/depot/BuildVisitor.java index 2e0e675..def7dd1 100644 --- a/src/java/com/samskivert/jdbc/depot/BuildVisitor.java +++ b/src/java/com/samskivert/jdbc/depot/BuildVisitor.java @@ -342,10 +342,7 @@ public abstract class BuildVisitor implements ExpressionVisitor // handle the field-level @Computed annotation, if there is one FieldMarshaller fm = _types.getMarshaller(pClass).getFieldMarshaller(field); - if (fm == null) { - throw new IllegalArgumentException( - "could not find marshaller for field: " + field); - } + Computed fieldComputed = fm.getComputed(); if (fieldComputed != null) { // check if the computed field has a literal SQL definition diff --git a/src/java/com/samskivert/jdbc/depot/DepotTypes.java b/src/java/com/samskivert/jdbc/depot/DepotTypes.java index 620ae9a..7c0920f 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotTypes.java +++ b/src/java/com/samskivert/jdbc/depot/DepotTypes.java @@ -22,7 +22,6 @@ package com.samskivert.jdbc.depot; import java.sql.SQLException; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -96,7 +95,7 @@ public class DepotTypes */ public String getTableName (Class cl) { - return _classMap.get(cl).getTableName(); + return getMarshaller(cl).getTableName(); } /** @@ -107,6 +106,9 @@ public class DepotTypes public String getTableAbbreviation (Class cl) { if (_useTableAbbreviations) { + if (!_classIx.containsKey(cl)) { + throw new RuntimeException("Persistent class not known: " + cl); + } Integer ix = _classIx.get(cl); if (ix == null) { 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, - * or null if there is no associated marshaller, or if the field is unknown on the class, or - * if the field does not directly associate with a column. + * throwing an exception if the record has not been registered with this object, or if the + * field is unknown on the record. */ public String getColumnName (Class cl, String field) { - DepotMarshaller dm = getMarshaller(cl); - if (dm != null) { - FieldMarshaller fm = dm.getFieldMarshaller(field); - if (fm != null) { - return fm.getColumnName(); - } + FieldMarshaller fm = getMarshaller(cl).getFieldMarshaller(field); + if (fm == null) { + throw new RuntimeException( + "Field not known on class [field=" + field + ", class=" + cl + "]"); } - return null; + return fm.getColumnName(); } /** - * Return the {@link DepotMarshaller} associated with the given persistent class, or null - * if the class has not been previously registered with this object. + * Return the {@link DepotMarshaller} associated with the given persistent class, if it's + * been registered with this object, otherwise throw an exception. */ public DepotMarshaller getMarshaller (Class cl) { - return _classMap.get(cl); + DepotMarshaller marsh = _classMap.get(cl); + if (marsh == null) { + throw new RuntimeException("Persistent class not known: " + cl); + } + return marsh; } /** diff --git a/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java b/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java index 1425b0d..6a0daba 100644 --- a/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java +++ b/src/java/com/samskivert/jdbc/depot/MySQLBuilder.java @@ -61,8 +61,8 @@ public class MySQLBuilder { _builder.append("match("); Class pClass = match.getPersistentRecord(); - FullTextIndex fts = _types.getMarshaller(pClass).getFullTextIndex(match.getName()); - String[] fields = fts.fieldNames(); + String[] fields = + _types.getMarshaller(pClass).getFullTextIndex(match.getName()).fieldNames(); for (int ii = 0; ii < fields.length; ii ++) { if (ii > 0) { _builder.append(", ");