mirror of
https://github.com/oatpp/oatpp-postgresql.git
synced 2024-11-21 01:05:09 +08:00
Simplify. Remove TypeMapper.
This commit is contained in:
parent
0409166b92
commit
2862c019b2
@ -96,6 +96,7 @@ find_package(PostgreSQL REQUIRED)
|
||||
|
||||
message("PostgreSQL_INCLUDE_DIRS=${PostgreSQL_INCLUDE_DIRS}")
|
||||
message("PostgreSQL_LIBRARIES=${PostgreSQL_LIBRARIES}")
|
||||
message("PostgreSQL_TYPE_INCLUDE_DIR=${PostgreSQL_TYPE_INCLUDE_DIR}")
|
||||
|
||||
message("\n############################################################################\n")
|
||||
|
||||
|
@ -9,8 +9,6 @@ add_library(${OATPP_THIS_MODULE_NAME}
|
||||
oatpp-postgresql/mapping/ResultMapper.hpp
|
||||
oatpp-postgresql/mapping/Serializer.cpp
|
||||
oatpp-postgresql/mapping/Serializer.hpp
|
||||
oatpp-postgresql/mapping/TypeMapper.cpp
|
||||
oatpp-postgresql/mapping/TypeMapper.hpp
|
||||
oatpp-postgresql/ql_template/Parser.cpp
|
||||
oatpp-postgresql/ql_template/Parser.hpp
|
||||
oatpp-postgresql/ql_template/TemplateValueProvider.cpp
|
||||
|
@ -56,7 +56,6 @@ namespace {
|
||||
|
||||
Executor::QueryParams::QueryParams(const StringTemplate& queryTemplate,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const mapping::TypeMapper& typeMapper,
|
||||
const mapping::Serializer& serializer,
|
||||
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver)
|
||||
{
|
||||
@ -103,7 +102,7 @@ Executor::QueryParams::QueryParams(const StringTemplate& queryTemplate,
|
||||
auto& data = outData[i];
|
||||
serializer.serialize(data, value);
|
||||
|
||||
paramOids[i] = typeMapper.getTypeOid(value.valueType);
|
||||
paramOids[i] = data.oid;
|
||||
paramValues[i] = data.data;
|
||||
paramLengths[i] = data.dataSize;
|
||||
paramFormats[i] = data.dataFormat;
|
||||
@ -183,7 +182,7 @@ std::unique_ptr<Oid[]> Executor::getParamTypes(const StringTemplate& queryTempla
|
||||
if(it != paramsTypeMap.end()) {
|
||||
auto type = typeResolver->resolveObjectPropertyType(it->second, queryParameter.propertyPath, cache);
|
||||
if(type) {
|
||||
result.get()[i] = m_typeMapper.getTypeOid(type);
|
||||
result.get()[i] = m_serializer.getTypeOid(type);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -223,7 +222,7 @@ std::shared_ptr<QueryResult> Executor::executeQueryPrepared(const StringTemplate
|
||||
const std::shared_ptr<postgresql::Connection>& connection)
|
||||
{
|
||||
|
||||
QueryParams queryParams(queryTemplate, params, m_typeMapper, m_serializer, typeResolver);
|
||||
QueryParams queryParams(queryTemplate, params, m_serializer, typeResolver);
|
||||
|
||||
PGresult *qres = PQexecPrepared(connection->getHandle(),
|
||||
queryParams.queryName,
|
||||
@ -243,7 +242,7 @@ std::shared_ptr<QueryResult> Executor::executeQuery(const StringTemplate& queryT
|
||||
const std::shared_ptr<postgresql::Connection>& connection)
|
||||
{
|
||||
|
||||
QueryParams queryParams(queryTemplate, params, m_typeMapper, m_serializer, typeResolver);
|
||||
QueryParams queryParams(queryTemplate, params, m_serializer, typeResolver);
|
||||
|
||||
PGresult *qres = PQexecParams(connection->getHandle(),
|
||||
queryParams.query,
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "QueryResult.hpp"
|
||||
|
||||
#include "mapping/Serializer.hpp"
|
||||
#include "mapping/TypeMapper.hpp"
|
||||
#include "mapping/ResultMapper.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
@ -59,7 +58,6 @@ private:
|
||||
|
||||
QueryParams(const StringTemplate& queryTemplate,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const mapping::TypeMapper& typeMapper,
|
||||
const mapping::Serializer& serializer,
|
||||
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver);
|
||||
|
||||
@ -110,7 +108,6 @@ private:
|
||||
private:
|
||||
std::shared_ptr<provider::Provider<Connection>> m_connectionProvider;
|
||||
std::shared_ptr<mapping::ResultMapper> m_resultMapper;
|
||||
mapping::TypeMapper m_typeMapper;
|
||||
mapping::Serializer m_serializer;
|
||||
public:
|
||||
|
||||
|
@ -236,14 +236,43 @@ oatpp::Void Deserializer::deserializeBoolean(const Deserializer* _this, const In
|
||||
|
||||
}
|
||||
|
||||
const oatpp::Type* Deserializer::guessAnyType(Oid oid) {
|
||||
|
||||
switch(oid) {
|
||||
|
||||
case TEXTOID:
|
||||
case VARCHAROID: return oatpp::String::Class::getType();
|
||||
|
||||
case INT2OID: return oatpp::Int16::Class::getType();
|
||||
case INT4OID: return oatpp::Int32::Class::getType();
|
||||
case INT8OID: return oatpp::Int64::Class::getType();
|
||||
|
||||
case FLOAT4OID: return oatpp::Float32::Class::getType();
|
||||
case FLOAT8OID: return oatpp::Float64::Class::getType();
|
||||
|
||||
case BOOLOID: return oatpp::Boolean::Class::getType();
|
||||
|
||||
case TIMESTAMPOID: return oatpp::UInt64::Class::getType();
|
||||
|
||||
case UUIDOID: return oatpp::postgresql::Uuid::Class::getType();
|
||||
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
oatpp::Void Deserializer::deserializeAny(const Deserializer* _this, const InData& data, const Type* type) {
|
||||
|
||||
(void) type;
|
||||
const Type* valueType = _this->m_typeMapper.getOidType(data.oid);
|
||||
|
||||
const Type* valueType = guessAnyType(data.oid);
|
||||
if(valueType == nullptr) {
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Deserializer::deserializeAny()]: Error. Unknown OID.");
|
||||
}
|
||||
|
||||
auto value = _this->deserialize(data, valueType);
|
||||
auto anyHandle = std::make_shared<data::mapping::type::AnyHandle>(value.getPtr(), value.valueType);
|
||||
|
||||
return oatpp::Void(anyHandle, Any::Class::getType());
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#ifndef oatpp_postgresql_mapping_Deserializer_hpp
|
||||
#define oatpp_postgresql_mapping_Deserializer_hpp
|
||||
|
||||
#include "TypeMapper.hpp"
|
||||
#include "oatpp/core/data/mapping/TypeResolver.hpp"
|
||||
#include "oatpp/core/Types.hpp"
|
||||
|
||||
@ -34,8 +33,6 @@
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
class Deserializer {
|
||||
public:
|
||||
typedef oatpp::data::mapping::type::Type Type;
|
||||
public:
|
||||
|
||||
struct InData {
|
||||
@ -58,9 +55,10 @@ private:
|
||||
static v_int32 deInt4(const InData& data);
|
||||
static v_int64 deInt8(const InData& data);
|
||||
static v_int64 deInt(const InData& data);
|
||||
|
||||
static const oatpp::Type* guessAnyType(Oid oid);
|
||||
private:
|
||||
std::vector<DeserializerMethod> m_methods;
|
||||
TypeMapper m_typeMapper;
|
||||
public:
|
||||
|
||||
Deserializer();
|
||||
@ -69,7 +67,7 @@ public:
|
||||
|
||||
oatpp::Void deserialize(const InData& data, const Type* type) const;
|
||||
|
||||
public:
|
||||
private:
|
||||
|
||||
static oatpp::Void deserializeString(const Deserializer* _this, const InData& data, const Type* type);
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "Serializer.hpp"
|
||||
|
||||
#include "Oid.hpp"
|
||||
#include "oatpp-postgresql/Types.hpp"
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
@ -35,11 +36,15 @@
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
Serializer::Serializer() {
|
||||
setSerializerMethods();
|
||||
setTypeOidMethods();
|
||||
}
|
||||
|
||||
void Serializer::setSerializerMethods() {
|
||||
|
||||
m_methods.resize(data::mapping::type::ClassId::getClassCount(), nullptr);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::String::CLASS_ID, &Serializer::serializeString);
|
||||
setSerializerMethod(data::mapping::type::__class::Any::CLASS_ID, nullptr);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::Int8::CLASS_ID, &Serializer::serializeInt8);
|
||||
setSerializerMethod(data::mapping::type::__class::UInt8::CLASS_ID, &Serializer::serializeUInt8);
|
||||
@ -57,22 +62,39 @@ Serializer::Serializer() {
|
||||
setSerializerMethod(data::mapping::type::__class::Float64::CLASS_ID, &Serializer::serializeFloat64);
|
||||
setSerializerMethod(data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::serializeBoolean);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractObject::CLASS_ID, nullptr);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractEnum::CLASS_ID, nullptr);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractVector::CLASS_ID, nullptr);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractList::CLASS_ID, nullptr);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractUnorderedSet::CLASS_ID, nullptr);
|
||||
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractPairList::CLASS_ID, nullptr);
|
||||
setSerializerMethod(data::mapping::type::__class::AbstractUnorderedMap::CLASS_ID, nullptr);
|
||||
|
||||
////
|
||||
|
||||
setSerializerMethod(postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::serializeUuid);
|
||||
|
||||
}
|
||||
|
||||
void Serializer::setTypeOidMethods() {
|
||||
|
||||
m_typeOidMethods.resize(data::mapping::type::ClassId::getClassCount(), nullptr);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::String::CLASS_ID, &Serializer::getTypeOid<TEXTOID>);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::Int8::CLASS_ID, &Serializer::getTypeOid<INT2OID>);
|
||||
setTypeOidMethod(data::mapping::type::__class::UInt8::CLASS_ID, &Serializer::getTypeOid<INT2OID>);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::Int16::CLASS_ID, &Serializer::getTypeOid<INT2OID>);
|
||||
setTypeOidMethod(data::mapping::type::__class::UInt16::CLASS_ID, &Serializer::getTypeOid<INT4OID>);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::Int32::CLASS_ID, &Serializer::getTypeOid<INT4OID>);
|
||||
setTypeOidMethod(data::mapping::type::__class::UInt32::CLASS_ID, &Serializer::getTypeOid<INT8OID>);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::Int64::CLASS_ID, &Serializer::getTypeOid<INT8OID>);
|
||||
|
||||
setTypeOidMethod(data::mapping::type::__class::Float32::CLASS_ID, &Serializer::getTypeOid<FLOAT4OID>);
|
||||
setTypeOidMethod(data::mapping::type::__class::Float64::CLASS_ID, &Serializer::getTypeOid<FLOAT8OID>);
|
||||
setTypeOidMethod(data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::getTypeOid<BOOLOID>);
|
||||
|
||||
////
|
||||
|
||||
setTypeOidMethod(postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::getTypeOid<UUIDOID>);
|
||||
|
||||
}
|
||||
|
||||
void Serializer::setSerializerMethod(const data::mapping::type::ClassId& classId, SerializerMethod method) {
|
||||
const v_uint32 id = classId.id;
|
||||
if(id < m_methods.size()) {
|
||||
@ -82,6 +104,15 @@ void Serializer::setSerializerMethod(const data::mapping::type::ClassId& classId
|
||||
}
|
||||
}
|
||||
|
||||
void Serializer::setTypeOidMethod(const data::mapping::type::ClassId& classId, TypeOidMethod method) {
|
||||
const v_uint32 id = classId.id;
|
||||
if(id < m_methods.size()) {
|
||||
m_typeOidMethods[id] = method;
|
||||
} else {
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Serializer::setTypeOidMethod()]: Error. Unknown classId");
|
||||
}
|
||||
}
|
||||
|
||||
void Serializer::serialize(OutputData& outData, const oatpp::Void& polymorph) const {
|
||||
auto id = polymorph.valueType->classId.id;
|
||||
auto& method = m_methods[id];
|
||||
@ -94,6 +125,20 @@ void Serializer::serialize(OutputData& outData, const oatpp::Void& polymorph) co
|
||||
}
|
||||
}
|
||||
|
||||
Oid Serializer::getTypeOid(const oatpp::Type* type) const {
|
||||
|
||||
auto id = type->classId.id;
|
||||
auto& method = m_typeOidMethods[id];
|
||||
if(method) {
|
||||
return (*method)(this, type);
|
||||
}
|
||||
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Serializer::getTypeOid()]: "
|
||||
"Error. Can't derive OID for type '" + std::string(type->classId.name) +
|
||||
"'");
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Serializer utility functions
|
||||
|
||||
@ -141,6 +186,7 @@ void Serializer::serializeString(OutputData& outData, const oatpp::Void& polymor
|
||||
outData.data = (char *)buff->getData();
|
||||
outData.dataSize = buff->getSize();
|
||||
outData.dataFormat = 1;
|
||||
outData.oid = TEXTOID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -150,6 +196,7 @@ void Serializer::serializeInt8(OutputData& outData, const oatpp::Void& polymorph
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Int8>();
|
||||
serInt2(outData, *v);
|
||||
outData.oid = INT2OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -159,6 +206,7 @@ void Serializer::serializeUInt8(OutputData& outData, const oatpp::Void& polymorp
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::UInt8>();
|
||||
serInt2(outData, *v);
|
||||
outData.oid = INT2OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -168,6 +216,7 @@ void Serializer::serializeInt16(OutputData& outData, const oatpp::Void& polymorp
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Int16>();
|
||||
serInt2(outData, *v);
|
||||
outData.oid = INT2OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -177,6 +226,7 @@ void Serializer::serializeUInt16(OutputData& outData, const oatpp::Void& polymor
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::UInt16>();
|
||||
serInt4(outData, *v);
|
||||
outData.oid = INT4OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -186,6 +236,7 @@ void Serializer::serializeInt32(OutputData& outData, const oatpp::Void& polymorp
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Int32>();
|
||||
serInt4(outData, *v);
|
||||
outData.oid = INT4OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -195,6 +246,7 @@ void Serializer::serializeUInt32(OutputData& outData, const oatpp::Void& polymor
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::UInt32>();
|
||||
serInt8(outData, *v);
|
||||
outData.oid = INT8OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
@ -204,19 +256,21 @@ void Serializer::serializeInt64(OutputData& outData, const oatpp::Void& polymorp
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Int64>();
|
||||
serInt8(outData, *v);
|
||||
outData.oid = INT8OID;
|
||||
} else {
|
||||
serNull(outData);
|
||||
}
|
||||
}
|
||||
|
||||
void Serializer::serializeUInt64(OutputData& outData, const oatpp::Void& polymorph) {
|
||||
serNull(outData);
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Serializer::serializeUInt64()]: Error. Not implemented!");
|
||||
}
|
||||
|
||||
void Serializer::serializeFloat32(OutputData& outData, const oatpp::Void& polymorph) {
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Float32>();
|
||||
serInt4(outData, *((p_int32) v.get()));
|
||||
outData.oid = FLOAT4OID;
|
||||
} else{
|
||||
serNull(outData);
|
||||
}
|
||||
@ -226,6 +280,7 @@ void Serializer::serializeFloat64(OutputData& outData, const oatpp::Void& polymo
|
||||
if(polymorph) {
|
||||
auto v = polymorph.staticCast<oatpp::Float64>();
|
||||
serInt8(outData, *((p_int64) v.get()));
|
||||
outData.oid = FLOAT8OID;
|
||||
} else{
|
||||
serNull(outData);
|
||||
}
|
||||
@ -239,6 +294,7 @@ void Serializer::serializeBoolean(OutputData& outData, const oatpp::Void& polymo
|
||||
outData.dataSize = 1;
|
||||
outData.dataFormat = 1;
|
||||
outData.data[0] = (bool)v;
|
||||
outData.oid = BOOLOID;
|
||||
} else{
|
||||
serNull(outData);
|
||||
}
|
||||
@ -250,6 +306,7 @@ void Serializer::serializeUuid(OutputData& outData, const oatpp::Void& polymorph
|
||||
outData.data = (char*) v->getData();
|
||||
outData.dataSize = v->getSize();
|
||||
outData.dataFormat = 1;
|
||||
outData.oid = UUIDOID;
|
||||
} else{
|
||||
serNull(outData);
|
||||
}
|
||||
|
@ -27,12 +27,15 @@
|
||||
|
||||
#include "oatpp/core/Types.hpp"
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
class Serializer {
|
||||
public:
|
||||
|
||||
struct OutputData {
|
||||
Oid oid;
|
||||
std::unique_ptr<char[]> dataBuffer;
|
||||
char* data;
|
||||
int dataSize;
|
||||
@ -41,6 +44,7 @@ public:
|
||||
|
||||
public:
|
||||
typedef void (*SerializerMethod)(OutputData&, const oatpp::Void&);
|
||||
typedef Oid (*TypeOidMethod)(const Serializer*, const oatpp::Type*);
|
||||
private:
|
||||
|
||||
static void serNull(OutputData& outData);
|
||||
@ -48,109 +52,127 @@ private:
|
||||
static void serInt4(OutputData& outData, v_int32 value);
|
||||
static void serInt8(OutputData& outData, v_int64 value);
|
||||
|
||||
private:
|
||||
|
||||
void setSerializerMethods();
|
||||
void setTypeOidMethods();
|
||||
|
||||
private:
|
||||
std::vector<SerializerMethod> m_methods;
|
||||
std::vector<TypeOidMethod> m_typeOidMethods;
|
||||
public:
|
||||
|
||||
Serializer();
|
||||
|
||||
void setSerializerMethod(const data::mapping::type::ClassId& classId, SerializerMethod method);
|
||||
void setTypeOidMethod(const data::mapping::type::ClassId& classId, TypeOidMethod method);
|
||||
|
||||
void serialize(OutputData& outData, const oatpp::Void& polymorph) const;
|
||||
|
||||
public:
|
||||
Oid getTypeOid(const oatpp::Type* type) const;
|
||||
|
||||
/**
|
||||
private:
|
||||
|
||||
/*
|
||||
* OID used - TEXTOID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeString(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT2OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeInt8(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT2OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeUInt8(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT2OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeInt16(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT4OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeUInt16(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT4OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeInt32(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT8OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeUInt32(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - INT8OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeInt64(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Not implemented
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeUInt64(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - FLOAT4OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeFloat32(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - FLOAT8OID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeFloat64(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - BOOLOID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeBoolean(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
/**
|
||||
/*
|
||||
* OID used - UUIDOID
|
||||
* @param outData
|
||||
* @param polymorph
|
||||
*/
|
||||
static void serializeUuid(OutputData& outData, const oatpp::Void& polymorph);
|
||||
|
||||
private:
|
||||
|
||||
template<Oid OID>
|
||||
static Oid getTypeOid(const Serializer* _this, const oatpp::Type* type) {
|
||||
(void) _this;
|
||||
(void) type;
|
||||
return OID;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
@ -1,124 +0,0 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "TypeMapper.hpp"
|
||||
|
||||
#include "Oid.hpp"
|
||||
#include "oatpp-postgresql/Types.hpp"
|
||||
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
TypeMapper::TypeMapper() {
|
||||
|
||||
{
|
||||
m_oids.resize(data::mapping::type::ClassId::getClassCount(), 0);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::String::CLASS_ID, TEXTOID);
|
||||
setTypeOid(data::mapping::type::__class::Any::CLASS_ID, 0);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::Int8::CLASS_ID, INT2OID);
|
||||
setTypeOid(data::mapping::type::__class::UInt8::CLASS_ID, INT2OID);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::Int16::CLASS_ID, INT2OID);
|
||||
setTypeOid(data::mapping::type::__class::UInt16::CLASS_ID, INT4OID);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::Int32::CLASS_ID, INT4OID);
|
||||
setTypeOid(data::mapping::type::__class::UInt32::CLASS_ID, INT8OID);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::Int64::CLASS_ID, INT8OID);
|
||||
setTypeOid(data::mapping::type::__class::UInt64::CLASS_ID, 0);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::Float32::CLASS_ID, FLOAT4OID);
|
||||
setTypeOid(data::mapping::type::__class::Float64::CLASS_ID, FLOAT8OID);
|
||||
setTypeOid(data::mapping::type::__class::Boolean::CLASS_ID, BOOLOID);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::AbstractObject::CLASS_ID, 0);
|
||||
setTypeOid(data::mapping::type::__class::AbstractEnum::CLASS_ID, 0);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::AbstractVector::CLASS_ID, 0);
|
||||
setTypeOid(data::mapping::type::__class::AbstractList::CLASS_ID, 0);
|
||||
setTypeOid(data::mapping::type::__class::AbstractUnorderedSet::CLASS_ID, 0);
|
||||
|
||||
setTypeOid(data::mapping::type::__class::AbstractPairList::CLASS_ID, 0);
|
||||
setTypeOid(data::mapping::type::__class::AbstractUnorderedMap::CLASS_ID, 0);
|
||||
|
||||
////
|
||||
|
||||
setTypeOid(postgresql::mapping::type::__class::Uuid::CLASS_ID, UUIDOID);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
setOidType(TEXTOID, oatpp::String::Class::getType());
|
||||
setOidType(VARCHAROID, oatpp::String::Class::getType());
|
||||
|
||||
setOidType(INT2OID, oatpp::Int16::Class::getType());
|
||||
setOidType(INT4OID, oatpp::Int32::Class::getType());
|
||||
setOidType(INT8OID, oatpp::Int64::Class::getType());
|
||||
|
||||
setOidType(FLOAT4OID, oatpp::Float32::Class::getType());
|
||||
setOidType(FLOAT8OID, oatpp::Float64::Class::getType());
|
||||
|
||||
setOidType(BOOLOID, oatpp::Boolean::Class::getType());
|
||||
|
||||
////
|
||||
|
||||
setOidType(TIMESTAMPOID, oatpp::UInt64::Class::getType());
|
||||
|
||||
setOidType(UUIDOID, oatpp::postgresql::Uuid::Class::getType());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TypeMapper::setTypeOid(const data::mapping::type::ClassId& classId, Oid oid) {
|
||||
const v_uint32 id = classId.id;
|
||||
if(id < m_oids.size()) {
|
||||
m_oids[id] = oid;
|
||||
} else {
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::TypeMapper::setTypeOid()]: Error. Unknown classId");
|
||||
}
|
||||
}
|
||||
|
||||
void TypeMapper::setOidType(Oid oid, const data::mapping::type::Type* type) {
|
||||
m_types[oid] = type;
|
||||
}
|
||||
|
||||
Oid TypeMapper::getTypeOid(const data::mapping::type::Type* type) const {
|
||||
const v_uint32 id = type->classId.id;
|
||||
if(id < m_oids.size()) {
|
||||
return m_oids[id];
|
||||
}
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::TypeMapper::getTypeOid()]: Error. Unknown classId");
|
||||
}
|
||||
|
||||
const data::mapping::type::Type* TypeMapper::getOidType(Oid oid) const {
|
||||
auto it = m_types.find(oid);
|
||||
if(it != m_types.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}}}
|
@ -1,52 +0,0 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* Project _____ __ ____ _ _
|
||||
* ( _ ) /__\ (_ _)_| |_ _| |_
|
||||
* )(_)( /(__)\ )( (_ _)(_ _)
|
||||
* (_____)(__)(__)(__) |_| |_|
|
||||
*
|
||||
*
|
||||
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef oatpp_postgresql_mapping_TypeMapper_hpp
|
||||
#define oatpp_postgresql_mapping_TypeMapper_hpp
|
||||
|
||||
#include "oatpp/core/Types.hpp"
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
class TypeMapper {
|
||||
private:
|
||||
std::vector<Oid> m_oids;
|
||||
std::unordered_map<Oid, const data::mapping::type::Type*> m_types;
|
||||
public:
|
||||
|
||||
TypeMapper();
|
||||
|
||||
void setTypeOid(const data::mapping::type::ClassId& classId, Oid oid);
|
||||
void setOidType(Oid oid, const data::mapping::type::Type* type);
|
||||
|
||||
Oid getTypeOid(const data::mapping::type::Type* type) const;
|
||||
const data::mapping::type::Type* getOidType(Oid oid) const;
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif // oatpp_postgresql_mapping_TypeMapper_hpp
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "steps to install some my dependency"
|
47
utility/install-oatpp-modules.sh
Executable file
47
utility/install-oatpp-modules.sh
Executable file
@ -0,0 +1,47 @@
|
||||
#!/bin/sh
|
||||
|
||||
BUILD_TYPE=$1
|
||||
|
||||
if [ -z "$BUILD_TYPE" ]; then
|
||||
BUILD_TYPE="Debug"
|
||||
fi
|
||||
|
||||
rm -rf tmp
|
||||
|
||||
mkdir tmp
|
||||
cd tmp
|
||||
|
||||
##########################################################
|
||||
## install oatpp module
|
||||
|
||||
function install_module () {
|
||||
|
||||
BUILD_TYPE=$1
|
||||
MODULE_NAME=$2
|
||||
NPROC=$(nproc)
|
||||
|
||||
if [ -z "$NPROC" ]; then
|
||||
NPROC=1
|
||||
fi
|
||||
|
||||
echo "\n\nINSTALLING MODULE '$MODULE_NAME' ($BUILD_TYPE) using $NPROC threads ...\n\n"
|
||||
|
||||
git clone --depth=1 https://github.com/oatpp/$MODULE_NAME
|
||||
|
||||
cd $MODULE_NAME
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
cmake -DOATPP_DISABLE_ENV_OBJECT_COUNTERS=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOATPP_BUILD_TESTS=OFF ..
|
||||
make install -j $NPROC
|
||||
|
||||
cd ../../
|
||||
|
||||
}
|
||||
|
||||
##########################################################
|
||||
|
||||
install_module $BUILD_TYPE oatpp
|
||||
|
||||
cd ../
|
||||
rm -rf tmp
|
Loading…
Reference in New Issue
Block a user