Package com.netflix.staash.json

Examples of com.netflix.staash.json.JsonObject


        return "{\""+table1+"\":"+res1+",\""+table2+"\":"+res2+"}";
    }

  public byte[] fetchValueForKey(String db, String table, String keycol,
      String key) {
    JsonObject storageConf = meta.getStorageForTable(db+"."+table);
        if (storageConf == null) return "{\"msg\":\"the requested table does not exist in paas\"}".getBytes();
        PaasConnection conn = fac.createConnection(storageConf,db);
        String ret = conn.read(db,table,keycol,key);
        JsonObject keyval = new JsonObject(ret).getObject("1");
        String val = keyval.getString("value");
        return val.getBytes();
  }
View Full Code Here


        String val = keyval.getString("value");
        return val.getBytes();
  }

  public byte[] readChunked(String db, String table, String objectName) {
    JsonObject storageConf = meta.getStorageForTable(db+"."+table);
        if (storageConf == null) return "{\"msg\":\"the requested table does not exist in paas\"}".getBytes();
        PaasConnection conn = fac.createConnection(storageConf,db);
        ByteArrayOutputStream os =  conn.readChunked(db, table, objectName);
        return os.toByteArray();
 
View Full Code Here

 

  public String writeChunked(String db, String table, String objectName,
      InputStream is) {
    // TODO Auto-generated method stub
    JsonObject storageConf = meta.getStorageForTable(db+"."+table);
        if (storageConf == null) return "{\"msg\":\"the requested table does not exist in paas\"}";
        PaasConnection conn = fac.createConnection(storageConf,db);
        return conn.writeChunked(db, table, objectName, is);
  }
View Full Code Here

        ResultSet rs = session
                .execute("select column1, value from "+MetaConstants.META_KEY_SPACE+"."+MetaConstants.META_COLUMN_FAMILY+ " where key='"+MetaConstants.STAASH_TABLE_ENTITY_TYPE+"';");
        List<Row> rows = rs.all();
        for (Row row : rows) {
            String field = row.getString(0);
            JsonObject val = new JsonObject(row.getString(1));
            String storage = val.getField("storage");
            tableToStorageMap.put(field, storage);
        }
    }
View Full Code Here

                .execute("select column1, value from "+MetaConstants.META_KEY_SPACE+"."+MetaConstants.META_COLUMN_FAMILY+ " where key='"+MetaConstants.STAASH_STORAGE_TYPE_ENTITY+"';");
        List<Row> rows = rs.all();
        Map<String,JsonObject> storageMap = new HashMap<String,JsonObject>();
        for (Row row : rows) {
            String field = row.getString(0);
            JsonObject val = new JsonObject(row.getString(1));
            jsonStorage.putObject(field, val);
            storageMap.put(field, val);
        }
        return storageMap;
    }
View Full Code Here

   
   
    public String writeMetaEntity(Entity entity) {
        try {
            if (dbHolder.contains(entity.getName())) {
                JsonObject obj = new JsonObject(
                        "{\"status\":\"error\",\"message\":\"db names must be unique\"}");
                return obj.toString();
            }
            session.execute(String.format(PaasUtils.INSERT_FORMAT, MetaConstants.META_KEY_SPACE + "."
                    + MetaConstants.META_COLUMN_FAMILY, entity.getRowKey(), entity.getName(),
                    entity.getPayLoad()));
            if (entity instanceof PaasDBEntity) dbHolder.add(entity.getName());
            if (entity instanceof PaasStorageEntity) jsonStorage.putObject(entity.getName(), new JsonObject(entity.getPayLoad()));
        } catch (AlreadyExistsException e) {
            // It's ok, ignore
        }
        if (entity instanceof PaasTableEntity) {
            // first create/check if schema db exists
            PaasTableEntity tableEnt = (PaasTableEntity) entity;
            String schemaName = tableEnt.getSchemaName();
            String storage = tableEnt.getStorage();
            try {
//                String payLoad = tableEnt.getPayLoad();
                if (storage!=null && storage.contains("mysql")) {
                    MySqlService.createDbInMySql(schemaName);
                } //else {
                session.execute(String.format(
                        PaasUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, schemaName, 1));
                //}//create counterpart in cassandra
            } catch (AlreadyExistsException e) {
                // It's ok, ignore
            }
            // if schema/db already exists now create the table
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String query = BuildQuery(tableEnt);
            Print(query);
            if (storage!=null && storage.contains("mysql")) {
               MySqlService.createTableInDb(schemaName, query);
            } else {
                storage="cassandra";
                session.execute(query);
            }
            List<String> tables = dbToTableMap.get(tableEnt.getSchemaName());
            if (tables==null) tables = new ArrayList<String>();
            tables.add(tableEnt.getName());
            tableToStorageMap.put(tableEnt.getName(), storage);
            // List<String> primaryKeys = entity.getPrimaryKey();
        }
        if (entity instanceof PaasTimeseriesEntity) {
            // first create/check if schema db exists
            PaasTimeseriesEntity tableEnt = (PaasTimeseriesEntity) entity;
            try {
                String schemaName = tableEnt.getSchemaName();
                session.execute(String.format(
                        PaasUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, schemaName, 1));
            } catch (AlreadyExistsException e) {
                // It's ok, ignore
            }
            // if schema/db already exists now create the table
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String query = BuildQuery(tableEnt);
            Print(query);
            session.execute(query);
            List<String> tables = dbToTimeseriesMap.get(tableEnt.getSchemaName());
            if (tables==null) tables = new ArrayList<String>();
            tables.add(tableEnt.getName().substring(tableEnt.getName().indexOf(".")+1));
            // List<String> primaryKeys = entity.getPrimaryKey();
        }
        JsonObject obj = new JsonObject("{\"status\":\"ok\"}");
        return obj.toString();
    }
View Full Code Here

        if (storage!=null && storage.equals("mysql")) {
            MySqlService.insertRowIntoTable(db, table, query);
        } else {
        session.execute(query);
        }
        JsonObject obj = new JsonObject("{\"status\":\"ok\"}");
        return obj.toString();
    }
View Full Code Here

    private String convertResultSet(ResultSet rs) {
        // TODO Auto-generated method stub
        String colStr = "";
        String rowStr = "";
        JsonObject response = new JsonObject();
        List<Row> rows = rs.all();
        if (!rows.isEmpty() && rows.size() == 1) {
            rowStr = rows.get(0).toString();
        }
        ColumnDefinitions colDefs = rs.getColumnDefinitions();
        colStr = colDefs.toString();
        response.putString("columns", colStr.substring(8, colStr.length() - 1));
        response.putString("values", rowStr.substring(4, rowStr.length() - 1));
        return response.toString();

    }
View Full Code Here

    }

    public String listSchemas() {
        // TODO Auto-generated method stub
        JsonObject obj = new JsonObject();
        JsonArray arr = new JsonArray();
        for (String db: dbHolder) {
            arr.addString(db);
        }
        obj.putArray("schemas", arr);
        return obj.toString();
    }
View Full Code Here

        obj.putArray("schemas", arr);
        return obj.toString();
    }
    public String listTablesInSchema(String schemaname) {
        // TODO Auto-generated method stub
        JsonObject obj = new JsonObject();
        JsonArray arr = new JsonArray();
        List<String> tblNames = dbToTableMap.get(schemaname);
        for (String name: tblNames) {
            arr.addString(name);
        }
        obj.putArray(schemaname, arr);
        return obj.toString();
    }
View Full Code Here

TOP

Related Classes of com.netflix.staash.json.JsonObject

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.