本文整理汇总了Java中org.voltdb.utils.Encoder类的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Encoder类属于org.voltdb.utils包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: debugJSON
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* @param catalog_stmt
* @return
*/
public static String debugJSON(Statement catalog_stmt) {
String jsonString = Encoder.hexDecodeToString(catalog_stmt.getFullplan());
String line = "\n----------------------------------------\n";
String ret = "FULL PLAN ORIG STRING:\n" + jsonString + line;
for (PlanFragment catalog_frgmt : catalog_stmt.getFragments()) {
jsonString = Encoder.hexDecodeToString(catalog_frgmt.getPlannodetree());
try {
JSONObject jsonObject = new JSONObject(jsonString);
ret += "FRAGMENT " + catalog_frgmt.getName() + "\n" + jsonObject.toString(2) + line;
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
} // FOR
return (ret);
}
示例2: compileSQL
import org.voltdb.utils.Encoder; //导入依赖的package包/类
public static AbstractPlanNode compileSQL(final Procedure catalog_proc, String name, String sql) throws Exception {
VoltCompiler compiler = new VoltCompiler();
HSQLInterface hsql = HSQLInterface.loadHsqldb();
Database catalog_db = (Database) catalog_proc.getParent();
Catalog catalog = catalog_db.getCatalog();
Statement catalog_stmt = catalog_proc.getStatements().add(name);
StatementCompiler.compile(compiler, hsql, catalog, catalog_db, new DatabaseEstimates(), catalog_stmt, sql, true);
// HACK: For now just return the PlanNodeList from the first fragment
System.err.println("CATALOG_STMT: " + CatalogUtil.debug(catalog_stmt.getFragments()));
assert (catalog_stmt.getFragments().get(0) != null);
String serialized = catalog_stmt.getFragments().get(0).getPlannodetree();
String jsonString = Encoder.hexDecodeToString(serialized);
PlanNodeList list = null; // FIXME
// (PlanNodeList)PlanNodeTree.fromJSONObject(new
// JSONObject(jsonString), catalog_db);
return (list.getRootPlanNode());
}
示例3: compileToCatalog
import org.voltdb.utils.Encoder; //导入依赖的package包/类
public void compileToCatalog(Catalog catalog, Database db) throws VoltCompilerException {
String hexDDL = Encoder.hexEncode(m_fullDDL);
catalog.execute("set " + db.getPath() + " schema \"" + hexDDL + "\"");
String xmlCatalog;
try {
xmlCatalog = m_hsql.getXMLFromCatalog();
} catch (HSQLParseException e) {
String msg = "DDL Error: " + e.getMessage();
throw m_compiler.new VoltCompilerException(msg);
}
// output the xml catalog to disk
PrintStream ddlXmlOutput = BuildDirectoryUtils.getDebugOutputPrintStream("schema-xml", "hsql-catalog-output.xml");
ddlXmlOutput.println(xmlCatalog);
ddlXmlOutput.close();
// build the local catalog from the xml catalog
fillCatalogFromXML(catalog, db, xmlCatalog);
}
示例4: getExplainPlans
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* Get textual explain plan info for each plan from the
* catalog to be shoved into the catalog jarfile.
*/
HashMap<String, byte[]> getExplainPlans(Catalog catalog) {
HashMap<String, byte[]> retval = new HashMap<String, byte[]>();
Database db = getCatalogDatabase();
assert(db != null);
for (Procedure proc : db.getProcedures()) {
for (Statement stmt : proc.getStatements()) {
String s = "SQL: " + stmt.getSqltext() + "\n";
s += "COST: " + Integer.toString(stmt.getCost()) + "\n";
s += "PLAN:\n\n";
s += Encoder.hexDecodeToString(stmt.getExplainplan()) + "\n";
byte[] b = s.getBytes(Constants.UTF8ENCODING);
retval.put(proc.getTypeName() + "_" + stmt.getTypeName() + ".txt", b);
}
}
return retval;
}
示例5: run
import org.voltdb.utils.Encoder; //导入依赖的package包/类
public long run(byte[][] data1, String[] data2, byte[][] data3) {
for (byte[] b : data1) {
if (new String(b, Constants.UTF8ENCODING).equals("Hello") == false) {
throw new VoltAbortException("bad match a");
}
}
for (String s : data2) {
if (s.equals("Hello") == false) {
throw new VoltAbortException("bad match b");
}
}
if (Encoder.hexEncode(data3[0]).equalsIgnoreCase("AAbbff00") == false) {
throw new VoltAbortException("bad match d");
}
if (Encoder.hexEncode(data3[1]).equalsIgnoreCase("AAbbff0011") == false) {
throw new VoltAbortException("bad match e");
}
if (Encoder.hexEncode(data3[2]).equalsIgnoreCase("1234567890abcdef") == false) {
throw new VoltAbortException("bad match f");
}
return 0;
}
示例6: FragIdAndText
import org.voltdb.utils.Encoder; //导入依赖的package包/类
@SuppressWarnings("deprecation")
FragIdAndText(String stmtName) {
Statement stmt = m_testProc.getStatements().getIgnoreCase(stmtName);
PlanFragment frag = null;
for (PlanFragment f : stmt.getFragments()) {
frag = f;
}
fragId = CatalogUtil.getUniqueIdForFragment(frag);
sqlText = stmt.getSqltext();
ActivePlanRepository.addFragmentForTest(
fragId,
Encoder.decodeBase64AndDecompressToBytes(frag.getPlannodetree()),
sqlText);
}
示例7: deserializeExpression
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* @param catalog_db
* @param exptree
* @return
* @throws Exception
*/
public static AbstractExpression deserializeExpression(Database catalog_db, String exptree) throws Exception {
AbstractExpression exp = null;
if (exptree != null && !exptree.isEmpty()) {
JSONObject json_obj = new JSONObject(Encoder.hexDecodeToString(exptree));
exp = AbstractExpression.fromJSONObject(json_obj, catalog_db);
}
return (exp);
}
示例8: getHexEncodedBytes
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* Get a ascii-string-safe version of the binary value using a
* hex encoding.
*
* @return A hex-encoded string value representing the serialized
* objects.
*/
public String getHexEncodedBytes() {
buffer.b.flip();
byte bytes[] = new byte[buffer.b.remaining()];
buffer.b.get(bytes);
String hex = Encoder.hexEncode(bytes);
buffer.discard();
return hex;
}
示例9: shouldAccept
import org.voltdb.utils.Encoder; //导入依赖的package包/类
@Override
public ClientResponseImpl shouldAccept(AuthUser user,
StoredProcedureInvocation invocation,
Procedure sysProc) {
if (!invocation.procName.equals("@UpdateApplicationCatalog")) {
return null;
}
ParameterSet params = invocation.getParams();
// Either the catalog bytes or the deployment string can be null, indicating
// that the user doesn't want to change that component. Null values will
// be populated correctly by the AsyncCompilerAgentHelper downstream.
if (params.toArray().length != 2)
{
return new ClientResponseImpl(ClientResponseImpl.UNEXPECTED_FAILURE,
new VoltTable[0],
"UpdateApplicationCatalog system procedure requires exactly " +
"two parameters, the catalog bytes and the deployment file " +
"string (either of which may be null).",
invocation.clientHandle);
}
if (params.toArray()[0] != null)
{
boolean isHex = false;
if (params.toArray()[0] instanceof String) {
isHex = Encoder.isHexEncodedString((String) params.toArray()[0]);
}
if (!isHex && !(params.toArray()[0] instanceof byte[])) {
return new ClientResponseImpl(ClientResponseImpl.UNEXPECTED_FAILURE,
new VoltTable[0],
"UpdateApplicationCatalog system procedure takes the " +
"catalog bytes as a byte array. The received parameter " +
"is of type " + params.toArray()[0].getClass() + ".",
invocation.clientHandle);
}
}
return null;
}
示例10: initSQLStmt
import org.voltdb.utils.Encoder; //导入依赖的package包/类
public void initSQLStmt(SQLStmt stmt, Statement catStmt) {
int fragCount = catStmt.getFragments().size();
for (PlanFragment frag : catStmt.getFragments()) {
byte[] planHash = Encoder.hexDecode(frag.getPlanhash());
byte[] plan = Encoder.decodeBase64AndDecompressToBytes(frag.getPlannodetree());
long id = ActivePlanRepository.loadOrAddRefPlanFragment(planHash, plan, catStmt.getSqltext());
boolean transactional = frag.getNontransactional() == false;
SQLStmt.Frag stmtFrag = new SQLStmt.Frag(id, planHash, transactional);
if (fragCount == 1 || frag.getHasdependencies()) {
stmt.aggregator = stmtFrag;
}
else {
stmt.collector = stmtFrag;
}
}
stmt.isReadOnly = catStmt.getReadonly();
stmt.isReplicatedTableDML = catStmt.getReplicatedtabledml();
stmt.site = m_site;
int numStatementParamJavaTypes = catStmt.getParameters().size();
stmt.statementParamJavaTypes = new byte[numStatementParamJavaTypes];
for (StmtParameter param : catStmt.getParameters()) {
stmt.statementParamJavaTypes[param.getIndex()] = (byte)param.getJavatype();
// ??? How does the SQLStmt successfully handle IN LIST queries without
// caching the value of param.getIsarray() here?
// Is the array-ness also reflected in the javatype? --paul
}
}
示例11: initializeHSQLBackend
import org.voltdb.utils.Encoder; //导入依赖的package包/类
static public HsqlBackend initializeHSQLBackend(long siteId,
CatalogContext context)
{
synchronized(backendLock) {
if (m_backend == null) {
try {
m_backend = new HsqlBackend(siteId);
final String binDDL = context.database.getSchema();
final String ddl = Encoder.decodeBase64AndDecompress(binDDL);
final String[] commands = ddl.split("\n");
for (String command : commands) {
String decoded_cmd = Encoder.hexDecodeToString(command);
decoded_cmd = decoded_cmd.trim();
if (decoded_cmd.length() == 0) {
continue;
}
m_backend.runDDL(decoded_cmd);
}
}
catch (final Exception ex) {
hostLog.fatal("Unable to construct HSQL backend");
VoltDB.crashLocalVoltDB(ex.getMessage(), true, ex);
}
}
return m_backend;
}
}
示例12: dispatchUpdateApplicationCatalog
import org.voltdb.utils.Encoder; //导入依赖的package包/类
ClientResponseImpl dispatchUpdateApplicationCatalog(StoredProcedureInvocation task,
ClientInputHandler handler, Connection ccxn, AuthSystem.AuthUser user)
{
ParameterSet params = task.getParams();
// default catalogBytes to null, when passed along, will tell the
// catalog change planner that we want to use the current catalog.
byte[] catalogBytes = null;
Object catalogObj = params.toArray()[0];
if (catalogObj != null) {
if (catalogObj instanceof String) {
// treat an empty string as no catalog provided
String catalogString = (String) catalogObj;
if (!catalogString.isEmpty()) {
catalogBytes = Encoder.hexDecode(catalogString);
}
} else if (catalogObj instanceof byte[]) {
// treat an empty array as no catalog provided
byte[] catalogArr = (byte[]) catalogObj;
if (catalogArr.length != 0) {
catalogBytes = catalogArr;
}
}
}
String deploymentString = (String) params.toArray()[1];
LocalObjectMessage work = new LocalObjectMessage(
new CatalogChangeWork(
m_siteId,
task.clientHandle, handler.connectionId(), ccxn.getHostnameAndIPAndPort(),
handler.isAdmin(), ccxn, catalogBytes, deploymentString,
task.procName, task.type, task.originalTxnId, task.originalUniqueId,
VoltDB.instance().getReplicationRole() == ReplicationRole.REPLICA,
VoltDB.instance().getCatalogContext().cluster.getUseddlschema(),
m_adhocCompletionHandler, user));
m_mailbox.send(m_plannerSiteId, work);
return null;
}
示例13: getHexEncodedBytes
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* Get a ascii-string-safe version of the binary value using a
* hex encoding.
*
* @return A hex-encoded string value representing the serialized
* objects.
*/
public String getHexEncodedBytes() {
buffer.b().flip();
byte bytes[] = new byte[buffer.b().remaining()];
buffer.b().get(bytes);
String hex = Encoder.hexEncode(bytes);
buffer.discard();
return hex;
}
示例14: toString
import org.voltdb.utils.Encoder; //导入依赖的package包/类
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("FRAGMENT PLAN HASH: %s\n", Encoder.hexEncode(m_planHash)));
if (m_parameterSet != null) {
ParameterSet pset = null;
try {
pset = ParameterSet.fromByteBuffer(m_parameterSet.asReadOnlyBuffer());
} catch (IOException e) {
e.printStackTrace();
}
assert(pset != null);
sb.append("\n ").append(pset.toString());
}
if (m_outputDepId != null) {
sb.append("\n");
sb.append(" OUTPUT_DEPENDENCY_ID ");
sb.append(m_outputDepId);
}
if ((m_inputDepIds != null) && (m_inputDepIds.size() > 0)) {
sb.append("\n");
sb.append(" INPUT_DEPENDENCY_IDS ");
for (long id : m_inputDepIds)
sb.append(id).append(", ");
sb.setLength(sb.lastIndexOf(", "));
}
if ((m_fragmentPlan != null) && (m_fragmentPlan.length != 0)) {
sb.append("\n");
sb.append(" FRAGMENT_PLAN ");
sb.append(m_fragmentPlan);
}
if ((m_stmtText != null) && (m_stmtText.length != 0)) {
sb.append("\n");
sb.append(" STATEMENT_TEXT ");
sb.append(m_stmtText);
}
return sb.toString();
}
示例15: writePlanBytes
import org.voltdb.utils.Encoder; //导入依赖的package包/类
/**
* Update the plan fragment and return the bytes of the plan
*/
static byte[] writePlanBytes(VoltCompiler compiler, PlanFragment fragment, AbstractPlanNode planGraph)
throws VoltCompilerException {
// get the plan bytes
PlanNodeList node_list = new PlanNodeList(planGraph);
String json = node_list.toJSONString();
compiler.captureDiagnosticJsonFragment(json);
// Place serialized version of PlanNodeTree into a PlanFragment
byte[] jsonBytes = json.getBytes(Charsets.UTF_8);
String bin64String = Encoder.compressAndBase64Encode(jsonBytes);
fragment.setPlannodetree(bin64String);
return jsonBytes;
}