|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"widgetsBundle": { |
||||
|
"alias": "scada_symbols", |
||||
|
"title": "SCADA symbols", |
||||
|
"scada": true, |
||||
|
"image": null, |
||||
|
"description": "Bundle with SCADA symbols", |
||||
|
"order": 9200, |
||||
|
"name": "SCADA symbols" |
||||
|
}, |
||||
|
"widgetTypeFqns": [ |
||||
|
"scada_symbol" |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
{ |
||||
|
"widgetsBundle": { |
||||
|
"alias": "scada_water_system_symbols", |
||||
|
"title": "SCADA water system symbols", |
||||
|
"scada": true, |
||||
|
"image": null, |
||||
|
"description": "Bundle with SCADA symbols for water system", |
||||
|
"order": 9300, |
||||
|
"name": "SCADA water system symbols" |
||||
|
}, |
||||
|
"widgetTypeFqns": [ |
||||
|
"horizontal_pipe", |
||||
|
"long_horizontal_pipe", |
||||
|
"vertical_pipe", |
||||
|
"long_vertical_pipe", |
||||
|
"left_bottom_elbow_pipe", |
||||
|
"bottom_right_elbow_pipe", |
||||
|
"top_right_elbow_pipe", |
||||
|
"left_top_elbow_pipe", |
||||
|
"cross_pipe", |
||||
|
"left_tee_pipe", |
||||
|
"bottom_tee_pipe", |
||||
|
"right_tee_pipe", |
||||
|
"top_tee_pipe", |
||||
|
"right_elbow_drain_pipe", |
||||
|
"left_elbow_drain_pipe", |
||||
|
"left_drain_pipe", |
||||
|
"right_drain_pipe", |
||||
|
"short_left_drain_pipe", |
||||
|
"short_right_drain_pipe", |
||||
|
"top_flow_meter", |
||||
|
"right_flow_meter", |
||||
|
"bottom_flow_meter", |
||||
|
"left_flow_meter", |
||||
|
"horizontal_inline_flow_meter", |
||||
|
"vertical_inline_flow_meter", |
||||
|
"centrifugal_pump", |
||||
|
"small_right_motor_pump", |
||||
|
"small_left_motor_pump", |
||||
|
"right_motor_pump", |
||||
|
"left_motor_pump", |
||||
|
"short_bottom_filter", |
||||
|
"long_bottom_filter", |
||||
|
"short_top_filter", |
||||
|
"long_top_filter", |
||||
|
"horizontal_wheel_valve", |
||||
|
"vertical_wheel_valve", |
||||
|
"horizontal_ball_valve", |
||||
|
"vertical_ball_valve", |
||||
|
"vertical_tank" |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
{ |
||||
|
"fqn": "scada_symbol", |
||||
|
"name": "SCADA symbol", |
||||
|
"deprecated": false, |
||||
|
"scada": true, |
||||
|
"image": null, |
||||
|
"description": "", |
||||
|
"descriptor": { |
||||
|
"type": "rpc", |
||||
|
"sizeX": 3, |
||||
|
"sizeY": 3, |
||||
|
"resources": [], |
||||
|
"templateHtml": "<tb-scada-symbol-widget\n [ctx]='ctx'\n [widgetTitlePanel]=\"widgetTitlePanel\">\n</tb-scada-symbol-widget>", |
||||
|
"templateCss": "", |
||||
|
"controllerScript": "self.onInit = function() {\n self.ctx.$scope.actionWidget.onInit();\n}\n\nself.typeParameters = function() {\n return {\n previewWidth: '300px',\n previewHeight: '320px',\n embedTitlePanel: true,\n targetDeviceOptional: true,\n displayRpcMessageToast: false\n };\n};\n\nself.onDestroy = function() {\n}\n", |
||||
|
"settingsSchema": "", |
||||
|
"dataKeySettingsSchema": "{}\n", |
||||
|
"settingsDirective": "tb-scada-symbol-widget-settings", |
||||
|
"hasBasicMode": true, |
||||
|
"basicModeDirective": "tb-scada-symbol-basic-config", |
||||
|
"defaultConfig": "{\"showTitle\":true,\"backgroundColor\":\"rgba(0, 0, 0, 0)\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"0px\",\"settings\":{\"background\":{\"type\":\"color\",\"imageUrl\":null,\"color\":\"rgb(255, 255, 255)\",\"overlay\":{\"enabled\":false,\"color\":\"rgba(255,255,255,0.72)\",\"blur\":3}},\"padding\":\"12px\",\"scadaSymbolUrl\":\"\",\"scadaSymbolObjectSettings\":{\"behavior\":{},\"properties\":{}}},\"title\":\"SCADA symbol\",\"dropShadow\":true,\"enableFullscreen\":false,\"widgetStyle\":{},\"actions\":{},\"widgetCss\":\"\",\"noDataDisplayMessage\":\"\",\"titleFont\":{\"size\":16,\"sizeUnit\":\"px\",\"family\":\"Roboto\",\"weight\":\"500\",\"style\":null,\"lineHeight\":\"1.6\"},\"showTitleIcon\":false,\"titleTooltip\":\"\",\"titleStyle\":null,\"pageSize\":1024,\"titleIcon\":\"mdi:lightbulb-outline\",\"iconColor\":\"rgba(0, 0, 0, 0.87)\",\"iconSize\":\"24px\",\"configMode\":\"basic\",\"targetDevice\":null,\"titleColor\":null,\"borderRadius\":\"0px\",\"margin\":\"0px\"}" |
||||
|
}, |
||||
|
"tags": null |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.controller; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
||||
|
import org.springframework.test.context.TestPropertySource; |
||||
|
import org.thingsboard.server.dao.service.DaoSqlTest; |
||||
|
import org.thingsboard.server.dao.sqlts.insert.sql.DedicatedEventsSqlPartitioningRepository; |
||||
|
|
||||
|
@DaoSqlTest |
||||
|
@TestPropertySource(properties = { |
||||
|
"spring.datasource.events.enabled=true", |
||||
|
"spring.datasource.events.url=${spring.datasource.url}", |
||||
|
"spring.datasource.events.driverClassName=${spring.datasource.driverClassName}", |
||||
|
}) |
||||
|
public class AuditLogControllerTest_DedicatedEventsDataSource extends AuditLogControllerTest { |
||||
|
|
||||
|
@Getter |
||||
|
@SpyBean |
||||
|
private DedicatedEventsSqlPartitioningRepository partitioningRepository; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.widget; |
||||
|
|
||||
|
import lombok.Builder; |
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
@Builder |
||||
|
public class WidgetTypeFilter { |
||||
|
|
||||
|
private TenantId tenantId; |
||||
|
private boolean fullSearch; |
||||
|
private boolean scadaFirst; |
||||
|
DeprecatedFilter deprecatedFilter; |
||||
|
List<String> widgetTypes; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data.widget; |
||||
|
|
||||
|
import lombok.Builder; |
||||
|
import lombok.Data; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
|
||||
|
@Data |
||||
|
@Builder |
||||
|
public class WidgetsBundleFilter { |
||||
|
|
||||
|
private TenantId tenantId; |
||||
|
private boolean fullSearch; |
||||
|
private boolean scadaFirst; |
||||
|
|
||||
|
public static WidgetsBundleFilter fromTenantId(TenantId tenantId) { |
||||
|
return WidgetsBundleFilter.builder().tenantId(tenantId).fullSearch(false).scadaFirst(false).build(); |
||||
|
} |
||||
|
|
||||
|
public static WidgetsBundleFilter fullSearchFromTenantId(TenantId tenantId) { |
||||
|
return WidgetsBundleFilter.builder().tenantId(tenantId).fullSearch(true).scadaFirst(false).build(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,37 +0,0 @@ |
|||||
/** |
|
||||
* Copyright © 2016-2024 The Thingsboard Authors |
|
||||
* |
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||
* you may not use this file except in compliance with the License. |
|
||||
* You may obtain a copy of the License at |
|
||||
* |
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||
* |
|
||||
* Unless required by applicable law or agreed to in writing, software |
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||
* See the License for the specific language governing permissions and |
|
||||
* limitations under the License. |
|
||||
*/ |
|
||||
package org.thingsboard.server.dao; |
|
||||
|
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan; |
|
||||
import org.springframework.context.annotation.ComponentScan; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
|
||||
import org.springframework.data.repository.config.BootstrapMode; |
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
|
||||
import org.thingsboard.server.dao.util.TbAutoConfiguration; |
|
||||
|
|
||||
/** |
|
||||
* @author Valerii Sosliuk |
|
||||
*/ |
|
||||
@Configuration |
|
||||
@TbAutoConfiguration |
|
||||
@ComponentScan({"org.thingsboard.server.dao.sql", "org.thingsboard.server.dao.attributes", "org.thingsboard.server.dao.cache", "org.thingsboard.server.cache"}) |
|
||||
@EnableJpaRepositories(value = "org.thingsboard.server.dao.sql", bootstrapMode = BootstrapMode.LAZY) |
|
||||
@EntityScan("org.thingsboard.server.dao.model.sql") |
|
||||
@EnableTransactionManagement |
|
||||
public class JpaDaoConfig { |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,26 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.config; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
|
||||
|
import java.lang.annotation.Retention; |
||||
|
import java.lang.annotation.RetentionPolicy; |
||||
|
|
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@ConditionalOnProperty(value = "spring.datasource.events.enabled", havingValue = "true") |
||||
|
public @interface DedicatedEventsDataSource { |
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.config; |
||||
|
|
||||
|
import com.zaxxer.hikari.HikariDataSource; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
||||
|
import org.springframework.data.repository.config.BootstrapMode; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.orm.jpa.JpaTransactionManager; |
||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
||||
|
import org.springframework.transaction.support.TransactionTemplate; |
||||
|
import org.thingsboard.server.dao.model.sql.AuditLogEntity; |
||||
|
import org.thingsboard.server.dao.model.sql.ErrorEventEntity; |
||||
|
import org.thingsboard.server.dao.model.sql.LifecycleEventEntity; |
||||
|
import org.thingsboard.server.dao.model.sql.RuleChainDebugEventEntity; |
||||
|
import org.thingsboard.server.dao.model.sql.RuleNodeDebugEventEntity; |
||||
|
import org.thingsboard.server.dao.model.sql.StatisticsEventEntity; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
@DedicatedEventsDataSource |
||||
|
@Configuration |
||||
|
@EnableJpaRepositories(value = {"org.thingsboard.server.dao.sql.event", "org.thingsboard.server.dao.sql.audit"}, |
||||
|
bootstrapMode = BootstrapMode.LAZY, |
||||
|
entityManagerFactoryRef = "eventsEntityManagerFactory", transactionManagerRef = "eventsTransactionManager") |
||||
|
public class DedicatedEventsJpaDaoConfig { |
||||
|
|
||||
|
public static final String EVENTS_PERSISTENCE_UNIT = "events"; |
||||
|
public static final String EVENTS_DATA_SOURCE = EVENTS_PERSISTENCE_UNIT + "DataSource"; |
||||
|
public static final String EVENTS_TRANSACTION_MANAGER = EVENTS_PERSISTENCE_UNIT + "TransactionManager"; |
||||
|
public static final String EVENTS_TRANSACTION_TEMPLATE = EVENTS_PERSISTENCE_UNIT + "TransactionTemplate"; |
||||
|
public static final String EVENTS_JDBC_TEMPLATE = EVENTS_PERSISTENCE_UNIT + "JdbcTemplate"; |
||||
|
|
||||
|
@Bean |
||||
|
@ConfigurationProperties("spring.datasource.events") |
||||
|
public DataSourceProperties eventsDataSourceProperties() { |
||||
|
return new DataSourceProperties(); |
||||
|
} |
||||
|
|
||||
|
@ConfigurationProperties(prefix = "spring.datasource.events.hikari") |
||||
|
@Bean(EVENTS_DATA_SOURCE) |
||||
|
public DataSource eventsDataSource(@Qualifier("eventsDataSourceProperties") DataSourceProperties eventsDataSourceProperties) { |
||||
|
return eventsDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); |
||||
|
} |
||||
|
|
||||
|
@Bean |
||||
|
public LocalContainerEntityManagerFactoryBean eventsEntityManagerFactory(@Qualifier(EVENTS_DATA_SOURCE) DataSource eventsDataSource, |
||||
|
EntityManagerFactoryBuilder builder) { |
||||
|
return builder |
||||
|
.dataSource(eventsDataSource) |
||||
|
.packages(LifecycleEventEntity.class, StatisticsEventEntity.class, ErrorEventEntity.class, RuleNodeDebugEventEntity.class, RuleChainDebugEventEntity.class, AuditLogEntity.class) |
||||
|
.persistenceUnit(EVENTS_PERSISTENCE_UNIT) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
@Bean(EVENTS_TRANSACTION_MANAGER) |
||||
|
public JpaTransactionManager eventsTransactionManager(@Qualifier("eventsEntityManagerFactory") LocalContainerEntityManagerFactoryBean eventsEntityManagerFactory) { |
||||
|
return new JpaTransactionManager(Objects.requireNonNull(eventsEntityManagerFactory.getObject())); |
||||
|
} |
||||
|
|
||||
|
@Bean(EVENTS_TRANSACTION_TEMPLATE) |
||||
|
public TransactionTemplate eventsTransactionTemplate(@Qualifier(EVENTS_TRANSACTION_MANAGER) JpaTransactionManager eventsTransactionManager) { |
||||
|
return new TransactionTemplate(eventsTransactionManager); |
||||
|
} |
||||
|
|
||||
|
@Bean(EVENTS_JDBC_TEMPLATE) |
||||
|
public JdbcTemplate eventsJdbcTemplate(@Qualifier(EVENTS_DATA_SOURCE) DataSource eventsDataSource) { |
||||
|
return new JdbcTemplate(eventsDataSource); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.config; |
||||
|
|
||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
||||
|
|
||||
|
import java.lang.annotation.Retention; |
||||
|
import java.lang.annotation.RetentionPolicy; |
||||
|
|
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@ConditionalOnProperty(value = "spring.datasource.events.enabled", havingValue = "false", matchIfMissing = true) |
||||
|
public @interface DefaultDataSource { |
||||
|
} |
||||
@ -0,0 +1,121 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.config; |
||||
|
|
||||
|
import com.zaxxer.hikari.HikariDataSource; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
||||
|
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
|
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; |
||||
|
import org.springframework.context.annotation.Bean; |
||||
|
import org.springframework.context.annotation.ComponentScan; |
||||
|
import org.springframework.context.annotation.ComponentScan.Filter; |
||||
|
import org.springframework.context.annotation.Configuration; |
||||
|
import org.springframework.context.annotation.FilterType; |
||||
|
import org.springframework.context.annotation.Primary; |
||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
||||
|
import org.springframework.data.repository.config.BootstrapMode; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
||||
|
import org.springframework.orm.jpa.JpaTransactionManager; |
||||
|
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
||||
|
import org.springframework.transaction.support.TransactionTemplate; |
||||
|
import org.thingsboard.server.dao.sql.audit.AuditLogRepository; |
||||
|
import org.thingsboard.server.dao.sql.event.EventRepository; |
||||
|
import org.thingsboard.server.dao.util.TbAutoConfiguration; |
||||
|
|
||||
|
import javax.sql.DataSource; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
@Configuration |
||||
|
@TbAutoConfiguration |
||||
|
@ComponentScan({"org.thingsboard.server.dao.sql", "org.thingsboard.server.dao.attributes", "org.thingsboard.server.dao.sqlts.dictionary", "org.thingsboard.server.dao.cache", "org.thingsboard.server.cache"}) |
||||
|
@EnableJpaRepositories(value = {"org.thingsboard.server.dao.sql", "org.thingsboard.server.dao.sqlts.dictionary"}, |
||||
|
excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {EventRepository.class, AuditLogRepository.class}), |
||||
|
bootstrapMode = BootstrapMode.LAZY) |
||||
|
public class JpaDaoConfig { |
||||
|
|
||||
|
@Bean |
||||
|
@ConfigurationProperties("spring.datasource") |
||||
|
public DataSourceProperties dataSourceProperties() { |
||||
|
return new DataSourceProperties(); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@ConfigurationProperties(prefix = "spring.datasource.hikari") |
||||
|
@Bean |
||||
|
public DataSource dataSource(@Qualifier("dataSourceProperties") DataSourceProperties dataSourceProperties) { |
||||
|
return dataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build(); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@Bean |
||||
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("dataSource") DataSource dataSource, |
||||
|
EntityManagerFactoryBuilder builder, |
||||
|
@Autowired(required = false) SqlTsLatestDaoConfig tsLatestDaoConfig, |
||||
|
@Autowired(required = false) SqlTsDaoConfig tsDaoConfig, |
||||
|
@Autowired(required = false) TimescaleDaoConfig timescaleDaoConfig, |
||||
|
@Autowired(required = false) TimescaleTsLatestDaoConfig timescaleTsLatestDaoConfig) { |
||||
|
List<String> packages = new ArrayList<>(); |
||||
|
packages.add("org.thingsboard.server.dao.model.sql"); |
||||
|
packages.add("org.thingsboard.server.dao.model.sqlts.dictionary"); |
||||
|
if (tsLatestDaoConfig != null) { |
||||
|
packages.add("org.thingsboard.server.dao.model.sqlts.latest"); |
||||
|
} |
||||
|
if (tsDaoConfig != null) { |
||||
|
packages.add("org.thingsboard.server.dao.model.sqlts.ts"); |
||||
|
} |
||||
|
if (timescaleDaoConfig != null) { |
||||
|
packages.add("org.thingsboard.server.dao.model.sqlts.timescale"); |
||||
|
} |
||||
|
if (timescaleTsLatestDaoConfig != null) { |
||||
|
packages.add("org.thingsboard.server.dao.model.sqlts.latest"); |
||||
|
} |
||||
|
return builder |
||||
|
.dataSource(dataSource) |
||||
|
.packages(packages.toArray(String[]::new)) |
||||
|
.persistenceUnit("default") |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@Bean |
||||
|
public JpaTransactionManager transactionManager(@Qualifier("entityManagerFactory") LocalContainerEntityManagerFactoryBean entityManagerFactory) { |
||||
|
return new JpaTransactionManager(Objects.requireNonNull(entityManagerFactory.getObject())); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@Bean |
||||
|
public TransactionTemplate transactionTemplate(@Qualifier("transactionManager") JpaTransactionManager transactionManager) { |
||||
|
return new TransactionTemplate(transactionManager); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@Bean |
||||
|
public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) { |
||||
|
return new JdbcTemplate(dataSource); |
||||
|
} |
||||
|
|
||||
|
@Primary |
||||
|
@Bean |
||||
|
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(@Qualifier("dataSource") DataSource dataSource) { |
||||
|
return new NamedParameterJdbcTemplate(dataSource); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,87 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.sql.audit; |
||||
|
|
||||
|
import jakarta.persistence.EntityManager; |
||||
|
import jakarta.persistence.PersistenceContext; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.thingsboard.server.common.data.audit.AuditLog; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.dao.config.DedicatedEventsDataSource; |
||||
|
import org.thingsboard.server.dao.sqlts.insert.sql.DedicatedEventsSqlPartitioningRepository; |
||||
|
import org.thingsboard.server.dao.util.SqlDao; |
||||
|
|
||||
|
import java.util.Collection; |
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.thingsboard.server.dao.config.DedicatedEventsJpaDaoConfig.EVENTS_JDBC_TEMPLATE; |
||||
|
import static org.thingsboard.server.dao.config.DedicatedEventsJpaDaoConfig.EVENTS_PERSISTENCE_UNIT; |
||||
|
import static org.thingsboard.server.dao.config.DedicatedEventsJpaDaoConfig.EVENTS_TRANSACTION_MANAGER; |
||||
|
|
||||
|
@DedicatedEventsDataSource |
||||
|
@Component |
||||
|
@SqlDao |
||||
|
public class DedicatedJpaAuditLogDao extends JpaAuditLogDao { |
||||
|
|
||||
|
@Autowired |
||||
|
@Qualifier(EVENTS_JDBC_TEMPLATE) |
||||
|
private JdbcTemplate jdbcTemplate; |
||||
|
@PersistenceContext(unitName = EVENTS_PERSISTENCE_UNIT) |
||||
|
private EntityManager entityManager; |
||||
|
|
||||
|
public DedicatedJpaAuditLogDao(AuditLogRepository auditLogRepository, DedicatedEventsSqlPartitioningRepository partitioningRepository) { |
||||
|
super(auditLogRepository, partitioningRepository); |
||||
|
} |
||||
|
|
||||
|
@Transactional(transactionManager = EVENTS_TRANSACTION_MANAGER) |
||||
|
@Override |
||||
|
public AuditLog save(TenantId tenantId, AuditLog domain) { |
||||
|
return super.save(tenantId, domain); |
||||
|
} |
||||
|
|
||||
|
@Transactional(transactionManager = EVENTS_TRANSACTION_MANAGER) |
||||
|
@Override |
||||
|
public AuditLog saveAndFlush(TenantId tenantId, AuditLog domain) { |
||||
|
return super.saveAndFlush(tenantId, domain); |
||||
|
} |
||||
|
|
||||
|
@Transactional(transactionManager = EVENTS_TRANSACTION_MANAGER) |
||||
|
@Override |
||||
|
public void removeById(TenantId tenantId, UUID id) { |
||||
|
super.removeById(tenantId, id); |
||||
|
} |
||||
|
|
||||
|
@Transactional(transactionManager = EVENTS_TRANSACTION_MANAGER) |
||||
|
@Override |
||||
|
public void removeAllByIds(Collection<UUID> ids) { |
||||
|
super.removeAllByIds(ids); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected EntityManager getEntityManager() { |
||||
|
return entityManager; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected JdbcTemplate getJdbcTemplate() { |
||||
|
return jdbcTemplate; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.sql.event; |
||||
|
|
||||
|
import org.springframework.beans.factory.annotation.Qualifier; |
||||
|
import org.springframework.jdbc.core.JdbcTemplate; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
import org.springframework.transaction.support.TransactionTemplate; |
||||
|
import org.thingsboard.server.dao.config.DedicatedEventsDataSource; |
||||
|
|
||||
|
import static org.thingsboard.server.dao.config.DedicatedEventsJpaDaoConfig.EVENTS_JDBC_TEMPLATE; |
||||
|
import static org.thingsboard.server.dao.config.DedicatedEventsJpaDaoConfig.EVENTS_TRANSACTION_TEMPLATE; |
||||
|
|
||||
|
@DedicatedEventsDataSource |
||||
|
@Repository |
||||
|
public class DedicatedEventInsertRepository extends EventInsertRepository { |
||||
|
|
||||
|
public DedicatedEventInsertRepository(@Qualifier(EVENTS_JDBC_TEMPLATE) JdbcTemplate jdbcTemplate, |
||||
|
@Qualifier(EVENTS_TRANSACTION_TEMPLATE) TransactionTemplate transactionTemplate) { |
||||
|
super(jdbcTemplate, transactionTemplate); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2024 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.sql.event; |
||||
|
|
||||
|
import org.springframework.stereotype.Component; |
||||
|
import org.thingsboard.server.common.stats.StatsFactory; |
||||
|
import org.thingsboard.server.dao.config.DedicatedEventsDataSource; |
||||
|
import org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent; |
||||
|
import org.thingsboard.server.dao.sqlts.insert.sql.DedicatedEventsSqlPartitioningRepository; |
||||
|
import org.thingsboard.server.dao.util.SqlDao; |
||||
|
|
||||
|
@DedicatedEventsDataSource |
||||
|
@Component |
||||
|
@SqlDao |
||||
|
public class DedicatedJpaEventDao extends JpaBaseEventDao { |
||||
|
|
||||
|
public DedicatedJpaEventDao(EventPartitionConfiguration partitionConfiguration, |
||||
|
DedicatedEventsSqlPartitioningRepository partitioningRepository, |
||||
|
LifecycleEventRepository lcEventRepository, |
||||
|
StatisticsEventRepository statsEventRepository, |
||||
|
ErrorEventRepository errorEventRepository, |
||||
|
DedicatedEventInsertRepository eventInsertRepository, |
||||
|
RuleNodeDebugEventRepository ruleNodeDebugEventRepository, |
||||
|
RuleChainDebugEventRepository ruleChainDebugEventRepository, |
||||
|
ScheduledLogExecutorComponent logExecutor, |
||||
|
StatsFactory statsFactory) { |
||||
|
super(partitionConfiguration, partitioningRepository, lcEventRepository, statsEventRepository, |
||||
|
errorEventRepository, eventInsertRepository, ruleNodeDebugEventRepository, |
||||
|
ruleChainDebugEventRepository, logExecutor, statsFactory); |
||||
|
} |
||||
|
|
||||
|
} |
||||