如何在Orientdb中使用HTTP创建顶点和边缘?

时间:2016-06-05 15:55:22

标签: java http orientdb

这是我的代码。我做了一个“GET”方法来获得我的DB的响应。

然后我读了我自己的文件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");
        }
    }
}

提前感谢。

1 个答案:

答案 0 :(得分:1)

您可以使用此POST方法创建类: http://your_host:2480/class/mydb/className

将属性添加到类中 http://your_host:2480/property/mydb/className/propertyName

您可以更详细的信息here

希望它有所帮助, 亚历克斯。

<强>更新 要插入使用此POST方法: http://your_host:2480/command/mydb/sql/insert到className(propertyName)值(“yourValue”)