protected String url = null;
protected String username = null;
protected String password = null;
+ protected boolean localTypesMode = false;
protected MLogListener logListener = null;
protected Connection connection = null;
/* */
- public MDatabaseConnection(String driver, String url, String username, String password, MLogListener logListener) throws MDatabaseConnectionFailureException {
+ public MDatabaseConnection(String driver, String url, String username, String password, boolean localTypesMode, MLogListener logListener) throws MDatabaseConnectionFailureException {
super();
//
if (MText.isBlank(driver)) {
this.url = url;
this.username = username;
this.password = password;
+ this.localTypesMode = localTypesMode;
this.setLogListener(logListener);
// Load driver.
try {
return this.password;
}
+ /* Local types mode. */
+
+ public boolean getLocalTypesMode() {
+ return this.localTypesMode;
+ }
+
/* Connection. */
protected Connection getConnection() {
}
// Execute the statement and parse the results.
preparedStatement.execute();
- results = new MSqlStatementResults(preparedStatement);
+ results = new MSqlStatementResults(preparedStatement, this.getLocalTypesMode());
this.logStatement(preparedStatement.toString());
}
catch (SQLException exception) {
protected String url = null;
protected String username = null;
protected String password = null;
+ protected boolean localTypesMode = false;
protected MLogListener logListener = null;
/* */
- public MDatabaseConnectionGenerator(String driver, String url, String username, String password, MLogListener logListener) {
+ public MDatabaseConnectionGenerator(String driver, String url, String username, String password, boolean localTypesMode, MLogListener logListener) {
super();
//
if (MText.isBlank(driver)) {
this.url = url;
this.username = username;
this.password = password;
+ this.localTypesMode = localTypesMode;
this.setLogListener(logListener);
}
return this.password;
}
+ /* Local types mode. */
+
+ public boolean getLocalTypesMode() {
+ return this.localTypesMode;
+ }
+
/* Log listener. */
public MLogListener getLogListener() {
/* Generator. */
public MDatabaseConnection getNewDatabaseConnection() throws MDatabaseConnectionFailureException {
- return new MDatabaseConnection(this.getDriver(), this.getUrl(), this.getUsername(), this.getPassword(), this.getLogListener());
+ return new MDatabaseConnection(this.getDriver(), this.getUrl(), this.getUsername(), this.getPassword(), this.getLocalTypesMode(), this.getLogListener());
}
public boolean isGeneratorFor(MDatabaseConnection databaseConnection) {
if (!databaseConnection.getPassword().equals(this.getPassword())) {
return false;
}
+ if (databaseConnection.getLocalTypesMode() != this.getLocalTypesMode()) {
+ return false;
+ }
if (databaseConnection.getLogListener() != this.getLogListener()) {
return false;
}
/* */
- public MDatabaseConnectionPool(String driver, String url, String username, String password, int minimumSize, int maximumSize, MLogListener logListener) throws MDatabaseConnectionFailureException {
+ public MDatabaseConnectionPool(String driver, String url, String username, String password, boolean localTypesMode, int minimumSize, int maximumSize, MLogListener logListener) throws MDatabaseConnectionFailureException {
super();
//
if (0 > minimumSize) {
throw new IllegalArgumentException(String.format("Invalid 'maximumSize': %s < %s ('minimumSize').", maximumSize, minimumSize));
}
//
- this.databaseConnectionGenerator = new MDatabaseConnectionGenerator(driver, url, username, password, logListener);
+ this.databaseConnectionGenerator = new MDatabaseConnectionGenerator(driver, url, username, password, localTypesMode, logListener);
this.minimumSize = minimumSize;
this.maximumSize = maximumSize;
//
public class MSqlStatementResults extends MObject {
protected PreparedStatement preparedStatement = null;
+ protected boolean localTypesMode = false;
+
protected ResultSet resultSet = null;
protected LinkedList<LinkedHashMap<String, Object>> records = new LinkedList<LinkedHashMap<String, Object>>();
/* */
- public MSqlStatementResults(PreparedStatement preparedStatement) throws MSqlStatementException {
+ public MSqlStatementResults(PreparedStatement preparedStatement, boolean localTypesMode) throws MSqlStatementException {
super();
//
if (null == preparedStatement) {
}
//
this.preparedStatement = preparedStatement;
+ this.localTypesMode = localTypesMode;
//
try {
this.resultSet = this.getPreparedStatement().getResultSet();
while (this.getResultSet().next()) {
ResultSetMetaData resultSetMetaData = this.getResultSet().getMetaData();
LinkedHashMap<String, Object> record = new LinkedHashMap<String, Object>();
+ //
for (int f = 0; resultSetMetaData.getColumnCount() > f; f++) {
String field = resultSetMetaData.getColumnLabel(f + 1);
- record.put(field, this.getResultSet().getObject(field));
+ Object value = this.getResultSet().getObject(field);
+ //
+ if ((value instanceof java.sql.Date) && (this.getLocalTypesMode())) {
+ value = ((java.sql.Date)value).toLocalDate();
+ }
+ else if ((value instanceof java.sql.Time) && (this.getLocalTypesMode())) {
+ value = ((java.sql.Time)value).toLocalTime();
+ }
+ else if ((value instanceof java.sql.Timestamp) && (this.getLocalTypesMode())) {
+ value = ((java.sql.Timestamp)value).toLocalDateTime();
+ }
+ //
+ record.put(field, value);
}
+ //
this.getRecords().add(record);
}
}
return this.resultSet;
}
+ public boolean getLocalTypesMode() {
+ return this.localTypesMode;
+ }
+
/* Records. */
public LinkedList<LinkedHashMap<String, Object>> getRecords() {