Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

samuellush
Copy link

No description provided.

@samuellush samuellush changed the title changes added back to persist branch ENG-5818vPersistOnly added optionals Jul 18, 2018
@samuellush samuellush requested a review from kwburgess July 18, 2018 00:03
@@ -115,6 +116,8 @@ public AnnotationTableMapping(final Class<?> objectClass) {
notAutoGeneratedColumns = toArray(notAutoGeneratedColumnsList);
autoGeneratedColumns = toArray(autoGeneratedColumnsList);

// TODO: implement optional

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) {

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) {

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) {

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);

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);

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);

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -1031,8 +1045,8 @@ else if (type == 100) {
}

// for beans
// TODO optional

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment?

final Object value = getValueFromResultSet(resultSet, i, type);
final Class<?> optionalSubType = mapping.getOptionalSubType(columnName);

// figure out these exception texts

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remov e comment?

// figure out these exception texts
if ((type == Optional.class) && (optionalSubType == Void.class)) {
throw new PersistException(
"Column [" + columnName + "] was Optional but optionalSubType was Void.class");

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");

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.

Copy link

@kwburgess kwburgess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 w/ comments

@samuellush
Copy link
Author

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

@samuellush samuellush requested a review from kwburgess July 20, 2018 21:38
}
return getterForFieldName.get();
}
return null;

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use case?

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;

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;

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 + "]");
Copy link

@kwburgess kwburgess Jul 20, 2018

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;

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 + "]");

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants