Rename query-builder class clearly 88/195788/3
authorsangwan.kwon <sangwan.kwon@samsung.com>
Tue, 18 Dec 2018 05:35:01 +0000 (14:35 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Tue, 18 Dec 2018 07:07:19 +0000 (16:07 +0900)
Change-Id: I62d380511084c8dca48063128b39c00cb369c639
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
include/klay/db/query-builder/column-pack.hxx [new file with mode: 0644]
include/klay/db/query-builder/database-impl.hxx [deleted file]
include/klay/db/query-builder/database.hxx
include/klay/db/query-builder/table-impl.hxx [deleted file]
include/klay/db/query-builder/table-pack.hxx [new file with mode: 0644]
include/klay/db/query-builder/table.hxx

diff --git a/include/klay/db/query-builder/column-pack.hxx b/include/klay/db/query-builder/column-pack.hxx
new file mode 100644 (file)
index 0000000..d473764
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  Copyright (c) 2017 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.
+ *  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
+ */
+
+#pragma once
+
+#include "type.hxx"
+
+#include <string>
+#include <vector>
+
+namespace qxx {
+namespace internal {
+
+template<typename... Base>
+class ColumnPack {
+public:
+       template<typename ColumnType>
+       std::string getName(ColumnType&&) const noexcept { return std::string(); }
+       std::vector<std::string> getNames(void) const noexcept { return {}; }
+
+       int size() const noexcept { return 0; }
+};
+
+template<typename Front, typename... Rest>
+class ColumnPack<Front, Rest...> : public ColumnPack<Rest...> {
+public:
+       using Column = Front;
+       using TableType = typename Column::TableType;
+
+       explicit ColumnPack(Front&& front, Rest&& ...rest);
+
+       template<typename ColumnType>
+       std::string getName(ColumnType&& type) const noexcept;
+       std::vector<std::string> getNames(void) const noexcept;
+
+       int size() const noexcept { return Base::size() + 1; }
+
+private:
+       using Base = ColumnPack<Rest...>;
+
+       Column column;
+};
+
+template<typename Front, typename... Rest>
+ColumnPack<Front, Rest...>::ColumnPack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), column(front)
+{
+}
+
+template<typename Front, typename... Rest>
+std::vector<std::string> ColumnPack<Front, Rest...>::getNames(void) const noexcept
+{
+       auto names = Base::getNames();
+       names.emplace_back(this->column.name);
+
+       return names;
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string ColumnPack<Front, Rest...>::getName(ColumnType&& type) const noexcept
+{
+       if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
+               return column.name;
+
+       return Base::template getName<ColumnType>(std::forward<ColumnType>(type));
+}
+
+} // namespace internal
+} // namespace qxx
diff --git a/include/klay/db/query-builder/database-impl.hxx b/include/klay/db/query-builder/database-impl.hxx
deleted file mode 100644 (file)
index a141fde..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- *  Copyright (c) 2017 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.
- *  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
- */
-
-#pragma once
-
-#include "table.hxx"
-
-#include <vector>
-#include <set>
-#include <string>
-
-namespace qxx {
-namespace internal {
-
-template<typename... Base>
-class DatabaseImpl {
-public:
-       template<typename Table>
-       std::string getTableName(Table&&) const noexcept { return std::string(); }
-
-       template<typename Column>
-       std::string getColumnName(Column&&) const noexcept { return std::string(); }
-};
-
-template<typename Front, typename... Rest>
-class DatabaseImpl<Front, Rest...> : public DatabaseImpl<Rest...> {
-public:
-       using Table = Front;
-
-       DatabaseImpl(Front&& front, Rest&& ...rest) :
-               Base(std::forward<Rest>(rest)...), table(front) {}
-
-       Table table;
-
-       template<typename Table>
-       std::string getTableName(Table&& table) const noexcept
-       {
-               if (this->table.compare(table))
-                       return this->table.name;
-
-               return Base::template getTableName<Table>(std::forward<Table>(table));
-       }
-
-       template<typename Column>
-       std::string getColumnName(Column&& column) const noexcept
-       {
-               using ColumnType = typename std::decay<Column>::type;
-               using TableType = typename ColumnType::TableType;
-               if (this->table.compare(TableType())) {
-                       auto cname = this->table.getColumnName(column.type);
-                       return this->table.name + "." + cname;
-               }
-
-               return Base::template getColumnName<Column>(std::forward<Column>(column));
-       }
-
-private:
-       using Base = DatabaseImpl<Rest...>;
-};
-
-} // namespace internal
-} // namespace qxx
index b5f9250e5c0a36008a119a959b4435534b9f12ce..809bd42c63bc0ea18083c6f54cbef3a9ee4c4536 100644 (file)
@@ -22,7 +22,7 @@
 #include <sstream>
 #include <algorithm>
 
-#include "database-impl.hxx"
+#include "table-pack.hxx"
 #include "tuple-helper.hxx"
 #include "condition.hxx"
 #include "expression.hxx"
@@ -52,11 +52,11 @@ public:
        std::string name;
 
 private:
-       using ImplType = internal::DatabaseImpl<Tables...>;
+       using TablePackType = internal::TablePack<Tables...>;
        using ColumnNames = std::vector<std::string>;
        using TableNames = std::set<std::string>;
 
-       explicit Database(const std::string& name, ImplType&& impl);
+       explicit Database(const std::string& name, TablePackType&& tablePack);
 
        template<typename ...Ts>
        friend Database<Ts...> make_database(const std::string& name, Ts&& ...tables);
@@ -68,32 +68,32 @@ private:
        std::vector<std::string> getColumnNames(Cs&& tuple);
 
        struct GetTableNames {
-               ImplType impl;
+               TablePackType tablePack;
                std::set<std::string> names;
-               GetTableNames(const ImplType &_impl) : impl(_impl) {}
+               GetTableNames(const TablePackType& tablePack) : tablePack(tablePack) {}
 
                template <typename T>
                void operator()(T&& type)
                {
                        auto column = make_column("anonymous", type);
                        using TableType = typename decltype(column)::TableType;
-                       auto name = this->impl.getTableName(TableType());
+                       auto name = this->tablePack.getName(TableType());
                        if (!name.empty())
                                names.emplace(name);
                }
        };
 
        struct GetColumnNames {
-               ImplType impl;
+               TablePackType tablePack;
                std::vector<std::string> names;
 
-               GetColumnNames(const ImplType &_impl) : impl(_impl) {}
+               GetColumnNames(const TablePackType& tablePack) : tablePack(tablePack) {}
 
                template <typename T>
                void operator()(T&& type)
                {
                        auto column = make_column("anonymous", type);
-                       auto name = this->impl.getColumnName(std::move(column));
+                       auto name = this->tablePack.getColumnName(std::move(column));
                        if (!name.empty())
                                names.emplace_back(name);
                }
@@ -108,20 +108,20 @@ private:
        template<typename Expr>
        std::string processWhere(Expr expr);
 
-       ImplType impl;
+       TablePackType tablePack;
        std::vector<std::string> cache;
 };
 
 template<typename ...Tables>
 Database<Tables...> make_database(const std::string& name, Tables&& ...tables)
 {
-       auto impl = internal::DatabaseImpl<Tables...>(std::forward<Tables>(tables)...);
-       return Database<Tables...>(name, std::move(impl));
+       auto tablePack = internal::TablePack<Tables...>(std::forward<Tables>(tables)...);
+       return Database<Tables...>(name, std::move(tablePack));
 }
 
 template<typename ...Tables>
-Database<Tables...>::Database(const std::string& name, ImplType&& impl)
-       : name(name), impl(std::move(impl)) {}
+Database<Tables...>::Database(const std::string& name, TablePackType&& tablePack)
+       : name(name), tablePack(std::move(tablePack)) {}
 
 template<typename... Tables>
 template<typename... ColumnTypes>
@@ -178,7 +178,7 @@ Database<Tables...>& Database<Tables...>::join(condition::Join type)
        std::stringstream ss;
        ss << condition::to_string(type) << " ";
        ss << "JOIN ";
-       ss << this->impl.getTableName(Table());
+       ss << this->tablePack.getName(Table());
 
        this->cache.emplace_back(ss.str());
        return *this;
@@ -191,12 +191,12 @@ Database<Tables...>& Database<Tables...>::on(Expr expr)
        std::stringstream ss;
        ss << "ON ";
 
-       auto lname = this->impl.getColumnName(std::move(expr.l));
+       auto lname = this->tablePack.getColumnName(std::move(expr.l));
        ss << lname << " ";
 
        ss << std::string(expr) << " ";
 
-       auto rname = this->impl.getColumnName(std::move(expr.r));
+       auto rname = this->tablePack.getColumnName(std::move(expr.r));
        ss << rname;
 
        this->cache.emplace_back(ss.str());
@@ -218,7 +218,7 @@ template<typename... Tables>
 template<typename Cs>
 std::set<std::string> Database<Tables...>::getTableNames(Cs&& tuple)
 {
-       GetTableNames closure(this->impl);
+       GetTableNames closure(this->tablePack);
        tuple_helper::for_each(std::forward<Cs>(tuple), closure);
 
        return closure.names;
@@ -228,7 +228,7 @@ template<typename... Tables>
 template<typename Cs>
 std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& tuple)
 {
-       GetColumnNames closure(this->impl);
+       GetColumnNames closure(this->tablePack);
        tuple_helper::for_each(std::forward<Cs>(tuple), closure);
 
        return closure.names;
@@ -263,7 +263,7 @@ template<typename Expr>
 std::string Database<Tables...>::processWhere(Expr expr)
 {
        std::stringstream ss;
-       ss << this->impl.getColumnName(expr.l);
+       ss << this->tablePack.getColumnName(expr.l);
        ss << " " << std::string(expr) << " ?";
 
        return ss.str();
diff --git a/include/klay/db/query-builder/table-impl.hxx b/include/klay/db/query-builder/table-impl.hxx
deleted file mode 100644 (file)
index cee3642..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- *  Copyright (c) 2017 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.
- *  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
- */
-
-#pragma once
-
-#include "type.hxx"
-
-#include <string>
-#include <vector>
-
-namespace qxx {
-namespace internal {
-
-template<typename... Base>
-class TableImpl {
-public:
-       std::vector<std::string> getColumnNames() const noexcept { return {}; }
-
-       template<class Type>
-       std::string getColumnName(Type&&) const noexcept { return std::string(); }
-
-       int size() const noexcept { return 0; }
-};
-
-template<typename Front, typename... Rest>
-class TableImpl<Front, Rest...> : public TableImpl<Rest...> {
-public:
-       using Column = Front;
-       using TableType = typename Column::TableType;
-
-       explicit TableImpl(Front&& front, Rest&& ...rest) :
-               Base(std::forward<Rest>(rest)...), column(front) {}
-
-       int size() const noexcept { return Base::size() + 1; }
-
-       std::vector<std::string> getColumnNames(void) const noexcept
-       {
-               auto names = Base::getColumnNames();
-               names.emplace_back(this->column.name);
-               return names;
-       }
-
-       template<typename ColumnType>
-       std::string getColumnName(ColumnType&& type) const noexcept
-       {
-               if (type::cast_compare(column.type, std::forward<ColumnType>(type)))
-                       return column.name;
-
-               return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(type));
-       }
-
-private:
-       using Base = TableImpl<Rest...>;
-
-       Column column;
-};
-
-} // namespace internal
-} // namespace qxx
diff --git a/include/klay/db/query-builder/table-pack.hxx b/include/klay/db/query-builder/table-pack.hxx
new file mode 100644 (file)
index 0000000..70394e3
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  Copyright (c) 2017 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.
+ *  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
+ */
+
+#pragma once
+
+#include <vector>
+#include <set>
+#include <string>
+
+namespace qxx {
+namespace internal {
+
+template<typename... Base>
+class TablePack {
+public:
+       template<typename TableType>
+       std::string getName(TableType&&) const noexcept { return std::string(); }
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&&) const noexcept { return std::string(); }
+};
+
+template<typename Front, typename... Rest>
+class TablePack<Front, Rest...> : public TablePack<Rest...> {
+public:
+       using Table = Front;
+
+       TablePack(Front&& front, Rest&& ...rest);
+
+       template<typename TableType>
+       std::string getName(TableType&& table) const noexcept;
+
+       template<typename ColumnType>
+       std::string getColumnName(ColumnType&& column) const noexcept;
+
+private:
+       using Base = TablePack<Rest...>;
+
+       Table table;
+};
+
+template<typename Front, typename... Rest>
+TablePack<Front, Rest...>::TablePack(Front&& front, Rest&& ...rest) :
+       Base(std::forward<Rest>(rest)...), table(front)
+{
+}
+
+template<typename Front, typename... Rest>
+template<typename TableType>
+std::string TablePack<Front, Rest...>::getName(TableType&& table) const noexcept
+{
+       if (this->table.compare(table))
+               return this->table.name;
+
+       return Base::template getName<TableType>(std::forward<TableType>(table));
+}
+
+template<typename Front, typename... Rest>
+template<typename ColumnType>
+std::string TablePack<Front, Rest...>::getColumnName(ColumnType&& column) const noexcept
+{
+       using DecayColumnType = typename std::decay<ColumnType>::type;
+       using DecayTableType = typename DecayColumnType::TableType;
+       if (this->table.compare(DecayTableType())) {
+               auto cname = this->table.getColumnName(column.type);
+               return this->table.name + "." + cname;
+       }
+
+       return Base::template getColumnName<ColumnType>(std::forward<ColumnType>(column));
+}
+
+} // namespace internal
+} // namespace qxx
index 8ee466db9ef6b2e607f1cf14c0259c99f956f3d9..cfba7021b81ceac1b473783a548845e41de2b46f 100644 (file)
@@ -17,7 +17,7 @@
 #pragma once
 
 #include "column.hxx"
-#include "table-impl.hxx"
+#include "column-pack.hxx"
 #include "tuple-helper.hxx"
 #include "expression.hxx"
 #include "util.hxx"
@@ -32,8 +32,8 @@ template<typename... Columns>
 class Table {
 public:
        using Self = Table<Columns...>;
-       using ImplType = internal::TableImpl<Columns...>;
-       using TableType = typename ImplType::TableType;
+       using ColumnPackType = internal::ColumnPack<Columns...>;
+       using TableType = typename ColumnPackType::TableType;
 
        template<typename... ColumnTypes>
        Self& select(ColumnTypes&&... cts);
@@ -66,7 +66,7 @@ public:
        std::string name;
 
 private:
-       explicit Table(const std::string& name, ImplType&& impl);
+       explicit Table(const std::string& name, ColumnPackType&& columnPack);
 
        template<typename ...Cs>
        friend Table<Cs...> make_table(const std::string& name, Cs&& ...columns);
@@ -82,15 +82,15 @@ private:
        std::vector<std::string> getColumnNames(void) const noexcept;
 
        struct GetColumnNames {
-               ImplType impl;
+               ColumnPackType columnPack;
                std::vector<std::string> names;
 
-               GetColumnNames(const ImplType &impl) : impl(impl) {}
+               GetColumnNames(const ColumnPackType& columnPack) : columnPack(columnPack) {}
 
                template <typename T>
                void operator()(T&& type)
                {
-                       auto name = this->impl.getColumnName(std::forward<T>(type));
+                       auto name = this->columnPack.getName(std::forward<T>(type));
                        if (!name.empty())
                                names.emplace_back(name);
                }
@@ -105,20 +105,20 @@ private:
        template<typename Expr>
        std::string processWhere(Expr expr);
 
-       ImplType impl;
+       ColumnPackType columnPack;
        std::vector<std::string> cache;
 };
 
 template<typename ...Columns>
 Table<Columns...> make_table(const std::string& name, Columns&& ...cs)
 {
-       auto impl = internal::TableImpl<Columns...>(std::forward<Columns>(cs)...);
-       return Table<Columns...>(name, std::move(impl));
+       auto columnPack = internal::ColumnPack<Columns...>(std::forward<Columns>(cs)...);
+       return Table<Columns...>(name, std::move(columnPack));
 }
 
 template<typename... Columns>
-Table<Columns...>::Table(const std::string& name, ImplType&& impl)
-       : name(name), impl(std::move(impl)) {}
+Table<Columns...>::Table(const std::string& name, ColumnPackType&& columnPack)
+       : name(name), columnPack(std::move(columnPack)) {}
 
 template<typename... Columns>
 template<typename... ColumnTypes>
@@ -290,7 +290,7 @@ template<typename... Columns>
 template<typename Cs>
 std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple)
 {
-       GetColumnNames closure(this->impl);
+       GetColumnNames closure(this->columnPack);
        tuple_helper::for_each(std::forward<Cs>(tuple), closure);
 
        return closure.names;
@@ -299,20 +299,20 @@ std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& tuple)
 template<typename... Columns>
 int Table<Columns...>::size() const noexcept
 {
-       return this->impl.size();
+       return this->columnPack.size();
 }
 
 template<typename... Columns>
 std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
 {
-       return this->impl.getColumnNames();
+       return this->columnPack.getNames();
 }
 
 template<typename... Columns>
 template<typename ColumnType>
 std::string Table<Columns...>::getColumnName(ColumnType&& type) const noexcept
 {
-       return this->impl.getColumnName(std::forward<ColumnType>(type));
+       return this->columnPack.getName(std::forward<ColumnType>(type));
 }
 
 template<typename... Columns>
@@ -344,7 +344,7 @@ template<typename Expr>
 std::string Table<Columns...>::processWhere(Expr expr)
 {
        std::stringstream ss;
-       ss << this->impl.getColumnName(expr.l.type);
+       ss << this->columnPack.getName(expr.l.type);
        ss << " " << std::string(expr) << " ?";
 
        return ss.str();