如何在 Orientdb 中使用 HTTP 创建顶点和边?
How can i create vertex and edge with HTTP in Orientdb?
这是我的代码。我做了一个 "GET" 方法来获得我的数据库的响应。
然后我读取了我自己的文件csv。在这一点上一切都很好,但是......我不知道我该如何做 "POST" 方法。我知道我需要使用 "addRequestProperty" 方法。
有创建顶点和边的想法吗?
public void run() throws MalformedURLException, JSONException, IOException {
String viaURl = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxx/mydb";
URL url = new URL(viaURl);
HttpURLConnection conexion = null;
String texto = null;
String json;
BufferedReader in = null, in2 = null;
int numDump = 5;
String dato;
String csvSplitBy = ";";
int numApps = 0;
OutputStreamWriter out;
try {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxxx", "xxxxxxxxxxxxx.".toCharArray());
}
});
conexion = (HttpURLConnection) url.openConnection();
conexion.setRequestMethod("GET");
conexion.connect();
System.out.println("¡¡¡Conectado!!!");
in = new BufferedReader(new InputStreamReader(conexion.getInputStream()));
out = new OutputStreamWriter(conexion.getOutputStream());
json = "";
while ((texto = in.readLine()) != null) {
json += texto;
}
in.close();
System.out.println(json);
conexion.setDoOutput(true);
try {
for (int i = 0; i < numDump; i++) {
String csvFile = "/home/danicroque/dump/dump_" + i;
try {
in2 = new BufferedReader(new FileReader(csvFile));
while ((dato = in2.readLine()) != null) {
numApps++;
String[] datos = dato.split(csvSplitBy, 15);
conexion.setRequestMethod("POST");
conexion.addRequestProperty("_id0" , datos[0]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("Fin");
}
}
}
提前致谢。
您可以使用此 POST 方法来创建 class:
http://your_host:2480/class/mydb/className
将 属性 添加到 class
http://your_host:2480/property/mydb/className/propertyName
你可以细看更详细的资料here。
希望对您有所帮助,
亚历克斯
更新:
要插入,请使用此 POST 方法:
http://your_host:2480/command/mydb/sql/insert 到 class 名称(属性 名称)值(“yourValue”)
这是我的代码。我做了一个 "GET" 方法来获得我的数据库的响应。
然后我读取了我自己的文件csv。在这一点上一切都很好,但是......我不知道我该如何做 "POST" 方法。我知道我需要使用 "addRequestProperty" 方法。
有创建顶点和边的想法吗?
public void run() throws MalformedURLException, JSONException, IOException {
String viaURl = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxx/mydb";
URL url = new URL(viaURl);
HttpURLConnection conexion = null;
String texto = null;
String json;
BufferedReader in = null, in2 = null;
int numDump = 5;
String dato;
String csvSplitBy = ";";
int numApps = 0;
OutputStreamWriter out;
try {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxxx", "xxxxxxxxxxxxx.".toCharArray());
}
});
conexion = (HttpURLConnection) url.openConnection();
conexion.setRequestMethod("GET");
conexion.connect();
System.out.println("¡¡¡Conectado!!!");
in = new BufferedReader(new InputStreamReader(conexion.getInputStream()));
out = new OutputStreamWriter(conexion.getOutputStream());
json = "";
while ((texto = in.readLine()) != null) {
json += texto;
}
in.close();
System.out.println(json);
conexion.setDoOutput(true);
try {
for (int i = 0; i < numDump; i++) {
String csvFile = "/home/danicroque/dump/dump_" + i;
try {
in2 = new BufferedReader(new FileReader(csvFile));
while ((dato = in2.readLine()) != null) {
numApps++;
String[] datos = dato.split(csvSplitBy, 15);
conexion.setRequestMethod("POST");
conexion.addRequestProperty("_id0" , datos[0]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("Fin");
}
}
}
提前致谢。
您可以使用此 POST 方法来创建 class: http://your_host:2480/class/mydb/className
将 属性 添加到 class http://your_host:2480/property/mydb/className/propertyName
你可以细看更详细的资料here。
希望对您有所帮助, 亚历克斯
更新: 要插入,请使用此 POST 方法: http://your_host:2480/command/mydb/sql/insert 到 class 名称(属性 名称)值(“yourValue”)