2019-11-17 11:57:02 +00:00
|
|
|
#include <Access/RowPolicy.h>
|
|
|
|
#include <Common/quoteString.h>
|
|
|
|
#include <boost/range/algorithm/equal.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-05-02 16:05:01 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
extern const int NOT_IMPLEMENTED;
|
2020-05-02 16:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
String RowPolicy::NameParts::getName() const
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
String name;
|
|
|
|
name.reserve(database.length() + table_name.length() + short_name.length() + 6);
|
|
|
|
name += backQuoteIfNeed(short_name);
|
|
|
|
name += " ON ";
|
2020-06-06 02:25:27 +00:00
|
|
|
if (!database.empty())
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name += backQuoteIfNeed(database);
|
|
|
|
name += '.';
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
2020-05-02 22:30:28 +00:00
|
|
|
name += backQuoteIfNeed(table_name);
|
|
|
|
return name;
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setDatabase(const String & database)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name_parts.database = database;
|
|
|
|
IAccessEntity::setName(name_parts.getName());
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setTableName(const String & table_name)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name_parts.table_name = table_name;
|
|
|
|
IAccessEntity::setName(name_parts.getName());
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setShortName(const String & short_name)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name_parts.short_name = short_name;
|
|
|
|
IAccessEntity::setName(name_parts.getName());
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setNameParts(const String & short_name, const String & database, const String & table_name)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name_parts.short_name = short_name;
|
|
|
|
name_parts.database = database;
|
|
|
|
name_parts.table_name = table_name;
|
|
|
|
IAccessEntity::setName(name_parts.getName());
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setNameParts(const NameParts & name_parts_)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
name_parts = name_parts_;
|
|
|
|
IAccessEntity::setName(name_parts.getName());
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 22:30:28 +00:00
|
|
|
void RowPolicy::setName(const String &)
|
2019-11-17 11:57:02 +00:00
|
|
|
{
|
2020-05-02 22:30:28 +00:00
|
|
|
throw Exception("RowPolicy::setName() is not implemented", ErrorCodes::NOT_IMPLEMENTED);
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool RowPolicy::equal(const IAccessEntity & other) const
|
|
|
|
{
|
|
|
|
if (!IAccessEntity::equal(other))
|
|
|
|
return false;
|
|
|
|
const auto & other_policy = typeid_cast<const RowPolicy &>(other);
|
2020-05-02 22:30:28 +00:00
|
|
|
return (name_parts == other_policy.name_parts) && boost::range::equal(conditions, other_policy.conditions)
|
|
|
|
&& restrictive == other_policy.restrictive && (to_roles == other_policy.to_roles);
|
2019-11-17 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|