update ghttp api
This commit is contained in:
parent
4997c3bfc4
commit
96f2db6306
|
@ -15,6 +15,9 @@ using namespace std;
|
|||
// before you run this example, make sure that you have started up ghttp service (using bin/ghttp db_name port)
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
string username = "root";
|
||||
string password = "123456";
|
||||
|
||||
// initialize the GStore server's IP address and port.
|
||||
cout << "in" <<endl;
|
||||
GstoreConnector gc("172.31.222.94", 9000);
|
||||
|
@ -22,10 +25,10 @@ int main(int argc, char * argv[])
|
|||
// build a new database by a RDF file.
|
||||
// note that the relative path is related to gserver
|
||||
|
||||
gc.build("lubm", "data/lubm/lubm.nt", "root", "123456");
|
||||
gc.build("lubm", "data/lubm/lubm.nt", username, password);
|
||||
|
||||
//load the database that you've build.
|
||||
gc.load("lubm", "root", "123456");
|
||||
gc.load("lubm", username, password);
|
||||
// then you can execute SPARQL query on this database.
|
||||
std::string sparql = "select ?x where \
|
||||
{ \
|
||||
|
@ -37,29 +40,30 @@ int main(int argc, char * argv[])
|
|||
?z <ub:worksFor> ?w. \
|
||||
?w <ub:name> <Department0>. \
|
||||
}";
|
||||
std::string answer = gc.query("root", "123456", "lubm", sparql);
|
||||
|
||||
std::string answer = gc.query(username, password, "lubm", sparql);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
// make a SPARQL query and save the result in ans.txt
|
||||
gc.query("root", "123456", "lubm", sparql, "ans.txt");
|
||||
gc.query(username, password, "lubm", sparql, "ans.txt");
|
||||
|
||||
// unload this database.
|
||||
gc.unload("lubm", "root", "123456");
|
||||
gc.unload("lubm", username, password);
|
||||
// also, you can load some exist database directly and then query.
|
||||
gc.load("lubm", "root", "123456");
|
||||
answer = gc.query("root", "123456", "lubm", sparql);
|
||||
gc.load("lubm", username, password);
|
||||
answer = gc.query(username, password, "lubm", sparql);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
//you can monitor a database
|
||||
answer = gc.monitor("lubm");
|
||||
answer = gc.monitor("lubm", username, password);
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
|
||||
//add a user(with username: Jack, password: 2)
|
||||
answer = gc.user("add_user", "root", "123456", "Jack", "2");
|
||||
answer = gc.user("add_user", username, password, "Jack", "2");
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
//add privilege to user Jack(add_query, add_load, add_unload)
|
||||
answer = gc.user("add_query", "root", "123456", "Jack", "lubm");
|
||||
answer = gc.user("add_query", username, password, "Jack", "lubm");
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
//then Jack can query the database LUBM10
|
||||
|
@ -67,15 +71,15 @@ int main(int argc, char * argv[])
|
|||
std::cout << answer << std::endl;
|
||||
|
||||
//delete privilege of user Jack(delete_query, delete_load, delete_unload)
|
||||
answer = gc.user("delete_query", "root", "123456", "Jack", "lubm");
|
||||
answer = gc.user("delete_query", username, password, "Jack", "lubm");
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
//delete user(with username: Jack, password: 2)
|
||||
answer = gc.user("delete_user", "root", "123456", "Jack", "2");
|
||||
answer = gc.user("delete_user", username, password, "Jack", "2");
|
||||
std::cout << answer << std::endl;
|
||||
|
||||
gc.unload("lubm", "root", "123456");
|
||||
|
||||
return 0;
|
||||
gc.unload("lubm", username, password);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,11 +175,11 @@ void GstoreConnector::query(string username, string password, string db_name, st
|
|||
}
|
||||
|
||||
string
|
||||
GstoreConnector::show()
|
||||
GstoreConnector::show(string username, string password)
|
||||
{
|
||||
string url = "http://" + this->serverIP + ":" + std::to_string(this->serverPort);
|
||||
|
||||
string cmd = url + "/?operation=show";
|
||||
string cmd = url + "/?operation=show&username=" + username + "&password=" + password;
|
||||
string recv_msg;
|
||||
int ret = hc.Get(cmd, recv_msg);
|
||||
return recv_msg;
|
||||
|
@ -235,21 +235,21 @@ GstoreConnector::showUser()
|
|||
return recv_msg;
|
||||
}
|
||||
string
|
||||
GstoreConnector::monitor(string db_name)
|
||||
GstoreConnector::monitor(string db_name, string username, string password)
|
||||
{
|
||||
string url = "http://" + this->serverIP + ":" + std::to_string(this->serverPort);
|
||||
|
||||
string cmd = url + "/?operation=monitor&db_name=" + db_name;
|
||||
string cmd = url + "/?operation=monitor&db_name=" + db_name + "&username=" + username + "&password=" + password;
|
||||
string recv_msg;
|
||||
int ret = hc.Get(cmd, recv_msg);
|
||||
return recv_msg;
|
||||
}
|
||||
string
|
||||
GstoreConnector::checkpoint(string db_name)
|
||||
GstoreConnector::checkpoint(string db_name, string username, string password)
|
||||
{
|
||||
string url = "http://" + this->serverIP + ":" + std::to_string(this->serverPort);
|
||||
|
||||
string cmd = url + "/?operation=checkpoint&db_name=" + db_name;
|
||||
string cmd = url + "/?operation=checkpoint&db_name=" + db_name + "&username=" + username + "&password=" + password;
|
||||
string recv_msg;
|
||||
int ret = hc.Get(cmd, recv_msg);
|
||||
return recv_msg;
|
||||
|
|
|
@ -32,11 +32,11 @@ public:
|
|||
bool drop(std::string _db_name);
|
||||
std::string query(std::string username, std::string password, std::string db_name, std::string sparql);
|
||||
void query(std::string username, std::string password, std::string db_name, std::string sparql, std::string filename);
|
||||
std::string show(); //show all databases
|
||||
std::string show(std::string username, std::string password); //show all databases
|
||||
std::string user(std::string type, std::string username1, std::string password1, std::string username2, std::string addtion);
|
||||
std::string showUser();
|
||||
std::string monitor(std::string db_name);
|
||||
std::string checkpoint(std::string db_name);
|
||||
std::string monitor(std::string db_name, std::string username, std::string password);
|
||||
std::string checkpoint(std::string db_name, std::string username, std::string password);
|
||||
static const std::string defaultServerIP;
|
||||
static const unsigned short defaultServerPort;
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@ public class JavaAPIExample
|
|||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String username = "root";
|
||||
String password = "123456";
|
||||
|
||||
// initialize the GStore server's IP address and port.
|
||||
GstoreConnector gc = new GstoreConnector("172.31.222.94", 9000);
|
||||
|
||||
|
@ -86,8 +89,8 @@ public class JavaAPIExample
|
|||
|
||||
// build a new database by a RDF file.
|
||||
// note that the relative path is related to gserver.
|
||||
gc.build("lubm", "data/lubm/lubm.nt", "root", "123456");
|
||||
gc.load("lubm", "root", "123456");
|
||||
gc.build("lubm", "data/lubm/lubm.nt", username, password);
|
||||
gc.load("lubm", username, password);
|
||||
|
||||
// then you can execute SPARQL query on this database.
|
||||
String sparql = "select ?x where "
|
||||
|
@ -100,14 +103,14 @@ public class JavaAPIExample
|
|||
+ "?z <ub:worksFor> ?w. "
|
||||
+ "?w <ub:name> <Department0>. "
|
||||
+ "}";
|
||||
String answer = gc.query("root", "123456", "lubm", sparql);
|
||||
String answer = gc.query(username, password, "lubm", sparql);
|
||||
System.out.println(answer);
|
||||
|
||||
// unload this database.
|
||||
gc.unload("lubm", "root", "123456");
|
||||
gc.unload("lubm", username, password);
|
||||
|
||||
// also, you can load some exist database directly and then query.
|
||||
gc.load("lubm", "root", "123456");
|
||||
gc.load("lubm", username, password);
|
||||
|
||||
//sparql = "delete where "
|
||||
//+ "{"
|
||||
|
@ -117,32 +120,32 @@ public class JavaAPIExample
|
|||
//PERFORMANCE: if we use the query above(as comment), result will be very large and the time cost is large, too
|
||||
//The method to improve it is to receive a line and output/save to file at once, instead of combining all lines into a String
|
||||
//The related code is in api/http/java/src/jgsc/GstoreConnector.java
|
||||
answer = gc.query("root", "123456", "lubm", sparql);
|
||||
answer = gc.query(username, password, "lubm", sparql);
|
||||
System.out.println(answer);
|
||||
|
||||
|
||||
// make a SPARQL query and save the result in ans.txt
|
||||
gc.query("root", "123456", "lubm", sparql, "ans.txt");
|
||||
gc.query(username, password, "lubm", sparql, "ans.txt");
|
||||
|
||||
//monitor a database
|
||||
answer = gc.monitor("lubm");
|
||||
answer = gc.monitor("lubm", username, password);
|
||||
System.out.println(answer);
|
||||
//add a user(with username: Jack, password: 2)
|
||||
answer = gc.user("add_user", "root", "123456", "Jack", "2");
|
||||
answer = gc.user("add_user", username, password, "Jack", "2");
|
||||
System.out.println(answer);
|
||||
//add privilege to user Jack(add_query, add_load, add_unload)
|
||||
answer = gc.user("add_query", "root", "123456", "Jack", "lubm");
|
||||
answer = gc.user("add_query", username, password, "Jack", "lubm");
|
||||
System.out.println(answer);
|
||||
//then Jack can query the database LUBM10
|
||||
answer = gc.query("Jack", "2", "lubm", sparql);
|
||||
System.out.println(answer);
|
||||
//delete privilege of user Jack(delete_query, delete_load, delete_unload)
|
||||
answer = gc.user("delete_query", "root", "123456", "Jack", "lubm");
|
||||
answer = gc.user("delete_query", username, password, "Jack", "lubm");
|
||||
System.out.println(answer);
|
||||
//delete user(with username: Jack, password: 2)
|
||||
answer = gc.user("delete_user", "root", "123456", "Jack", "2");
|
||||
answer = gc.user("delete_user", username, password, "Jack", "2");
|
||||
System.out.println(answer);
|
||||
|
||||
gc.unload("lubm", "root", "123456");
|
||||
gc.unload("lubm", username, password);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,14 +315,14 @@ public class GstoreConnector {
|
|||
// }
|
||||
|
||||
//show all databases
|
||||
public String show() {
|
||||
public String show(String _username, String _password) {
|
||||
boolean connect_return = this.connect();
|
||||
if (!connect_return) {
|
||||
System.err.println("connect to server error. @GstoreConnector.show");
|
||||
return "connect to server error.";
|
||||
}
|
||||
|
||||
String cmd = "?operation=show";
|
||||
String cmd = "?operation=show&username=" + _username + "&password=" + _password;
|
||||
String msg = this.sendGet(cmd);
|
||||
|
||||
this.disconnect();
|
||||
|
@ -354,27 +354,27 @@ public class GstoreConnector {
|
|||
this.disconnect();
|
||||
return msg;
|
||||
}
|
||||
public String monitor(String db_name) {
|
||||
public String monitor(String db_name, String _username, String _password) {
|
||||
boolean connect_return = this.connect();
|
||||
if (!connect_return) {
|
||||
System.err.println("connect to server error. @GstoreConnector.show");
|
||||
return "connect to server error.";
|
||||
}
|
||||
|
||||
String cmd = "?operation=monitor&db_name=" + db_name;
|
||||
String cmd = "?operation=monitor&db_name=" + db_name + "&username=" + _username + "&password=" + _password;
|
||||
String msg = this.sendGet(cmd);
|
||||
|
||||
this.disconnect();
|
||||
return msg;
|
||||
}
|
||||
public String checkpoint(String db_name) {
|
||||
public String checkpoint(String db_name, String _username, String _password) {
|
||||
boolean connect_return = this.connect();
|
||||
if (!connect_return) {
|
||||
System.err.println("connect to server error. @GstoreConnector.show");
|
||||
return "connect to server error.";
|
||||
}
|
||||
|
||||
String cmd = "?operation=checkpoint&db_name=" + db_name;
|
||||
String cmd = "?operation=checkpoint&db_name=" + db_name + "&username=" + _username + "&password=" + _password;
|
||||
String msg = this.sendGet(cmd);
|
||||
|
||||
this.disconnect();
|
||||
|
|
|
@ -37,4 +37,20 @@ echo $gc->query($username, $password, "lubm", $sparql) . PHP_EOL;
|
|||
// fquery--make a SPARQL query and save the result in the file
|
||||
$gc->fquery($username, $password, "lubm", $sparql, $filename);
|
||||
|
||||
// show user information
|
||||
$ret = $gc->showUser();
|
||||
echo $ret. PHP_EOL;
|
||||
|
||||
// show
|
||||
$ret = $gc->show($username, $password);
|
||||
echo $ret. PHP_EOL;
|
||||
|
||||
// monitor the database
|
||||
$ret = $gc->monitor("lubm", $username, $password);
|
||||
echo $ret. PHP_EOL;
|
||||
|
||||
// save the database
|
||||
$ret = $gc->checkpoint("lubm", $username, $password);
|
||||
echo $ret. PHP_EOL;
|
||||
|
||||
?>
|
||||
|
|
|
@ -105,5 +105,30 @@ class GstoreConnector {
|
|||
$this->fGet($cmd, $filename);
|
||||
return;
|
||||
}
|
||||
|
||||
function show($username, $password) {
|
||||
$cmd = $this->Url . "/?operation=show&username=" . $username . "&password=" . $password;
|
||||
return $this->Get($cmd);
|
||||
}
|
||||
|
||||
function user($type, $username1, $password1, $username2, $addition) {
|
||||
$cmd = $this->Url . "/?operation=user&type=" . $type . "&username1=" . $username1 . "&password1=" . $password1 . "&username2" . $username2 . "&addition=" . $addition;
|
||||
return $this->Get($cmd);
|
||||
}
|
||||
|
||||
function showUser() {
|
||||
$cmd = $this->Url . "/?operation=showUser";
|
||||
return $this->Get($cmd);
|
||||
}
|
||||
|
||||
function monitor($db_name, $username, $password) {
|
||||
$cmd = $this->Url . "/?operation=monitor&db_name=" . $db_name . "&username=" . $username . "&password=" . $password;
|
||||
return $this->Get($cmd);
|
||||
}
|
||||
|
||||
function checkpoint($db_name, $username, $password) {
|
||||
$cmd = $this->Url . "/?operation=checkpoint&db_name=" . $db_name . "&username=" . $username . "&password=" . $password;
|
||||
return $this->Get($cmd);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue