com.nflabs.zeppelin.result.AbstractResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zeppelin-zengine Show documentation
Show all versions of zeppelin-zengine Show documentation
Zengine is java framework for data analysis on Hadoop. see http://nflabs.github.io/zeppelin/#/zengine
package com.nflabs.zeppelin.result;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
public abstract class AbstractResult {
//TODO: static configuration vs dependency igection
// = Zengine.getConf().getLong(ConfVars.ZEPPELIN_MAX_RESULT)
private static final long DEFAULT_RESULT_NUM_LIMIT = 100;
private ColumnDef [] columnDef;
private long max;
transient private ResultSet res;
transient Exception e;
boolean loaded = false;
@SuppressWarnings("unused")
private int code;
public AbstractResult(ResultSet res) throws ResultDataException {
this(res, -1);
}
public AbstractResult(ResultSet res, long max) throws ResultDataException {
try {
init(res, max);
} catch (SQLException e) {
throw new ResultDataException(e);
}
}
public boolean isLoaded(){
return loaded;
}
public AbstractResult(Exception e) throws ResultDataException {
this.e = e;
columnDef = new ColumnDef[4];
columnDef[0] = new ColumnDef("class", Types.VARCHAR, "varchar");
columnDef[1] = new ColumnDef("message", Types.VARCHAR, "varchar");
columnDef[2] = new ColumnDef("stacktrace", Types.VARCHAR, "varchar");
columnDef[3] = new ColumnDef("cause", Types.VARCHAR, "varchar");
max = -1;
Object [] row = new Object[4];
row[0] = e.getClass().getName();
row[1] = e.getMessage();
row[2] = e.getStackTrace();
row[3] = (e.getCause()==null) ? null : e.getCause().getMessage();
try {
process(columnDef, row, 0);
} catch (Exception e1) {
throw new ResultDataException(e1);
}
}
public AbstractResult(int code, String [] message) throws ResultDataException {
this.code = code;
if(message!=null){
columnDef = new ColumnDef[1];
columnDef[0] = new ColumnDef("message", Types.VARCHAR, "varchar");
try {
for(int i=0; i=0 && count>max) break;
Object [] row = new Object[numColumns];
for(int i=0; i