Package org.json_voltpatches

Examples of org.json_voltpatches.JSONStringer


     * Get a JSON representation of this table.
     * @return A string containing a JSON representation of this table.
     */
    @Override
    public String toJSONString() {
        JSONStringer js = new JSONStringer();
        try {

            js.object();

            // status code (1 byte)
            js.key(JSON_STATUS_KEY).value(getStatusCode());

            // column schema
            js.key(JSON_SCHEMA_KEY).array();
            for (int i = 0; i < getColumnCount(); i++) {
                js.object();
                js.key(JSON_NAME_KEY).value(getColumnName(i));
                js.key(JSON_TYPE_KEY).value(getColumnType(i).getValue());
                js.endObject();
            }
            js.endArray();

            // row data
            js.key(JSON_DATA_KEY).array();
            VoltTableRow row = cloneRow();
            row.resetRowPosition();
            while (row.advanceRow()) {
                js.array();
                for (int i = 0; i < getColumnCount(); i++) {
                    row.putJSONRep(i, js);
                }
                js.endArray();
            }
            js.endArray();

            js.endObject();
        }
        catch (JSONException e) {
            e.printStackTrace();
            throw new RuntimeException("Failed to serialized a table to JSON.", e);
        }
        return js.toString();
    }
View Full Code Here


        }
        boolean success = false;
        try {
            final FileOutputStream fos = new FileOutputStream(f);
            StringWriter sw = new StringWriter();
            JSONStringer stringer = new JSONStringer();
            try {
                stringer.object();
                stringer.key("version").value(1);
                stringer.key("txnId").value(txnId);
                stringer.key("timestamp").value(timestamp);
                stringer.key("timestampString").value(SnapshotUtil.formatHumanReadableDate(timestamp));
                stringer.key("newPartitionCount").value(newPartitionCount);
                stringer.key("tables").array();
                for (int ii = 0; ii < tables.size(); ii++) {
                    stringer.value(tables.get(ii).getTypeName());
                }
                stringer.endArray();
                stringer.key("exportSequenceNumbers").array();
                for (Map.Entry<String, Map<Integer, Pair<Long, Long>>> entry : exportSequenceNumbers.entrySet()) {
                    stringer.object();

                    stringer.key("exportTableName").value(entry.getKey());

                    stringer.key("sequenceNumberPerPartition").array();
                    for (Map.Entry<Integer, Pair<Long,Long>> sequenceNumber : entry.getValue().entrySet()) {
                        stringer.object();
                        stringer.key("partition").value(sequenceNumber.getKey());
                        //First value is the ack offset which matters for pauseless rejoin, but not persistence
                        stringer.key("exportSequenceNumber").value(sequenceNumber.getValue().getSecond());
                        stringer.endObject();
                    }
                    stringer.endArray();

                    stringer.endObject();
                }
                stringer.endArray();

                stringer.key("partitionTransactionIds").object();
                for (Map.Entry<Integer, Long> entry : partitionTransactionIds.entrySet()) {
                    stringer.key(entry.getKey().toString()).value(entry.getValue());
                }
                stringer.endObject();

                stringer.key("catalogCRC").value(catalogCRC);
                stringer.key("instanceId").value(instanceId.serializeToJSONObject());
                stringer.endObject();
            } catch (JSONException e) {
                throw new IOException(e);
            }

            sw.append(stringer.toString());

            final byte tableListBytes[] = sw.getBuffer().toString().getBytes("UTF-8");
            final PureJavaCrc32 crc = new PureJavaCrc32();
            crc.update(tableListBytes);
            ByteBuffer fileBuffer = ByteBuffer.allocate(tableListBytes.length + 4);
View Full Code Here

        int i = 0;
        int size = 0;
        try {
            for (Pair<AbstractExpression, Boolean> p : m_predicates) {
                final AbstractExpression predicate = p.getFirst();
                JSONStringer stringer = new JSONStringer();
                stringer.object();
                stringer.key("triggersDelete").value(p.getSecond());
                // If the predicate is null, EE will serialize all rows to the corresponding data
                // target. It's the same as passing an always-true expression,
                // but without the overhead of the evaluating the expression. This avoids the
                // overhead when there is only one data target that wants all the rows.
                if (predicate != null) {
                    stringer.key("predicateExpression").object();
                    predicate.toJSONString(stringer);
                    stringer.endObject();
                }
                stringer.endObject();
                predicates[i] = stringer.toString().getBytes(Charsets.UTF_8);
                size += predicates[i].length;
                i++;
            }
        } catch (Exception e) {
            VoltDB.crashLocalVoltDB("Failed to serialize snapshot predicates", true, e);
View Full Code Here

        else if (m_config.fileInfoOnly) {
            String collectionFilesListPath = m_config.voltdbroot + File.separator + m_config.prefix;

            byte jsonBytes[] = null;
            try {
                JSONStringer stringer = new JSONStringer();

                stringer.object();
                stringer.key("server").value(m_config.prefix);
                stringer.key("files").array();
                for (String path: collectionFilesList) {
                    stringer.object();
                    stringer.key("filename").value(path);
                    if (Arrays.asList(cmdFilenames).contains(path.split(" ")[0])) {
                        stringer.key("size").value(0);
                    }
                    else {
                        stringer.key("size").value(new File(path).length());
                    }
                    stringer.endObject();
                }
                stringer.endArray();
                stringer.endObject();

                JSONObject jsObj = new JSONObject(stringer.toString());
                jsonBytes = jsObj.toString(4).getBytes(Charsets.UTF_8);
            } catch (JSONException e) {
                Throwables.propagate(e);
            }
View Full Code Here

        return result;
    }

    @Override
    public String toJSONString() {
        JSONStringer stringer = new JSONStringer();
        try {
        stringer.object();
        toJSONString(stringer);
        stringer.endObject();
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
        return stringer.toString();
    }
View Full Code Here

        if (columnName == null || columnName.equals("")) {
            columnName = "column#" + m_columnIndex;
        }
        if (m_verboseExplainForDebugging) {
            columnName += " (as JSON: ";
            JSONStringer stringer = new JSONStringer();
            try
            {
                stringer.object();
                toJSONString(stringer);
                stringer.endObject();
                columnName += stringer.toString();
            }
            catch (Exception e)
            {
                columnName += "CORRUPTED beyond the ability to format? " + e;
                e.printStackTrace();
View Full Code Here

    }

    @Override
    public String toJSONString() {
        params.run();
        JSONStringer js = new JSONStringer();
        try {
            js.object();
            js.key("proc_name");
            js.value(procName);
            js.key("parameters");
            js.value(params.get());
            js.endObject();
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Failed to serialize an invocation to JSON.", e);
        }
        return js.toString();
    }
View Full Code Here

        File adFile = new VoltFile(overflowPath, nonce + ".ad");
        exportLog.info("Creating ad for " + nonce);
        assert(!adFile.exists());
        byte jsonBytes[] = null;
        try {
            JSONStringer stringer = new JSONStringer();
            stringer.object();
            stringer.key("database").value(m_database);
            writeAdvertisementTo(stringer);
            stringer.endObject();
            JSONObject jsObj = new JSONObject(stringer.toString());
            jsonBytes = jsObj.toString(4).getBytes(Charsets.UTF_8);
        } catch (JSONException e) {
            Throwables.propagate(e);
        }
View Full Code Here

        }

        // Initiate a snapshot with stream snapshot target
        String data = null;
        try {
            JSONStringer jsStringer = new JSONStringer();
            jsStringer.object();
            jsStringer.key("streamPairs");
            jsStringer.object();
            jsStringer.key(Long.toString(sourceSite)).value(Long.toString(hsId));
            jsStringer.endObject();
            // make this snapshot only contain data from this site
            m_rejoinLog.info("Rejoin source for site " + CoreUtils.hsIdToString(getSiteId()) +
                               " is " + CoreUtils.hsIdToString(sourceSite));
            jsStringer.endObject();
            data = jsStringer.toString();
        } catch (Exception e) {
            VoltDB.crashLocalVoltDB("Failed to serialize to JSON", true, e);
        }

        /*
 
View Full Code Here

    // For dev speed, we'll detect mastership changes here and construct and send this message to the
    // local client interface so we can keep the CIs implementation
    private void sendLeaderChangeNotify(long hsId, int partitionId)
    {
        try {
            JSONStringer stringer = new JSONStringer();
            stringer.object();
            stringer.key(JSON_PARTITION_ID).value(partitionId);
            stringer.key(JSON_INITIATOR_HSID).value(hsId);
            stringer.endObject();
            BinaryPayloadMessage bpm = new BinaryPayloadMessage(new byte[0], stringer.toString().getBytes("UTF-8"));
            int hostId = m_hostMessenger.getHostId();
            m_hostMessenger.send(CoreUtils.getHSIdFromHostAndSite(hostId,
                        HostMessenger.CLIENT_INTERFACE_SITE_ID),
                    bpm);
        }
View Full Code Here

TOP

Related Classes of org.json_voltpatches.JSONStringer

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.