-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENG-5818vPersistOnly added optionals #1
base: master
Are you sure you want to change the base?
Conversation
@@ -115,6 +116,8 @@ public AnnotationTableMapping(final Class<?> objectClass) { | |||
notAutoGeneratedColumns = toArray(notAutoGeneratedColumnsList); | |||
autoGeneratedColumns = toArray(autoGeneratedColumnsList); | |||
|
|||
// TODO: implement optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
@@ -197,13 +200,27 @@ public String getTableName() { | |||
@Override | |||
public Method getGetterForColumn(final String columnName) { | |||
final String fieldName = columnsMap.get(columnName.toLowerCase(Locale.ENGLISH)); | |||
return gettersMap.get(fieldName); | |||
if (fieldName == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do the if check log + catch a guaranteed NPE if the if check is true?
Wrap fieldName in Optional<>, do an "if present" check and throw an exception if it isn't. otherwise, return as normal. (e.g. no log needed, no try catch)
} | ||
|
||
@Override | ||
public Method getSetterForColumn(final String columnName) { | ||
final String fieldName = columnsMap.get(columnName.toLowerCase(Locale.ENGLISH)); | ||
return settersMap.get(fieldName); | ||
if (fieldName == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@Override | ||
public Class<?> getOptionalSubType(final String columnName) { | ||
final String fieldName = columnsMap.get(columnName.toLowerCase(Locale.ENGLISH)); | ||
if (fieldName == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
ENGINE_LOG.warn("Could not find field name corresponding to column name [" + columnName + "]"); | ||
} | ||
try { | ||
return gettersMap.get(fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed what you were trying to do here, wrap in an optional and throw a different persist exception for the inner map.
love the foresight for error cases!
@@ -114,7 +116,11 @@ public String getFieldNameForColumn(String columnName) { | |||
@Override | |||
public Method getSetterForColumn(String columnName) { | |||
String fieldName = getFieldNameForColumn(columnName); | |||
return settersMap.get(fieldName); | |||
try { | |||
return settersMap.get(fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -126,7 +132,22 @@ public Method getSetterForColumn(String columnName) { | |||
@Override | |||
public Method getGetterForColumn(String columnName) { | |||
String fieldName = getFieldNameForColumn(columnName); | |||
return gettersMap.get(fieldName); | |||
try { | |||
return gettersMap.get(fieldName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
public Class<?> getOptionalSubType(String columnName) { | ||
String fieldName = getFieldNameForColumn(columnName); | ||
try { | ||
return annotationsMap.get(fieldName).optionalSubType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
src/main/net/sf/persist/Persist.java
Outdated
@@ -1031,8 +1045,8 @@ else if (type == 100) { | |||
} | |||
|
|||
// for beans | |||
// TODO optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment?
src/main/net/sf/persist/Persist.java
Outdated
final Object value = getValueFromResultSet(resultSet, i, type); | ||
final Class<?> optionalSubType = mapping.getOptionalSubType(columnName); | ||
|
||
// figure out these exception texts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remov e comment?
src/main/net/sf/persist/Persist.java
Outdated
// figure out these exception texts | ||
if ((type == Optional.class) && (optionalSubType == Void.class)) { | ||
throw new PersistException( | ||
"Column [" + columnName + "] was Optional but optionalSubType was Void.class"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's wrong with the void class?
throw new PersistException( | ||
"Column [" + columnName + "] was Optional but optionalSubType was Void.class"); | ||
} else if ((type != Optional.class) && (optionalSubType != Void.class)) { | ||
PARAMETERS_LOG.error("Column type was not Optional but optionalSubType was not Void.class"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is if someone populates "optionalSubType" but doesn't use optional as their main... okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 w/ comments
This doesn't actually work as is. Persist reads in the column names from the table, finds corresponding annotations in the Value class, and maps the getters/setters, but you don't necessarily need every column to be represented in the Value class though with these changes you will get an exception |
} | ||
return getterForFieldName.get(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG.warn - column exists in table that does not have a corresponding getter (or setter below) in the value class, ignoring column.
} | ||
return optSubTypeForFieldName.get(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if field name is not defined, we don't care, so return a null
} | ||
return serializationTypeForFieldName.get(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use case?
} | ||
return writerClassForFieldName.get(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use case?
Optional.ofNullable(annotationsMap.get(fieldName.get()).writerClass()); | ||
if (!writerClassForFieldName.isPresent()) { | ||
throw new NoSuchElementException( | ||
"Could not find writer class for columnn with field name [" + fieldName + "]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
columnn -> column (for this line and above exceptions)
} | ||
return setterForFieldName.get(); | ||
} | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add warn (similar to getter)
final Optional<Method> getterForFieldName = Optional.ofNullable(gettersMap.get(fieldName.get())); | ||
if (!getterForFieldName.isPresent()) { | ||
throw new NoSuchElementException( | ||
"Could not find getter for columnn with field name [" + fieldName + "]"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as above (would love to understand the difference between "No Table Mapping" and "annotation table mapping " in persist library)
No description provided.