数据库的选择性加载

1.1 条件控制注解定义

通过对 @ConditionalOnProperty 的二次封装,进行控制底层数据库实现上的选择控制

  1. /**
  2. * Copyright © 2016-2022 The Thingsboard Authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.thingsboard.server.dao.util;
  17. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  18. import java.lang.annotation.Retention;
  19. import java.lang.annotation.RetentionPolicy;
  20. @Retention(RetentionPolicy.RUNTIME)
  21. @ConditionalOnProperty(prefix = "database.ts_latest", value = "type", havingValue = "cassandra")
  22. public @interface NoSqlTsLatestDao {
  23. }

1.2 相关配置定义如下

  1. database:
  2. ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by single API call to fetch telemetry records
  3. ts:
  4. # type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
  5. type: "${DATABASE_TS_TYPE:cassandra}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
  6. ts_latest:
  7. # type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)
  8. type: "${DATABASE_TS_LATEST_TYPE:cassandra}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale)

其它代码实现

image.png

Cassandra 相关资料

Cassandra 简介

Cassandra 安装

Cassandra数据类型