Search in sources :

Example 6 with Session

use of com.teradata.jaqy.Session in project jaqy by Teradata.

the class CloseCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) {
    SessionUtils.checkOpen(interpreter);
    Session session = interpreter.getSession();
    session.close(interpreter, false);
// interpreter.println ("Session " + session.getId () + " is now closed.");
}
Also used : Session(com.teradata.jaqy.Session)

Example 7 with Session

use of com.teradata.jaqy.Session in project jaqy by Teradata.

the class ExecCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
    if (args.length == 0) {
        interpreter.setParseAction(this, null);
    } else {
        CommandLine cmdLine = getCommandLine(args);
        args = cmdLine.getArgs();
        String charset = null;
        for (Option option : cmdLine.getOptions()) {
            if ("c".equals(option.getOpt())) {
                charset = option.getValue();
            }
        }
        if (args.length > 0) {
            Path file = interpreter.getPath(args[0]);
            if (!file.exists()) {
                interpreter.error("file not found: " + args[0]);
            }
            SessionUtils.checkOpen(interpreter);
            Reader reader = FileUtils.getReader(file.getInputStream(), charset);
            String sql = StringUtils.getStringFromReader(reader);
            Session session = interpreter.getSession();
            session.executeQuery(sql, interpreter, interpreter.getRepeatCount());
            // now reset things
            interpreter.setRepeatCount(1);
            interpreter.setLimit(0);
        } else {
            interpreter.setParseAction(this, null);
        }
    }
}
Also used : Path(com.teradata.jaqy.interfaces.Path) CommandLine(org.apache.commons.cli.CommandLine) Reader(java.io.Reader) Option(org.apache.commons.cli.Option) Session(com.teradata.jaqy.Session)

Example 8 with Session

use of com.teradata.jaqy.Session in project jaqy by Teradata.

the class ExecCommand method parse.

@Override
public void parse(String action, Object value, boolean silent, Globals globals, JaqyInterpreter interpreter) throws Exception {
    SessionUtils.checkOpen(interpreter);
    if (!silent) {
        Display display = interpreter.getDisplay();
        display.echo(interpreter, action, false);
    }
    Session session = interpreter.getSession();
    session.executeQuery(action, interpreter, 1);
}
Also used : Display(com.teradata.jaqy.interfaces.Display) Session(com.teradata.jaqy.Session)

Example 9 with Session

use of com.teradata.jaqy.Session 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();
    }
}
Also used : JaqyResultSet(com.teradata.jaqy.interfaces.JaqyResultSet) CommandLine(org.apache.commons.cli.CommandLine) JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) Option(org.apache.commons.cli.Option) SchemaInfo(com.teradata.jaqy.schema.SchemaInfo) Session(com.teradata.jaqy.Session)

Aggregations

Session (com.teradata.jaqy.Session)9 JaqyHelper (com.teradata.jaqy.interfaces.JaqyHelper)5 JaqyConnection (com.teradata.jaqy.connection.JaqyConnection)4 DatabaseMetaData (java.sql.DatabaseMetaData)3 CommandLine (org.apache.commons.cli.CommandLine)3 Option (org.apache.commons.cli.Option)3 Display (com.teradata.jaqy.interfaces.Display)2 SchemaInfo (com.teradata.jaqy.schema.SchemaInfo)2 JaqyResultSet (com.teradata.jaqy.interfaces.JaqyResultSet)1 Path (com.teradata.jaqy.interfaces.Path)1 Reader (java.io.Reader)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1