-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkit.cpp
150 lines (127 loc) · 4.59 KB
/
kit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//
// kit.cpp
// Neo4j-cpp-driver
//
// Created by skyblue on 2017/7/9.
// Copyright © 2017年 skyblue. All rights reserved.
//
#include "kit.hpp"
#include <sstream>
namespace neo4jDriver
{
//Neo4j工具包
std::string Kit::getStatusCode(std::string httpHeader)
{
size_t begin = httpHeader.find_first_of(" ");
std::string temp = httpHeader.substr(begin+1, httpHeader.length());
size_t end = temp.find_first_of(" ");
std::string statusCode = temp.substr(0, end);
return statusCode;
};
std::string Kit::getWhereString(std::string fieldName, Json::Value &properties, std::string idFieldName)
{
return Kit::append(fieldName, properties, " AND ", idFieldName);
};
std::string Kit::getWhereString(std::string fieldName, std::string propertiesNamePrefix, Json::Value &properties, std::string idFieldName)
{
return Kit::append(fieldName, propertiesNamePrefix, properties, " AND ", idFieldName);
};
std::string Kit::getSetString(std::string fieldName, Json::Value &properties)
{
return Kit::append(fieldName, properties, ",");
};
std::string Kit::getLabelString(const std::vector<std::string> &labels)
{
std::string labelsString = "";
for (int i=0; i < labels.size(); i++)
{
if (i+1 < labels.size())
{
labelsString += labels[i] + ":";
}
else
{
labelsString += labels[i];
}
}
return labelsString;
};
unsigned long long int Kit::getNodeOrRelationshipID(std::string nodeOrRelationshipSelf)
{
size_t id;
size_t begin = nodeOrRelationshipSelf.find_last_of("/");
std::string idString = nodeOrRelationshipSelf.substr(begin + 1, nodeOrRelationshipSelf.length());
std::stringstream sstream;
sstream << idString;
sstream >> id;
sstream.clear();
return id;
};
/*
* 私有方法
*/
std::string Kit::append(std::string fieldName, Json::Value &properties, std::string appendToken, std::string idFieldName)
{
std::string parameters = "";
bool isFirst = true;
for (Json::ValueIterator i = properties.begin(); i != properties.end(); i++)
{
if (isFirst)
{
if (idFieldName == "" || (idFieldName != "" && i.name() != idFieldName))
{
parameters += fieldName + "." + i.name() + "={" + i.name() + "}";
}
else
{
parameters += "id(" + fieldName + ")={" + i.name() + "}";
}
isFirst = false;
}
else
{
if (idFieldName == "" || (idFieldName != "" && i.name() != idFieldName))
{
parameters += appendToken + fieldName + "." + i.name() + "={" + i.name() + "}";
}
else
{
parameters += appendToken + "id(" + fieldName + ")={" + i.name() + "}";
}
}
}
return parameters;
};
std::string Kit::append(std::string fieldName, std::string propertiesNamePrefix, Json::Value &properties, std::string appendToken, std::string idFieldName)
{
std::string parameters = "";
bool isFirst = true;
for (Json::ValueIterator i = properties.begin(); i != properties.end(); i++)
{
if (isFirst)
{
if (idFieldName == "" || (idFieldName != "" && i.name() != idFieldName))
{
parameters += fieldName + "." + i.name() + "={" + propertiesNamePrefix + i.name() + "}";
}
else
{
parameters += "id(" + fieldName + ")={" + propertiesNamePrefix + i.name() + "}";
}
isFirst = false;
}
else
{
if (idFieldName == "" || (idFieldName != "" && i.name() != idFieldName))
{
parameters += appendToken + fieldName + "." + i.name() + "={" + propertiesNamePrefix + i.name() + "}";
}
else
{
parameters += appendToken + "id(" + fieldName + ")={" + propertiesNamePrefix + i.name() + "}";
}
}
}
return parameters;
};
}