Skip to content

Commit 5fc2f82

Browse files
committed
Consistently apply final modifier to methods and constructor parameters.
Add simple JavaDoc to JdbcConnector class. Minor style changes to éxecuteQuery code block.
1 parent a61858b commit 5fc2f82

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

javasource/databaseconnector/impl/JdbcConnector.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,46 @@
2222
import databaseconnector.interfaces.ConnectionManager;
2323
import databaseconnector.interfaces.ObjectInstantiator;
2424

25+
/**
26+
* JdbcConnector implements the execute query (and execute statement) functionality, and returns a {@link Stream} of {@link IMendixObject}s.
27+
*/
2528
public class JdbcConnector {
2629
private final ILogNode logNode;
27-
private ObjectInstantiator objectInstantiator;
28-
private ConnectionManager connectionManager;
30+
private final ObjectInstantiator objectInstantiator;
31+
private final ConnectionManager connectionManager;
2932

30-
public JdbcConnector(final ILogNode logNode, ObjectInstantiator objectInstantiator, ConnectionManager connectionManager) {
33+
public JdbcConnector(final ILogNode logNode, final ObjectInstantiator objectInstantiator, final ConnectionManager connectionManager) {
3134
this.logNode = logNode;
3235
this.objectInstantiator = objectInstantiator;
3336
this.connectionManager = connectionManager;
3437
}
3538

36-
public JdbcConnector(ILogNode logNode) {
39+
public JdbcConnector(final ILogNode logNode) {
3740
this(logNode, new ObjectInstantiatorImpl(), ConnectionManagerSingleton.getInstance());
3841
}
3942

40-
public Stream<IMendixObject> executeQuery(String jdbcUrl, String userName, String password, IMetaObject metaObject, String sql,
41-
IContext context) throws SQLException {
43+
public Stream<IMendixObject> executeQuery(final String jdbcUrl, final String userName, final String password, final IMetaObject metaObject, final String sql,
44+
final IContext context) throws SQLException {
4245
String entityName = metaObject.getName();
46+
4347
Function<Map<String, Optional<Object>>, IMendixObject> toMendixObject = columns -> {
44-
4548
IMendixObject obj = objectInstantiator.instantiate(context, entityName);
49+
4650
BiConsumer<String, Optional<Object>> setMemberValue = (name, value) -> {
47-
PrimitiveType primitiveType = metaObject.getMetaPrimitive(name).getType();
48-
// convert to suitable value
49-
Function<Object, Object> toSuitableValue = toSuitableValue(primitiveType);
51+
PrimitiveType type = metaObject.getMetaPrimitive(name).getType();
52+
// convert to suitable value (different for Binary type)
53+
Function<Object, Object> toSuitableValue = toSuitableValue(type);
5054
// for Boolean type, convert null to false
51-
Supplier<Object> defaultValue = () -> primitiveType == PrimitiveType.Boolean ? Boolean.FALSE : null;
55+
Supplier<Object> defaultValue = () -> type == PrimitiveType.Boolean ? Boolean.FALSE : null;
5256
// apply two functions declared above
5357
Object convertedValue = value.map(toSuitableValue).orElseGet(defaultValue);
5458
// update object with converted value
55-
if (primitiveType == PrimitiveType.HashString)
59+
if (type == PrimitiveType.HashString)
5660
((MendixHashString) obj.getMember(context, name)).setInitialHash((String) convertedValue);
5761
else
5862
obj.setValue(context, name, convertedValue);
5963
};
64+
6065
columns.forEach(setMemberValue);
6166
logNode.trace("Instantiated object: " + obj);
6267
return obj;
@@ -69,7 +74,7 @@ private Function<Object, Object> toSuitableValue(final PrimitiveType type) {
6974
return v -> type == PrimitiveType.Binary ? new ByteArrayInputStream((byte[]) v) : v;
7075
}
7176

72-
public Stream<Map<String, Optional<Object>>> executeQuery(String jdbcUrl, String userName, String password, IMetaObject metaObject, String sql) throws SQLException {
77+
private Stream<Map<String, Optional<Object>>> executeQuery(final String jdbcUrl, final String userName, final String password, final IMetaObject metaObject, final String sql) throws SQLException {
7378
logNode.trace(String.format("executeQuery: %s, %s, %s", jdbcUrl, userName, sql));
7479

7580
try (Connection connection = connectionManager.getConnection(jdbcUrl, userName, password);
@@ -81,7 +86,7 @@ public Stream<Map<String, Optional<Object>>> executeQuery(String jdbcUrl, String
8186
}
8287
}
8388

84-
public long executeStatement(String jdbcUrl, String userName, String password, String sql) throws SQLException {
89+
public long executeStatement(final String jdbcUrl, final String userName, final String password, final String sql) throws SQLException {
8590
logNode.trace(String.format("executeStatement: %s, %s, %s", jdbcUrl, userName, sql));
8691

8792
try (Connection connection = connectionManager.getConnection(jdbcUrl, userName, password);

javasource/databaseconnector/impl/ObjectInstantiatorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class ObjectInstantiatorImpl implements ObjectInstantiator {
1010

1111
@Override
12-
public IMendixObject instantiate(IContext context, String entityName) {
12+
public IMendixObject instantiate(final IContext context, final String entityName) {
1313
return Core.instantiate(context, entityName);
1414
}
1515
}

javasource/databaseconnector/impl/ResultSetIterator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* with that, it provides information about columns of the given result set.
2323
*/
2424
public class ResultSetIterator implements Iterator<ResultSet> {
25-
2625
private final ResultSet resultSet;
2726
private final List<ColumnInfo> columnInfos;
2827
private final IMetaObject metaObject;
@@ -43,7 +42,7 @@ private List<ColumnInfo> createColumnInfos(final ResultSet resultSet) {
4342
}
4443
}
4544

46-
private ColumnInfo getColumnInfo(int index) {
45+
private ColumnInfo getColumnInfo(final int index) {
4746
final String columnName;
4847

4948
try {

javasource/databaseconnector/interfaces/ConnectionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import java.sql.SQLException;
55

66
public interface ConnectionManager {
7-
Connection getConnection(String jdbcUrl, String userName, String password) throws SQLException;
7+
Connection getConnection(final String jdbcUrl, final String userName, final String password) throws SQLException;
88
}

javasource/databaseconnector/interfaces/ObjectInstantiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import com.mendix.systemwideinterfaces.core.IMendixObject;
55

66
public interface ObjectInstantiator {
7-
IMendixObject instantiate(IContext context, String entityName);
7+
IMendixObject instantiate(final IContext context, final String entityName);
88
}

0 commit comments

Comments
 (0)