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

[jdbc] Fixed ClassCastException; Update mariadb-java-client to version 1.4.6 #8883

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.openhab.persistence.jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<derby.version>10.12.1.1</derby.version>
<h2.version>1.4.191</h2.version>
<hsqldb.version>2.3.3</hsqldb.version>
<mariadb.version>1.3.5</mariadb.version>
<mariadb.version>1.4.6</mariadb.version>
<mysql.version>8.0.13</mysql.version>
<postgresql.version>9.4.1212</postgresql.version>
<sqlite.version>3.16.1</sqlite.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
public class JdbcBaseDAO {
private final Logger logger = LoggerFactory.getLogger(JdbcBaseDAO.class);

public Properties databaseProps = new Properties();
public final Properties databaseProps = new Properties();
protected String urlSuffix = "";
public Map<String, String> sqlTypes = new HashMap<>();
public final Map<String, String> sqlTypes = new HashMap<>();

// Get Database Meta data
protected DbMetaData dbMeta;
Expand Down Expand Up @@ -318,12 +318,12 @@ public void doCreateItemTable(ItemVO vo) {
}

public void doStoreItemValue(Item item, ItemVO vo) {
vo = storeItemValueProvider(item, vo);
ItemVO storedVO = storeItemValueProvider(item, vo);
String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue,
new String[] { "#tableName#", "#tablePrimaryValue#" },
new String[] { vo.getTableName(), sqlTypes.get("tablePrimaryValue") });
Object[] params = new Object[] { vo.getValue(), vo.getValue() };
logger.debug("JDBC::doStoreItemValue sql={} value='{}'", sql, vo.getValue());
new String[] { storedVO.getTableName(), sqlTypes.get("tablePrimaryValue") });
Object[] params = new Object[] { storedVO.getValue(), storedVO.getValue() };
logger.debug("JDBC::doStoreItemValue sql={} value='{}'", sql, storedVO.getValue());
Yank.execute(sql, params);
}

Expand Down Expand Up @@ -402,17 +402,17 @@ protected ItemVO storeItemValueProvider(Item item, ItemVO vo) {
String it = getSqlTypes().get(itemType);
if (it.toUpperCase().contains("DOUBLE")) {
vo.setValueTypes(it, java.lang.Double.class);
Number newVal = ((DecimalType) item.getState());
Number newVal = (Number) item.getState();
logger.debug("JDBC::storeItemValueProvider: newVal.doubleValue: '{}'", newVal.doubleValue());
vo.setValue(newVal.doubleValue());
} else if (it.toUpperCase().contains("DECIMAL") || it.toUpperCase().contains("NUMERIC")) {
vo.setValueTypes(it, java.math.BigDecimal.class);
DecimalType newVal = ((DecimalType) item.getState());
DecimalType newVal = (DecimalType) item.getState();
logger.debug("JDBC::storeItemValueProvider: newVal.toBigDecimal: '{}'", newVal.toBigDecimal());
vo.setValue(newVal.toBigDecimal());
} else if (it.toUpperCase().contains("INT")) {
vo.setValueTypes(it, java.lang.Integer.class);
Number newVal = ((DecimalType) item.getState());
Number newVal = (Number) item.getState();
logger.debug("JDBC::storeItemValueProvider: newVal.intValue: '{}'", newVal.intValue());
vo.setValue(newVal.intValue());
} else {// fall back to String
Expand All @@ -423,7 +423,7 @@ protected ItemVO storeItemValueProvider(Item item, ItemVO vo) {
}
} else if ("ROLLERSHUTTERITEM".equals(itemType) || "DIMMERITEM".equals(itemType)) {
vo.setValueTypes(getSqlTypes().get(itemType), java.lang.Integer.class);
Number newVal = ((DecimalType) item.getState());
Number newVal = (DecimalType) item.getState();
logger.debug("JDBC::storeItemValueProvider: newVal.intValue: '{}'", newVal.intValue());
vo.setValue(newVal.intValue());
} else if ("DATETIMEITEM".equals(itemType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.persistence.jdbc.internal;

import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
Expand Down Expand Up @@ -243,12 +244,11 @@ private void setDBDAOClass(String sn) {

logger.debug("JDBC::updateConfig: Init Data Access Object Class: '{}'", ddp);
try {
dBDAO = (JdbcBaseDAO) Class.forName(ddp).newInstance();
dBDAO = (JdbcBaseDAO) Class.forName(ddp).getConstructor().newInstance();
logger.debug("JDBC::updateConfig: dBDAO ClassName={}", dBDAO.getClass().getName());
} catch (InstantiationException e) {
logger.error("JDBC::updateConfig: InstantiationException: {}", e.getMessage());
} catch (IllegalAccessException e) {
logger.error("JDBC::updateConfig: IllegalAccessException: {}", e.getMessage());
} catch (IllegalAccessException | InstantiationException | InvocationTargetException
| NoSuchMethodException e) {
logger.error("JDBC::updateConfig: Exception: {}", e.getMessage());
} catch (ClassNotFoundException e) {
logger.warn("JDBC::updateConfig: no Configuration for serviceName '{}' found. ClassNotFoundException: {}",
serviceName, e.getMessage());
Expand Down Expand Up @@ -294,21 +294,21 @@ private void testJDBCDriver(String driver) {
e.getMessage());
String warn = ""
+ "\n\n\t!!!\n\tTo avoid this error, place an appropriate JDBC driver file for serviceName '{}' in addons directory.\n"
+ "\tCopy missing JDBC-Driver-jar to your OpenHab/addons Folder.\n\t!!!\n" + "\tDOWNLOAD: \n";
+ "\tCopy missing JDBC-Driver-jar to your openHab/addons Folder.\n\t!!!\n" + "\tDOWNLOAD: \n";
if (serviceName.equals("derby")) {
warn += "\tDerby: version >= 10.11.1.1 from http://mvnrepository.com/artifact/org.apache.derby/derby\n";
warn += "\tDerby: version >= 10.11.1.1 from https://mvnrepository.com/artifact/org.apache.derby/derby\n";
} else if (serviceName.equals("h2")) {
warn += "\tH2: version >= 1.4.189 from http://mvnrepository.com/artifact/com.h2database/h2\n";
warn += "\tH2: version >= 1.4.189 from https://mvnrepository.com/artifact/com.h2database/h2\n";
} else if (serviceName.equals("hsqldb")) {
warn += "\tHSQLDB: version >= 2.3.3 from http://mvnrepository.com/artifact/org.hsqldb/hsqldb\n";
warn += "\tHSQLDB: version >= 2.3.3 from https://mvnrepository.com/artifact/org.hsqldb/hsqldb\n";
} else if (serviceName.equals("mariadb")) {
warn += "\tMariaDB: version >= 1.2.0 from http://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client\n";
warn += "\tMariaDB: version >= 1.2.0 from https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client\n";
} else if (serviceName.equals("mysql")) {
warn += "\tMySQL: version >= 5.1.36 from http://mvnrepository.com/artifact/mysql/mysql-connector-java\n";
warn += "\tMySQL: version >= 5.1.36 from https://mvnrepository.com/artifact/mysql/mysql-connector-java\n";
} else if (serviceName.equals("postgresql")) {
warn += "\tPostgreSQL:version >= 9.4.1208 from http://mvnrepository.com/artifact/org.postgresql/postgresql\n";
warn += "\tPostgreSQL:version >= 9.4.1208 from https://mvnrepository.com/artifact/org.postgresql/postgresql\n";
} else if (serviceName.equals("sqlite")) {
warn += "\tSQLite: version >= 3.16.1 from http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc\n";
warn += "\tSQLite: version >= 3.16.1 from https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc\n";
}
logger.warn(warn, serviceName);
}
Expand Down