Skip to content

Conversation

schauder
Copy link
Contributor

When loading the referenced entities get loaded by a separate select statement.
Changes to a collection get handled just like 1-1 relationships by deleting all and reinserting them again.

Introduced a separate method in JdbcPersistentProperty instead of just using the table name, although it currently still is the table name.

Now providing SqlTypes in SqlParameterSource, since MySql has a problem with null parameters when it doesn't know the type.

Fixed an error where a SQL-statement generated by the SqlGenerator was obviously wrong.

When loading the referenced entities get loaded by a separate select statement.
Changes to a collection get handled just like 1-1 relationships by deleting all and reinserting them again.

Introduced a separate method in JdbcPersistentProperty instead of just unsing the table name, although it currently still is the table name.

Now providing SqlTypes in SqlParameterSource, since MySql has a problem with null parameters when it doesn't know the type.

Fixed an error where a SQL-statement generated by the SqlGenerator was obviously wrong.
Copy link
Contributor

@gregturn gregturn left a comment

Choose a reason for hiding this comment

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

All in all, I found this PR quite enjoyable to read. The polishing of existing code really improved things.

private final JdbcPersistentProperty idProperty;

@java.beans.ConstructorProperties({ "entity", "conversions", "context", "template" })
public EntityRowMapper(JdbcPersistentEntity<T> entity, ConversionService conversions, JdbcMappingContext context,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does @ConstructorProperties do for you? I read the javadocs, and didn't get it. I commented out both usages, and all the test cases still passed, so ??? to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question /head scratch/ I thought Olli introduced that at some point, but he didn't. At least not in this class. It might be that lombok created it when delomboking the code.

Anyway I agree: It seems to superfluous and will remove it.

@NonNull private final String prefix;

@java.beans.ConstructorProperties({ "resultSet", "conversionService", "prefix" })
private ResultSetParameterValueProvider(ResultSet resultSet, ConversionService conversionService, String prefix) {
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment.


String tableColumns = String.join(", ", propertyNamesForInsert);
String parameterNames = propertyNamesForInsert.stream().collect(Collectors.joining(", :", ":", ""));

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Nice polishing there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thx


Class<?> type = p.getType();
if (Collection.class.isAssignableFrom(type))
return collectionPropertyAsStream(p, propertyAccessor);
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer wrapping these single line statements with braces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

if (Collection.class.isAssignableFrom(type))
return collectionPropertyAsStream(p, propertyAccessor);

return singlePropertyAsStream(p, propertyAccessor);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't know if it's just me, but I prefer wrapping this bare return statement in an else so it's clear its part of the previous statement, and nothing can sneak in in the future accidentally breaking the semantics of this either/or outcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually disagree on this one. With the final 'return' I find it much easier to see that the bucket stops here.

I'll poll the team to see if we have a de facto style guide for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nobody seems to have a strong opinion but the single return statement seems to be preferred.

Olli pointed out the ternary operator as an alternative for single returns and I like that even more. So I want with that here and in the following instance.

return Stream.empty();
}

return ((Collection<Object>) property).stream();
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment.

public class JdbcUtil {

private static final Map<Class, Integer> sqlTypeMappings = new HashMap<>();

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the key type be Class<?>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I thought about that and came to the conclusion that Class<?> would mean that there is a single unnamed type ? that applies to all keys. But the keys are obvious of type Class<T> with a different T for each key so Class is actually the best type we can correctly specify.

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some tests and seems like you are right and I'm confused :-/ https://stackoverflow.com/q/46050311/66686

}

public static int sqlTypeFor(Class type) {
return sqlTypeMappings.keySet().stream() //
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment.


private Object getObject(String column) {

return values.get(index).get(column);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think you need the extra blank line here.

Applied changes from review.
Removed superfluous @ConstructorProperties annotations.
Fixed formatting.
Improved usage of generics.
@gregturn gregturn closed this Sep 13, 2017
@gregturn gregturn deleted the issue/DATAJDBC-113 branch September 13, 2017 14:33
@gregturn
Copy link
Contributor

Resolves via 9b7b126 and fd2ae05

mp911de added a commit that referenced this pull request Feb 21, 2022
We now expose a bind marker API that allows to model a vendor-specific bind marker strategy. The currently supported database systems (Postgres, MsSql) implement indexed respective named strategies that differ in how placeholders and identifiers are generated.

Original pull request: #19.
mp911de added a commit that referenced this pull request Feb 21, 2022
Improve Javadoc. Rename parameters for more expressiveness. Replace ASCII filtering with filter Function to move actual filtering into dialects.

Original pull request: #19.
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