forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jdbc] Add support for TimescaleDB (openhab#11090) (openhab#11091)
Signed-off-by: Riccardo Nimser-Joseph <[email protected]> Co-authored-by: Riccardo Nimser-Joseph <[email protected]>
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...ab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcTimescaledbDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.persistence.jdbc.db; | ||
|
||
import java.util.Properties; | ||
|
||
import org.knowm.yank.Yank; | ||
import org.openhab.persistence.jdbc.dto.ItemVO; | ||
import org.openhab.persistence.jdbc.utils.StringUtilsExt; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Extended Database Configuration class. Class represents the extended database-specific configuration. Overrides and | ||
* supplements the default settings from JdbcBaseDAO and JdbcPostgresqlDAO. | ||
* | ||
* @author Riccardo Nimser-Joseph - Initial contribution | ||
*/ | ||
public class JdbcTimescaledbDAO extends JdbcPostgresqlDAO { | ||
private final Logger logger = LoggerFactory.getLogger(JdbcTimescaledbDAO.class); | ||
|
||
protected String sqlCreateHypertable; | ||
|
||
public JdbcTimescaledbDAO() { | ||
super(); | ||
|
||
initSqlQueries(); | ||
} | ||
|
||
public Properties getDatabaseProperties() { | ||
Properties properties = new Properties(this.databaseProps); | ||
|
||
// Adjust the jdbc url since the service name 'timescaledb' is only used to differentiate the DAOs | ||
if (properties.containsKey("jdbcUrl")) { | ||
properties.put("jdbcUrl", properties.getProperty("jdbcUrl").replace("timescaledb", "postgresql")); | ||
} | ||
|
||
return properties; | ||
} | ||
|
||
public void doCreateItemTable(ItemVO vo) { | ||
String sql; | ||
|
||
sql = StringUtilsExt.replaceArrayMerge(this.sqlCreateItemTable, | ||
new String[] { "#tableName#", "#dbType#", "#tablePrimaryKey#" }, | ||
new String[] { vo.getTableName(), vo.getDbType(), sqlTypes.get("tablePrimaryKey") }); | ||
this.logger.debug("JDBC::doCreateItemTable sql={}", sql); | ||
Yank.execute(sql, null); | ||
|
||
sql = StringUtilsExt.replaceArrayMerge(this.sqlCreateHypertable, new String[] { "#tableName#" }, | ||
new String[] { vo.getTableName() }); | ||
this.logger.debug("JDBC::doCreateItemTable sql={}", sql); | ||
Yank.execute(sql, null); | ||
} | ||
|
||
private void initSqlQueries() { | ||
this.logger.debug("JDBC::initSqlQueries: '{}'", this.getClass().getSimpleName()); | ||
|
||
this.sqlCreateHypertable = "SELECT create_hypertable('#tableName#', 'time')"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters