diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockKey.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockKey.java deleted file mode 100644 index 5de01b3e2c..0000000000 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockKey.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright © 2016-2020 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.lock; - -public enum LockKey { - OAUTH2_CONFIG(999); - - private int id; - - LockKey(int id) { - this.id = id; - } - - public int getId() { - return id; - } -} diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockService.java deleted file mode 100644 index 4ffd05233d..0000000000 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockService.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright © 2016-2020 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.lock; - -public interface LockService { - /** - * Lock with SQL Database till the end of transaction - * - * @param key identifier - */ - void transactionLock(LockKey key); -} diff --git a/dao/src/main/java/org/thingsboard/server/dao/lock/LockServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/lock/LockServiceImpl.java deleted file mode 100644 index ff1e052f97..0000000000 --- a/dao/src/main/java/org/thingsboard/server/dao/lock/LockServiceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright © 2016-2020 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.lock; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.thingsboard.server.dao.sql.lock.LockRepository; - -import javax.annotation.PostConstruct; - -@Service -@Slf4j -public class LockServiceImpl implements LockService { - - @Autowired(required = false) - private LockRepository lockRepository; - - @PostConstruct - public void init(){ - if (lockRepository == null) { - log.warn("Locking with DB is not enabled."); - } - } - - @Override - public void transactionLock(LockKey key) { - if (lockRepository == null) return; - log.trace("Locking transaction key [{}]", key); - lockRepository.transactionLock(key.getId()); - } -} diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/lock/LockRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/lock/LockRepository.java deleted file mode 100644 index eced945acd..0000000000 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/lock/LockRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright © 2016-2020 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.lock; - -public interface LockRepository { - void transactionLock(Integer key); -} diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/lock/PsqlLockRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/lock/PsqlLockRepository.java deleted file mode 100644 index 76c4b6ebc8..0000000000 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/lock/PsqlLockRepository.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright © 2016-2020 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.lock; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.stereotype.Repository; -import org.thingsboard.server.dao.util.PsqlDao; - -@Slf4j -@PsqlDao -@Repository -public class PsqlLockRepository implements LockRepository { - private static final String TRANSACTION_LOCK_QUERY = "SELECT pg_advisory_xact_lock(?)"; - - @Autowired - private JdbcTemplate jdbcTemplate; - - @Override - public void transactionLock(Integer key) { - jdbcTemplate.query(TRANSACTION_LOCK_QUERY, - preparedStatement -> preparedStatement.setInt(1, key), - resultSet -> {} - ); - } -}