use of com.teradata.jaqy.interfaces.JaqyHelper in project jaqy by Teradata.
the class TablePrinter method print.
public long print(JaqyResultSet rs, PrintWriter pw, long limit, JaqyInterpreter interpreter) throws Exception {
JaqyHelper helper = rs.getHelper();
// rewind operation.
if (m_autoShrink && rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
JaqyResultSet newRS = ResultSetUtils.copyResultSet(rs, limit, interpreter);
rs.close();
rs = newRS;
}
JaqyResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
boolean[] leftAligns = new boolean[columns];
int[] widths = new int[columns];
TypeHandler[] handlers = new TypeHandler[columns];
for (int i = 0; i < columns; ++i) {
int columnIndex = i + 1;
int type = metaData.getColumnType(columnIndex);
leftAligns[i] = isLeftAlign(type);
handlers[i] = helper.getTypeHandler(rs, i + 1);
}
if (m_autoShrink) {
//
for (int i = 0; i < columns; ++i) {
widths[i] = 0;
int dispSize = ResultSetUtils.getDisplayWidth(rs, i + 1);
if (dispSize <= m_columnThreshold)
widths[i] = dispSize;
}
shrink(columns, widths, rs, handlers, limit, interpreter);
} else {
//
for (int i = 0; i < columns; ++i) {
widths[i] = ResultSetUtils.getDisplayWidth(rs, i + 1);
if (widths[i] > m_maxColumnSize)
widths[i] = m_maxColumnSize;
}
}
// Make sure the title length is considered as well.
for (int i = 0; i < columns; ++i) {
String title = metaData.getColumnLabel(i + 1);
if (widths[i] < title.length())
widths[i] = title.length();
}
if (m_border)
printBorder(pw, widths);
// Print the title
if (m_border)
pw.print("| ");
for (int i = 0; i < columns; ++i) {
String title = metaData.getColumnLabel(i + 1);
if (i > 0) {
if (m_border)
pw.print(" | ");
else
pw.print(' ');
}
StringUtils.print(pw, title, widths[i], leftAligns[i], (i < (columns - 1)) || m_border);
}
if (m_border)
pw.print(" |");
pw.println();
// print the dashes
if (m_border)
printBorder(pw, widths);
else
printDash(pw, widths);
long count = 0;
if (limit == 0)
limit = Long.MAX_VALUE;
while (rs.next() && count < limit) {
++count;
if (m_border)
pw.print("| ");
for (int i = 0; i < columns; ++i) {
if (i > 0) {
if (m_border)
pw.print(" | ");
else
pw.print(' ');
}
StringUtils.print(pw, handlers[i].getString(rs, i + 1, interpreter), widths[i], leftAligns[i], (i < (columns - 1)) || m_border);
}
if (m_border)
pw.print(" |");
pw.println();
}
if (m_border)
printBorder(pw, widths);
return count;
}
use of com.teradata.jaqy.interfaces.JaqyHelper in project jaqy by Teradata.
the class ImportSchemaCommand method execute.
@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
JaqyImporter<?> importer = interpreter.getImporter();
if (importer == null) {
interpreter.error("There is no current import.");
}
SchemaInfo schemaInfo = importer.getSchema();
if (schemaInfo == null) {
interpreter.error("Current import schema is not available.");
}
boolean displaySQL = false;
CommandLine cmdLine = getCommandLine(args);
for (Option option : cmdLine.getOptions()) {
switch(option.getOpt().charAt(0)) {
case 's':
{
displaySQL = true;
break;
}
}
}
SessionUtils.checkOpen(interpreter);
Session session = interpreter.getSession();
JaqyHelper helper = session.getConnection().getHelper();
if (displaySQL) {
String sql = SchemaUtils.getTableSchema(helper, schemaInfo, "TABLENAME", false);
interpreter.println(sql);
} else {
JaqyResultSet rs = SchemaUtils.getSchemaResultSet(helper, schemaInfo, false, interpreter);
interpreter.print(rs);
rs.close();
}
}
use of com.teradata.jaqy.interfaces.JaqyHelper in project jaqy by Teradata.
the class CSVExporter method export.
@Override
public long export(JaqyResultSet rs, JaqyInterpreter interpreter) throws Exception {
PrintWriter pw = new PrintWriter(new BufferedWriter(m_out));
JaqyResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
TypeHandler[] handlers = new TypeHandler[columns];
JaqyHelper helper = rs.getHelper();
CSVPrinter printer = new CSVPrinter(pw, m_format);
for (int i = 0; i < columns; ++i) {
// print the header row
printer.print(metaData.getColumnLabel(i + 1));
CSVExportInfo fileInfo = m_fileInfoMap.get(i + 1);
if (fileInfo == null)
handlers[i] = helper.getTypeHandler(rs, i + 1);
else
handlers[i] = new FileHandler(m_file, fileInfo);
}
printer.println();
long count = 0;
while (rs.next()) {
++count;
for (int i = 0; i < columns; ++i) {
printer.print(handlers[i].getString(rs, i + 1, interpreter));
}
printer.println();
}
printer.close();
return count;
}
use of com.teradata.jaqy.interfaces.JaqyHelper in project jaqy by Teradata.
the class CSVPrinter method print.
@Override
public long print(JaqyResultSet rs, PrintWriter pw, long limit, JaqyInterpreter interpreter) throws Exception {
JaqyHelper helper = rs.getHelper();
JaqyResultSetMetaData metaData = rs.getMetaData();
int columns = metaData.getColumnCount();
TypeHandler[] handlers = new TypeHandler[columns];
@SuppressWarnings("resource") org.apache.commons.csv.CSVPrinter printer = new org.apache.commons.csv.CSVPrinter(pw, m_format);
for (int i = 0; i < columns; ++i) {
// print the header row
printer.print(metaData.getColumnLabel(i + 1));
handlers[i] = helper.getTypeHandler(rs, i + 1);
}
printer.println();
long count = 0;
if (limit == 0)
limit = Long.MAX_VALUE;
while (rs.next() && count < limit) {
++count;
for (int i = 0; i < columns; ++i) {
printer.print(handlers[i].getString(rs, i + 1, interpreter));
}
printer.println();
}
printer.flush();
return count;
}
use of com.teradata.jaqy.interfaces.JaqyHelper in project jaqy by Teradata.
the class ProjectColumnList method bind.
public void bind(JaqyResultSet rs, JaqyInterpreter interpreter) throws SQLException {
int numCols = m_columnList.size();
ExpNode[] exps = new ExpNode[numCols];
FullColumnInfo[] columnInfos = new FullColumnInfo[numCols];
ResultSetMetaData rsmd = rs.getMetaData().getMetaData();
JaqyHelper helper = rs.getHelper();
for (int i = 0; i < numCols; ++i) {
ProjectColumn column = m_columnList.get(i);
int index = rs.findColumn(column.name);
columnInfos[i] = ResultSetMetaDataUtils.getColumnInfo(rsmd, index, helper);
columnInfos[i].name = column.asName;
columnInfos[i].label = column.asName;
ColumnNode exp = new ColumnNode(column.name);
exp.bind(rs, null, interpreter);
exps[i] = exp;
}
m_project = new ExpNodeProject(exps);
m_meta = new JaqyResultSetMetaData(new InMemoryResultSetMetaData(columnInfos), DummyHelper.getInstance());
}
Aggregations