Search in sources :

Example 1 with Display

use of com.teradata.jaqy.interfaces.Display in project jaqy by Teradata.

the class OpenCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
    Session session = interpreter.getSession();
    Display display = interpreter.getDisplay();
    if (session == null) {
        interpreter.error("No active sessions.");
    }
    if (!session.isClosed()) {
        interpreter.error("The current session already has a connection open.");
    }
    CommandLine cmdLine = getCommandLine(args);
    args = cmdLine.getArgs();
    if (args.length == 0) {
        interpreter.error("invalid command arguments.");
    }
    Properties prop = new Properties();
    cmdLine.getOptions();
    boolean hasUser = false;
    boolean hasPassword = false;
    for (Option option : cmdLine.getOptions()) {
        if ("p".equals(option.getOpt())) {
            prop.setProperty("password", option.getValue());
            hasPassword = true;
        } else if ("f".equals(option.getOpt())) {
            String password = display.getPassword(interpreter, "Password: ");
            prop.setProperty("password", password);
            hasPassword = true;
        } else if ("u".equals(option.getOpt())) {
            prop.setProperty("user", option.getValue());
            hasUser = true;
        } else if ("D".equals(option.getOpt())) {
            String key = option.getValue(0);
            String value = option.getValue(1);
            prop.setProperty(key, value);
        }
    }
    if (hasUser && !hasPassword) {
        // use a blank password if the user is specified and password is not.
        prop.setProperty("password", "");
    }
    session.open(args[0], prop, interpreter, display);
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) Properties(java.util.Properties) Session(com.teradata.jaqy.Session) Display(com.teradata.jaqy.interfaces.Display)

Example 2 with Display

use of com.teradata.jaqy.interfaces.Display in project jaqy by Teradata.

the class IfCommand method parse.

@Override
public void parse(String action, Object value, boolean silent, Globals globals, JaqyInterpreter interpreter) throws IOException {
    globals.log(Level.INFO, "if condition = " + value);
    Display display = interpreter.getDisplay();
    if (value != null && (Boolean) value) {
        globals.log(Level.INFO, "running if statement");
        globals.log(Level.INFO, action);
        globals.log(Level.INFO, "end if statement");
        interpreter.interpret(new ReaderLineInput(new StringReader(action), interpreter.getDirectory(), false), false);
        if (!silent) {
            display.echo(interpreter, ".end " + getName(), false);
        }
    } else {
        if (!silent) {
            String[] lines = action.split("\n");
            for (String line : lines) {
                display.echo(interpreter, "-- skip: " + line, false);
            }
            display.echo(interpreter, ".end " + getName(), false);
        }
    }
}
Also used : StringReader(java.io.StringReader) ReaderLineInput(com.teradata.jaqy.lineinput.ReaderLineInput) Display(com.teradata.jaqy.interfaces.Display)

Example 3 with Display

use of com.teradata.jaqy.interfaces.Display in project jaqy by Teradata.

the class AliasCommand method parse.

@Override
public void parse(String action, Object value, boolean silent, Globals globals, JaqyInterpreter interpreter) {
    if (!silent) {
        Display display = interpreter.getDisplay();
        display.echo(interpreter, action, false);
        display.echo(interpreter, ".end " + getName(), false);
    }
    globals.getAliasManager().setAlias((String) value, action);
}
Also used : Display(com.teradata.jaqy.interfaces.Display)

Example 4 with Display

use of com.teradata.jaqy.interfaces.Display 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 5 with Display

use of com.teradata.jaqy.interfaces.Display in project jaqy by Teradata.

the class RemarkCommand method parse.

@Override
public void parse(String action, Object value, boolean silent, Globals globals, JaqyInterpreter interpreter) throws IOException {
    if (!silent) {
        Display display = interpreter.getDisplay();
        display.echo(interpreter, action, false);
        display.echo(interpreter, ".end " + getName(), false);
    }
}
Also used : Display(com.teradata.jaqy.interfaces.Display)

Aggregations

Display (com.teradata.jaqy.interfaces.Display)6 Session (com.teradata.jaqy.Session)2 ReaderLineInput (com.teradata.jaqy.lineinput.ReaderLineInput)1 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 CommandLine (org.apache.commons.cli.CommandLine)1 Option (org.apache.commons.cli.Option)1