/*
- * Copyright (c) 2014 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 Samsung Electronics Co., Ltd. All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace CKM {
namespace DB {
Crypto::Crypto(const std::string &path, const RawBuffer &rawPass) :
- m_connection(nullptr), m_inUserTransaction(false)
+ m_inUserTransaction(false)
{
try {
- m_connection = new SqlConnection(path, SqlConnection::Flag::Option::CRW);
+ m_connection.reset(new SqlConnection(path, SqlConnection::Flag::Option::CRW));
m_connection->SetKey(rawPass);
initDatabase();
m_connection->ExecCommand("VACUUM;");
}
Crypto::Crypto(Crypto &&other) :
- m_connection(other.m_connection),
+ m_connection(std::move(other.m_connection)),
m_inUserTransaction(other.m_inUserTransaction)
{
- other.m_connection = NULL;
other.m_inUserTransaction = false;
}
-Crypto::~Crypto()
-{
- delete m_connection;
-}
-
Crypto &Crypto::operator=(Crypto &&other)
{
if (this == &other)
return *this;
- delete m_connection;
-
- m_connection = other.m_connection;
- other.m_connection = NULL;
+ m_connection = std::move(other.m_connection);
m_inUserTransaction = other.m_inUserTransaction;
other.m_inUserTransaction = false;
Transaction transaction(this);
if (m_connection->CheckTableExist("SCHEMA_INFO")) {
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
if (SchemaInfo.getVersionInfo(schemaVersion)) {
LogDebug("Current DB version: " << schemaVersion);
return true;
}
// update DB version info
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
SchemaInfo.setVersionInfo();
transaction.commit();
}
"Can not create the database schema: no initialization script");
m_connection->ExecCommand((*script).c_str());
- SchemaInfo SchemaInfo(m_connection);
+ SchemaInfo SchemaInfo(m_connection.get());
SchemaInfo.setVersionInfo();
transaction.commit();
}
bool Crypto::isNameOwnerPresent(const Name &name, const ClientId &owner) const
{
try {
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
return nameTable.isPresent(name, owner);
} catch (const SqlConnection::Exception::SyntaxError &) {
LogError("Couldn't prepare insert statement");
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
- ObjectTable objectTable(this->m_connection);
- PermissionTable permissionTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
+ ObjectTable objectTable(m_connection.get());
+ PermissionTable permissionTable(m_connection.get());
nameTable.addRow(name, owner);
for (const auto &i : rows)
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
- ObjectTable objectTable(this->m_connection);
- PermissionTable permissionTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
+ ObjectTable objectTable(m_connection.get());
+ PermissionTable permissionTable(m_connection.get());
nameTable.addRow(row.name, row.owner);
objectTable.addRow(row);
permissionTable.setPermission(row.name,
{
try {
// transaction is present in the layer above
- ObjectTable objectTable(this->m_connection);
+ ObjectTable objectTable(m_connection.get());
objectTable.updateRow(row);
return;
} catch (const SqlConnection::Exception::SyntaxError &) {
{
try {
// transaction is present in the layer above
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
if (nameTable.isPresent(name, owner)) {
nameTable.deleteRow(name, owner);
const ClientId &accessor) const
{
try {
- PermissionTable permissionTable(this->m_connection);
+ PermissionTable permissionTable(m_connection.get());
return permissionTable.getPermissionRow(name, owner, accessor);
} catch (const SqlConnection::Exception::InvalidColumn &) {
LogError("Select statement invalid column error");
deleteCommand->BindString(1, owner.c_str());
deleteCommand->Step();
- NameTable nameTable(this->m_connection);
+ NameTable nameTable(m_connection.get());
nameTable.deleteAllRows(owner);
transaction.commit();
const PermissionMask permissionMask)
{
try {
- PermissionTable permissionTable(this->m_connection);
+ PermissionTable permissionTable(m_connection.get());
permissionTable.setPermission(name, owner, accessor, permissionMask);
return;
} catch (const SqlConnection::Exception::SyntaxError &) {