Removed LockService

This commit is contained in:
vzikratyi 2020-10-08 12:21:53 +03:00
parent d2f45db0a6
commit 6ae75e295c
5 changed files with 0 additions and 160 deletions

View File

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

View File

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

View File

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

View File

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

View File

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