2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.jdbc.db;
15 import org.knowm.yank.Yank;
16 import org.openhab.persistence.jdbc.utils.DbMetaData;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Extended Database Configuration class. Class represents
22 * the extended database-specific configuration. Overrides and supplements the
23 * default settings from JdbcBaseDAO. Enter only the differences to JdbcBaseDAO here.
25 * @author Helmut Lehmeyer - Initial contribution
27 public class JdbcMariadbDAO extends JdbcBaseDAO {
28 private final Logger logger = LoggerFactory.getLogger(JdbcMariadbDAO.class);
33 public JdbcMariadbDAO() {
40 private void initSqlQueries() {
41 logger.debug("JDBC::initSqlQueries: '{}'", this.getClass().getSimpleName());
45 * INFO: http://www.java2s.com/Code/Java/Database-SQL-JDBC/StandardSQLDataTypeswithTheirJavaEquivalents.htm
47 private void initSqlTypes() {
48 logger.debug("JDBC::initSqlTypes: Initialize the type array");
52 * INFO: https://github.com/brettwooldridge/HikariCP
54 private void initDbProps() {
56 databaseProps.setProperty("dataSource.cachePrepStmts", "true");
57 databaseProps.setProperty("dataSource.prepStmtCacheSize", "250");
58 databaseProps.setProperty("dataSource.prepStmtCacheSqlLimit", "2048");
59 databaseProps.setProperty("dataSource.jdbcCompliantTruncation", "false");// jdbc standard max varchar max length
62 // Properties for HikariCP
63 // Use driverClassName
64 databaseProps.setProperty("driverClassName", "org.mariadb.jdbc.Driver");
65 // driverClassName OR BETTER USE dataSourceClassName
66 // databaseProps.setProperty("dataSourceClassName", "org.mariadb.jdbc.MySQLDataSource");
67 databaseProps.setProperty("maximumPoolSize", "3");
68 databaseProps.setProperty("minimumIdle", "2");
72 public void initAfterFirstDbConnection() {
73 logger.debug("JDBC::initAfterFirstDbConnection: Initializing step, after db is connected.");
74 dbMeta = new DbMetaData();
75 // Initialize sqlTypes, depending on DB version for example
76 if (dbMeta.isDbVersionGreater(5, 1)) {
77 sqlTypes.put("DATETIMEITEM", "TIMESTAMP(3)");
78 sqlTypes.put("tablePrimaryKey", "TIMESTAMP(3)");
79 sqlTypes.put("tablePrimaryValue", "NOW(3)");
87 public Integer doPingDB() {
88 return Yank.queryScalar(sqlPingDB, Long.class, null).intValue();
95 /****************************
96 * SQL generation Providers *
97 ****************************/
103 /******************************
104 * public Getters and Setters *
105 ******************************/