Search in sources :

Example 1 with JaqyConnection

use of com.teradata.jaqy.connection.JaqyConnection in project jaqy by Teradata.

the class InfoCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws SQLException {
    if (args.length == 0) {
        interpreter.error("need to provide the information type.");
    }
    SessionUtils.checkOpen(interpreter);
    String type = args[0].toLowerCase();
    Session session = interpreter.getSession();
    JaqyConnection conn = session.getConnection();
    JaqyHelper helper = conn.getHelper();
    DatabaseMetaData metaData = conn.getMetaData();
    if ("behavior".equals(type) || "behaviors".equals(type))
        listBehaviors(interpreter, metaData, helper);
    else if ("catalog".equals(type) || "catalogs".equals(type))
        listCatalogs(interpreter, metaData, helper);
    else if ("client".equals(type))
        listClient(interpreter, metaData, helper);
    else if ("feature".equals(type) || "features".equals(type))
        listFeatures(interpreter, metaData, helper);
    else if ("function".equals(type) || "functions".equals(type))
        listFunctions(interpreter, metaData, helper);
    else if ("keyword".equals(type) || "keywords".equals(type))
        listKeywords(interpreter, metaData, helper);
    else if ("limit".equals(type) || "limits".equals(type))
        listLimits(interpreter, metaData, helper);
    else if ("schema".equals(type) || "schemas".equals(type))
        listSchemas(interpreter, metaData, helper);
    else if ("server".equals(type))
        listServer(interpreter, metaData, helper);
    else if ("table".equals(type))
        listTableTypes(interpreter, metaData, helper);
    else if ("type".equals(type) || "types".equals(type))
        listTypes(interpreter, metaData, helper);
    else if ("user".equals(type))
        listUser(interpreter, metaData, helper);
    else {
        interpreter.error("invalid information type: " + args[0]);
    }
}
Also used : JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) JaqyConnection(com.teradata.jaqy.connection.JaqyConnection) DatabaseMetaData(java.sql.DatabaseMetaData) Session(com.teradata.jaqy.Session)

Example 2 with JaqyConnection

use of com.teradata.jaqy.connection.JaqyConnection in project jaqy by Teradata.

the class ListCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws SQLException {
    SessionUtils.checkOpen(interpreter);
    // 0 = catalog, 1 = schema, 2 = table
    int listType = 2;
    String catalogPattern = ".";
    String schemaPattern = ".";
    String tablePattern = "%";
    if (args.length == 0) {
    // no change to the pattern.
    } else if (args.length == 1) {
        catalogPattern = args[0];
        // we are selecting the catalogs
        if ("%".equals(args[0])) {
            listType = 0;
        } else {
            listType = 1;
        }
    } else if (args.length == 2) {
        catalogPattern = args[0];
        schemaPattern = args[1];
        listType = 1;
    } else if (args.length >= 3) {
        catalogPattern = args[0];
        schemaPattern = args[1];
        tablePattern = args[2];
        listType = 2;
    }
    Session session = interpreter.getSession();
    JaqyConnection conn = session.getConnection();
    DatabaseMetaData meta = conn.getMetaData();
    if (".".equals(catalogPattern)) {
        catalogPattern = conn.getCatalog(interpreter);
    }
    if (".".equals(schemaPattern)) {
        schemaPattern = conn.getSchema(interpreter);
    }
    JaqyHelper helper = conn.getHelper();
    ResultSet rs = null;
    String sep = meta.getCatalogSeparator();
    if (sep == null)
        sep = "/";
    if (listType == 0) {
        interpreter.println("-- Listing catalogs");
        rs = meta.getCatalogs();
    } else if (listType == 1) {
        interpreter.println("-- Listing schema: " + catalogPattern + sep + schemaPattern);
        rs = meta.getSchemas(catalogPattern, schemaPattern);
    } else if (listType == 2) {
        interpreter.println("-- Listing tables: " + catalogPattern + sep + schemaPattern + sep + tablePattern);
        rs = meta.getTables(catalogPattern, schemaPattern, tablePattern, null);
    }
    if (rs == null)
        return;
    interpreter.print(helper.getResultSet(rs, interpreter));
    rs.close();
}
Also used : JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) JaqyConnection(com.teradata.jaqy.connection.JaqyConnection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Session(com.teradata.jaqy.Session)

Example 3 with JaqyConnection

use of com.teradata.jaqy.connection.JaqyConnection in project jaqy by Teradata.

the class PwdCommand method execute.

@Override
public void execute(String[] args, boolean silent, JaqyInterpreter interpreter) throws Exception {
    SessionUtils.checkOpen(interpreter);
    Session session = interpreter.getSession();
    JaqyConnection conn = session.getConnection();
    JaqyHelper helper = conn.getHelper();
    String catalog = null;
    String schema = null;
    DatabaseMetaData meta = conn.getMetaData();
    String catalogName = "CATALOG";
    String schemaName = "SCHEMA";
    StringBuilder builder = new StringBuilder();
    try {
        catalog = conn.getCatalog(interpreter);
    } catch (SQLException ex) {
    }
    if (catalog != null && catalog.length() != 0) {
        try {
            catalogName = meta.getCatalogTerm();
        } catch (SQLException ex) {
        }
        builder.append(catalogName).append(" : ").append(catalog);
    }
    try {
        schema = helper.getSchema(interpreter);
    } catch (SQLException ex) {
    }
    if (schema != null && schema.length() != 0) {
        try {
            schemaName = meta.getSchemaTerm();
        } catch (SQLException ex) {
        }
        if (builder.length() > 0)
            builder.append(", ");
        builder.append(schemaName).append(" : ").append(schema);
    }
    interpreter.println(builder.toString());
}
Also used : JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) SQLException(java.sql.SQLException) JaqyConnection(com.teradata.jaqy.connection.JaqyConnection) DatabaseMetaData(java.sql.DatabaseMetaData) Session(com.teradata.jaqy.Session)

Example 4 with JaqyConnection

use of com.teradata.jaqy.connection.JaqyConnection in project jaqy by Teradata.

the class ImportTableCommand 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.");
    }
    if (args.length == 0) {
        interpreter.error("Staging table name is not specified.");
    }
    StringBuilder buffer = new StringBuilder();
    for (String arg : args) buffer.append(arg);
    String tableName = buffer.toString();
    SessionUtils.checkOpen(interpreter);
    Session session = interpreter.getSession();
    JaqyConnection conn = session.getConnection();
    JaqyHelper helper = conn.getHelper();
    String sql = SchemaUtils.getTableSchema(helper, schemaInfo, tableName, false);
    boolean prevCommit = conn.getAutoCommit();
    if (!prevCommit)
        conn.setAutoCommit(true);
    interpreter.println("-- Table Schema --");
    interpreter.println(sql);
    session.executeQuery(sql, interpreter, 1);
    sql = null;
    if (!prevCommit)
        conn.setAutoCommit(false);
    buffer.setLength(0);
    buffer.append("INSERT INTO ").append(tableName).append(" VALUES (");
    int columnCount = schemaInfo.columns.length;
    for (int i = 0; i < columnCount; ++i) {
        if (i > 0)
            buffer.append(',');
        buffer.append('?');
    }
    buffer.append(')');
    sql = buffer.toString();
    interpreter.println("-- INSERTION --");
    interpreter.println(sql);
    try {
        session.importQuery(sql, interpreter);
    } finally {
        interpreter.setQueryMode(QueryMode.Regular);
    }
}
Also used : JaqyHelper(com.teradata.jaqy.interfaces.JaqyHelper) JaqyConnection(com.teradata.jaqy.connection.JaqyConnection) SchemaInfo(com.teradata.jaqy.schema.SchemaInfo) Session(com.teradata.jaqy.Session)

Example 5 with JaqyConnection

use of com.teradata.jaqy.connection.JaqyConnection in project jaqy by Teradata.

the class JaqyInterpreter method getQueryString.

public String getQueryString(String sql, int column) throws SQLException {
    SessionUtils.checkOpen(this);
    JaqyConnection conn = m_session.getConnection();
    return QueryUtils.getQueryString(conn, sql, column, this);
}
Also used : JaqyConnection(com.teradata.jaqy.connection.JaqyConnection)

Aggregations

JaqyConnection (com.teradata.jaqy.connection.JaqyConnection)5 Session (com.teradata.jaqy.Session)4 JaqyHelper (com.teradata.jaqy.interfaces.JaqyHelper)4 DatabaseMetaData (java.sql.DatabaseMetaData)3 SchemaInfo (com.teradata.jaqy.schema.SchemaInfo)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1