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.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.LinkedList;
import java.util.List;
public abstract class AbstractResult {
private ColumnDef [] columnDef;
private long max;
transient private ResultSet res;
transient Exception e;
boolean loaded = false;
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 void init(ResultSet res, long max) throws SQLException, ResultDataException{
ResultSetMetaData metaData = res.getMetaData();
int numColumns = metaData.getColumnCount();
// meta data extraction
columnDef = new ColumnDef[numColumns];
for(int i=0; i=0 && count>max) break;
Object [] row = new Object[numColumns];
for(int i=0; i