2 * Copyright (c) 2010-2022 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.eclipse.jdt.annotation.NonNullByDefault;
16 import org.knowm.yank.Yank;
17 import org.openhab.persistence.jdbc.utils.DbMetaData;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Extended Database Configuration class. Class represents
23 * the extended database-specific configuration. Overrides and supplements the
24 * default settings from JdbcBaseDAO. Enter only the differences to JdbcBaseDAO here.
26 * @author Helmut Lehmeyer - Initial contribution
29 public class JdbcMariadbDAO extends JdbcBaseDAO {
30 private final Logger logger = LoggerFactory.getLogger(JdbcMariadbDAO.class);
35 public JdbcMariadbDAO() {
42 private void initSqlQueries() {
43 logger.debug("JDBC::initSqlQueries: '{}'", this.getClass().getSimpleName());
47 * INFO: http://www.java2s.com/Code/Java/Database-SQL-JDBC/StandardSQLDataTypeswithTheirJavaEquivalents.htm
49 private void initSqlTypes() {
50 logger.debug("JDBC::initSqlTypes: Initialize the type array");
51 sqlTypes.put("IMAGEITEM", "VARCHAR(16255)");
52 sqlTypes.put("STRINGITEM", "VARCHAR(16255)"); // MariaDB using utf-8 max = 16383, using 16383-128 = 16255
56 * INFO: https://github.com/brettwooldridge/HikariCP
58 private void initDbProps() {
60 databaseProps.setProperty("dataSource.cachePrepStmts", "true");
61 databaseProps.setProperty("dataSource.prepStmtCacheSize", "250");
62 databaseProps.setProperty("dataSource.prepStmtCacheSqlLimit", "2048");
63 databaseProps.setProperty("dataSource.jdbcCompliantTruncation", "false");// jdbc standard max varchar max length
66 // Properties for HikariCP
67 // Use driverClassName
68 databaseProps.setProperty("driverClassName", "org.mariadb.jdbc.Driver");
69 // driverClassName OR BETTER USE dataSourceClassName
70 // databaseProps.setProperty("dataSourceClassName", "org.mariadb.jdbc.MySQLDataSource");
71 databaseProps.setProperty("maximumPoolSize", "3");
72 databaseProps.setProperty("minimumIdle", "2");
76 public void initAfterFirstDbConnection() {
77 logger.debug("JDBC::initAfterFirstDbConnection: Initializing step, after db is connected.");
78 dbMeta = new DbMetaData();
79 // Initialize sqlTypes, depending on DB version for example
80 if (dbMeta.isDbVersionGreater(5, 1)) {
81 sqlTypes.put("DATETIMEITEM", "TIMESTAMP(3)");
82 sqlTypes.put("tablePrimaryKey", "TIMESTAMP(3)");
83 sqlTypes.put("tablePrimaryValue", "NOW(3)");
91 public Integer doPingDB() {
92 return Yank.queryScalar(sqlPingDB, Long.class, null).intValue();
99 /****************************
100 * SQL generation Providers *
101 ****************************/
107 /******************************
108 * public Getters and Setters *
109 ******************************/