Package org.codehaus.jackson.node

Examples of org.codehaus.jackson.node.JsonNodeFactory


            }
        }
    }

    public ObjectNode toJson() {
        JsonNodeFactory factory = JsonNodeFactory.instance;
        ObjectNode object = factory.objectNode();
        ObjectNode fieldsJson = object.putObject("fields");

        for (IndexFieldDefinition field : fields) {
            fieldsJson.put(field.getName(), field.toJson());
        }
View Full Code Here


        Preconditions.checkNotNull(order, "Null argument: order");
        this.order = order;
    }

    public ObjectNode toJson() {
        JsonNodeFactory factory = JsonNodeFactory.instance;
        ObjectNode object = factory.objectNode();
        object.put("class", this.getClass().getName());
        object.put("order", this.order.toString());
        return object;
    }
View Full Code Here

        return namespaces;
    }

    public static JsonNode toJson(Namespaces namespaces) {
        JsonNodeFactory factory = JsonNodeFactory.instance;
        ObjectNode jsonNamespaces = factory.objectNode();

        for (Map.Entry<String, String> entry : namespaces.getNsToPrefixMapping().entrySet()) {
            String namespace = entry.getKey();
            String prefix = entry.getValue();
View Full Code Here

    }

    @Override
    public ObjectNode toJson(Record record, WriteOptions options, Namespaces namespaces, LRepository repository)
            throws RepositoryException, InterruptedException {
        JsonNodeFactory factory = JsonNodeFactory.instance;
        ObjectNode recordNode = factory.objectNode();

        if (record.getId() != null) {
            recordNode.put("id", record.getId().toString());
        }
View Full Code Here

    public JsonNode valueToJson(Object value, ValueType valueType, WriteOptions options, Namespaces namespaces,
            LRepository repository) throws RepositoryException, InterruptedException {
        String name = valueType.getBaseName();

        JsonNodeFactory factory = JsonNodeFactory.instance;

        JsonNode result;

        if (name.equals("LIST")) {
            result = listToJson(value, valueType.getNestedValueType(), options, namespaces, repository);
        } else if (name.equals("PATH")) {
            result = pathToJson(value, valueType.getNestedValueType(), options, namespaces, repository);
        } else if (name.equals("STRING")) {
            result = factory.textNode((String)value);
        } else if (name.equals("LONG")) {
            result = factory.numberNode((Long)value);
        } else if (name.equals("DOUBLE")) {
            result = factory.numberNode((Double)value);
        } else if (name.equals("BOOLEAN")) {
            result = factory.booleanNode((Boolean)value);
        } else if (name.equals("INTEGER")) {
            result = factory.numberNode((Integer)value);
        } else if (name.equals("URI") || name.equals("DATETIME") || name.equals("DATE") || name.equals("LINK")) {
            result = factory.textNode(value.toString());
        } else if (name.equals("DECIMAL")) {
            result = factory.numberNode((BigDecimal)value);
        } else if (name.equals("BLOB")) {
            Blob blob = (Blob)value;
            result = BlobConverter.toJson(blob);
        } else if (name.equals("RECORD")){
            result = toJson((Record)value, options, namespaces, repository);
        } else if (name.equals("BYTEARRAY")) {
            result = factory.binaryNode(((ByteArray) value).getBytes());
        } else {
            throw new RuntimeException("Unsupported value type: " + name);
        }

        return result;
View Full Code Here

        return result;
    }

    private static JsonNode typeToJson(QName name, Long version, Namespaces namespaces) {
        JsonNodeFactory factory = JsonNodeFactory.instance;
        ObjectNode jsonType = factory.objectNode();

        jsonType.put("name", QNameConverter.toJson(name, namespaces));
        if (version != null) {
            jsonType.put("version", version);
        }
View Full Code Here

        //
        // Create records using put
        //
        startExecutor();
        final JsonNodeFactory factory = JsonNodeFactory.instance;
        final long now = System.currentTimeMillis();

        for (int i = 0; i < iterations; i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        ObjectNode recordNode = factory.objectNode();
                        recordNode.put("type", "n$recordType");

                        ObjectNode fieldsNode = recordNode.putObject("fields");
                        for (int f = 1; f <= 5; f++) {
                            fieldsNode.put("n$field" + f, Words.get());
                        }

                        ObjectNode namespaces = recordNode.putObject("namespaces");
                        namespaces.put("org.lilyproject.rest-perftest", "n");

                        byte[] recordBytes = JsonFormat.serializeAsBytes(recordNode);

                        String recordId = "USER." + now + "_" + seqnr;
                        recordIds.add(recordId);

                        long before = System.nanoTime();
                        put("/record/" + recordId, recordBytes, 201);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Create record using put", "C", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Create records using post
        //
        startExecutor();
        for (int i = 0; i < iterations; i++) {
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        ObjectNode actionNode = factory.objectNode();
                        actionNode.put("action", "create");

                        ObjectNode recordNode = actionNode.putObject("record");
                        recordNode.put("type", "n$recordType");

                        ObjectNode fieldsNode = recordNode.putObject("fields");
                        for (int f = 1; f <= 5; f++) {
                            fieldsNode.put("n$field" + f, Words.get());
                        }

                        ObjectNode namespaces = recordNode.putObject("namespaces");
                        namespaces.put("org.lilyproject.rest-perftest", "n");

                        byte[] recordBytes = JsonFormat.serializeAsBytes(actionNode);

                        long before = System.nanoTime();
                        Result result = post("/record", recordBytes, 201);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Create record using post", "E", duration / 1e6d);

                        // ID is assigned by the server, read it out
                        ObjectNode createdRecord = (ObjectNode)JsonFormat.deserialize(result.data);
                        recordIds.add(createdRecord.get("id").getValueAsText());
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Read records
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        long before = System.nanoTime();
                        get("/record/" + recordIds.get(seqnr), 200);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Record read", "R", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Read records using vtag
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        long before = System.nanoTime();
                        get("/record/" + recordIds.get(seqnr) + "/vtag/last", 200);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Record read via last vtag", "T", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Read records using version
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        long before = System.nanoTime();
                        get("/record/" + recordIds.get(seqnr) + "/version/1", 200);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Record read specific version", "V", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Read list of versions
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        long before = System.nanoTime();
                        get("/record/" + recordIds.get(seqnr) + "/version", 200);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Read list of versions", "L", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Read list of variants
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        long before = System.nanoTime();
                        get("/record/" + recordIds.get(seqnr) + "/variant", 200);
                        double duration = System.nanoTime() - before;
                        metrics.increment("Read list of variants", "M", duration / 1e6d);
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            });
        }
        stopExecutor();

        //
        // Update records using PUT
        //
        startExecutor();
        for (int i = 0; i < recordIds.size(); i++) {
            final int seqnr = i;
            executor.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        ObjectNode recordNode = factory.objectNode();

                        ObjectNode fieldsNode = recordNode.putObject("fields");
                        for (int f = 1; f <= 5; f++) {
                            fieldsNode.put("n$field" + f, Words.get());
                        }
View Full Code Here

TOP

Related Classes of org.codehaus.jackson.node.JsonNodeFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.