Browse Source

Removed LockService

pull/3557/head
vzikratyi 6 years ago
parent
commit
6ae75e295c
  1. 30
      common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockKey.java
  2. 25
      common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockService.java
  3. 45
      dao/src/main/java/org/thingsboard/server/dao/lock/LockServiceImpl.java
  4. 20
      dao/src/main/java/org/thingsboard/server/dao/sql/lock/LockRepository.java
  5. 40
      dao/src/main/java/org/thingsboard/server/dao/sql/lock/PsqlLockRepository.java

30
common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockKey.java

@ -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;
}
}

25
common/dao-api/src/main/java/org/thingsboard/server/dao/lock/LockService.java

@ -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);
}

45
dao/src/main/java/org/thingsboard/server/dao/lock/LockServiceImpl.java

@ -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());
}
}

20
dao/src/main/java/org/thingsboard/server/dao/sql/lock/LockRepository.java

@ -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);
}

40
dao/src/main/java/org/thingsboard/server/dao/sql/lock/PsqlLockRepository.java

@ -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 -> {}
);
}
}
Loading…
Cancel
Save