Skip to content

Commit

Permalink
Using PersistException for all Persist-generated exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
r5v9 committed Sep 1, 2007
1 parent 1d32b91 commit b99ee63
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 50 deletions.
12 changes: 6 additions & 6 deletions persist/src/main/net/sf/persist/Mapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static final Mapping getMapping(final DatabaseMetaData metaData, final Cl
try {
return new TableMapping(metaData, objectClass, nameGuesser);
} catch (SQLException e) {
throw new RuntimeSQLException(e);
throw new PersistException(e);
}
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ protected static final Map[] getFieldsMaps(final Class objectClass) {
// check conflicting NoColumn and Column annotations
if (noPersistGetter != null || noPersistSetter != null) {
if (getterAnnotation != null || setterAnnotation != null) {
throw new RuntimeSQLException("Field [" + fieldName + "] from class [" + objectClass.getName()
throw new PersistException("Field [" + fieldName + "] from class [" + objectClass.getName()
+ "] has conflicting NoColumn and Column annotations");
}
continue;
Expand All @@ -113,14 +113,14 @@ protected static final Map[] getFieldsMaps(final Class objectClass) {
// assert that getters and setters have valid and compatible
// types
if (getterSetter[1].getParameterTypes().length != 1) {
throw new RuntimeSQLException("Setter [" + getterSetter[1]
throw new PersistException("Setter [" + getterSetter[1]
+ "] should have a single parameter but has " + getterSetter[1].getParameterTypes().length);
}
if (getterSetter[0].getReturnType() == void.class) {
throw new RuntimeSQLException("Getter [" + getterSetter[0] + "] must have a return parameter");
throw new PersistException("Getter [" + getterSetter[0] + "] must have a return parameter");
}
if (getterSetter[0].getReturnType() != getterSetter[1].getParameterTypes()[0]) {
throw new RuntimeSQLException("Getter [" + getterSetter[0] + "] and setter [" + getterSetter[1]
throw new PersistException("Getter [" + getterSetter[0] + "] and setter [" + getterSetter[1]
+ "] have incompatible types");
}

Expand All @@ -141,7 +141,7 @@ protected static final Map[] getFieldsMaps(final Class objectClass) {
setterAnnotation.toString().indexOf('(') + 1,
setterAnnotation.toString().lastIndexOf(')'));

throw new RuntimeSQLException("Annotations for getter [" + getterSetter[0] + "] and setter ["
throw new PersistException("Annotations for getter [" + getterSetter[0] + "] and setter ["
+ getterSetter[1] + "] have different annotations [" + getterAnn + "] [" + setterAnn
+ "]");
}
Expand Down
18 changes: 9 additions & 9 deletions persist/src/main/net/sf/persist/NoTableMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public NoTableMapping(Class objectClass, NameGuesser nameGuesser) {
// autoGenerated is not supported on @NoTable mappings
if (annotation != null) {
if (annotation.autoGenerated() == true) {
throw new RuntimeSQLException("@Column(autoGenerated=true) is set for field [" + fieldName
throw new PersistException("@Column(autoGenerated=true) is set for field [" + fieldName
+ "] of class [" + objectClass.getCanonicalName()
+ " which has been declared with @NoTable");
}
Expand All @@ -64,7 +64,7 @@ public NoTableMapping(Class objectClass, NameGuesser nameGuesser) {

// check if the column name is blank
if (annotation.name().trim().equals("")) {
throw new RuntimeSQLException("@Column annotation for field [" + fieldName + "] of class ["
throw new PersistException("@Column annotation for field [" + fieldName + "] of class ["
+ objectClass.getCanonicalName() + "] defines a blank column name");
}

Expand Down Expand Up @@ -93,12 +93,12 @@ public NoTableMapping(Class objectClass, NameGuesser nameGuesser) {

/**
* Returns the field name associated with a given column. If a mapping can't
* be found, will throw a RuntimeSQLException.
* be found, will throw a PersistException.
*/
public String getFieldNameForColumn(String columnName) {
String fieldName = columnsMap.get(columnName);
if (fieldName == null) {
throw new RuntimeSQLException("Could map field for column [" + columnName + "] on class ["
throw new PersistException("Could map field for column [" + columnName + "] on class ["
+ objectClass.getCanonicalName()
+ "]. Please specify an explict @Column annotation for that column.");
}
Expand All @@ -107,7 +107,7 @@ public String getFieldNameForColumn(String columnName) {

/**
* Returns the setter method associated with a given column. If a mapping
* can't be found, will throw a RuntimeSQLException.
* can't be found, will throw a PersistException.
*
* @see Mapping
*/
Expand All @@ -118,7 +118,7 @@ public Method getSetterForColumn(String columnName) {

/**
* Returns the getter method associated with a given column. If a mapping
* can't be found, will throw a RuntimeSQLException.
* can't be found, will throw a PersistException.
*
* @see Mapping
*/
Expand All @@ -134,7 +134,7 @@ public Method getGetterForColumn(String columnName) {
private void checkNameConflicts(String fieldName, String column) {
String existingFieldName = columnsMap.get(column);
if (existingFieldName != null) {
throw new RuntimeSQLException("Fields [" + fieldName + "] and [" + existingFieldName
throw new PersistException("Fields [" + fieldName + "] and [" + existingFieldName
+ "] have conflicting column name [" + column
+ "] either from guessed names or anotations. "
+ "Please specify @Column mappings for at least one of those fields");
Expand All @@ -153,7 +153,7 @@ private void checkAnnotation(Class objectClass) {

// check if annotation is set
if (noTableAnnotation == null) {
throw new RuntimeSQLException("Class [" + objectClass.getCanonicalName()
throw new PersistException("Class [" + objectClass.getCanonicalName()
+ "] does not specify a @NoTable annotation therefore it can't be mapped through NoTableMapping");
}

Expand All @@ -162,7 +162,7 @@ private void checkAnnotation(Class objectClass) {
.getAnnotation(net.sf.persist.annotations.Table.class);

if (tableAnnotation != null) {
throw new RuntimeSQLException("Class [" + objectClass.getCanonicalName()
throw new PersistException("Class [" + objectClass.getCanonicalName()
+ "] specifies conflicting @Table and @NoTable annotations");
}
}
Expand Down
Loading

0 comments on commit b99ee63

Please sign in to comment.