Search in sources :

Example 6 with Stopwatch

use of lucee.runtime.timer.Stopwatch in project Lucee by lucee.

the class DBInfo method typeProcedures.

private void typeProcedures(DatabaseMetaData metaData) throws SQLException, PageException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    String schema = null;
    pattern = setCase(metaData, pattern);
    if (StringUtil.isEmpty(pattern, true)) {
        pattern = null;
    }
    lucee.runtime.type.Query qry = new QueryImpl(metaData.getProcedures(dbname, schema, pattern), "query", pageContext.getTimeZone());
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Stopwatch(lucee.runtime.timer.Stopwatch) Query(lucee.runtime.type.Query)

Example 7 with Stopwatch

use of lucee.runtime.timer.Stopwatch in project Lucee by lucee.

the class DBInfo method typeForeignKeys.

private void typeForeignKeys(DatabaseMetaData metaData) throws PageException, SQLException {
    required("table", table);
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    table = setCase(metaData, table);
    int index = table.indexOf('.');
    String schema = null;
    if (index > 0) {
        schema = table.substring(0, index);
        table = table.substring(index + 1);
    }
    checkTable(metaData);
    lucee.runtime.type.Query qry = new QueryImpl(metaData.getExportedKeys(dbname, schema, table), "query", pageContext.getTimeZone());
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Stopwatch(lucee.runtime.timer.Stopwatch) Query(lucee.runtime.type.Query)

Example 8 with Stopwatch

use of lucee.runtime.timer.Stopwatch in project Lucee by lucee.

the class DBInfo method typeUsers.

private void typeUsers(DatabaseMetaData metaData) throws PageException, SQLException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    checkTable(metaData);
    ResultSet result = metaData.getSchemas();
    Query qry = new QueryImpl(result, "query", pageContext.getTimeZone());
    qry.rename(TABLE_SCHEM, USER);
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Query(lucee.runtime.type.Query) Stopwatch(lucee.runtime.timer.Stopwatch) ResultSet(java.sql.ResultSet)

Example 9 with Stopwatch

use of lucee.runtime.timer.Stopwatch in project Lucee by lucee.

the class DBInfo method typeDBNames.

private void typeDBNames(DatabaseMetaData metaData) throws PageException, SQLException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    lucee.runtime.type.Query catalogs = new QueryImpl(metaData.getCatalogs(), "query", pageContext.getTimeZone());
    lucee.runtime.type.Query scheme = new QueryImpl(metaData.getSchemas(), "query", pageContext.getTimeZone());
    Pattern p = null;
    if (pattern != null && !"%".equals(pattern))
        p = SQLUtil.pattern(pattern, true);
    String[] columns = new String[] { "database_name", "type" };
    String[] types = new String[] { "VARCHAR", "VARCHAR" };
    lucee.runtime.type.Query qry = new QueryImpl(columns, types, 0, "query");
    int row = 1, len = catalogs.getRecordcount();
    String value;
    // catalog
    for (int i = 1; i <= len; i++) {
        value = (String) catalogs.getAt(TABLE_CAT, i);
        if (!matchPattern(value, p))
            continue;
        qry.addRow();
        qry.setAt(DATABASE_NAME, row, value);
        qry.setAt(KeyConstants._type, row, "CATALOG");
        row++;
    }
    // scheme
    len = scheme.getRecordcount();
    for (int i = 1; i <= len; i++) {
        value = (String) scheme.getAt(TABLE_SCHEM, i);
        if (!matchPattern(value, p))
            continue;
        qry.addRow();
        qry.setAt(DATABASE_NAME, row, value);
        qry.setAt(KeyConstants._type, row, "SCHEMA");
        row++;
    }
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : Pattern(java.util.regex.Pattern) QueryImpl(lucee.runtime.type.QueryImpl) Stopwatch(lucee.runtime.timer.Stopwatch) Query(lucee.runtime.type.Query)

Example 10 with Stopwatch

use of lucee.runtime.timer.Stopwatch in project Lucee by lucee.

the class HSQLDBHandler method execute.

/**
 * executes a query on the queries inside the cld fusion enviroment
 * @param pc Page Context
 * @param sql
 * @param maxrows
 * @return result as Query
 * @throws PageException
 * @throws PageException
 */
public Query execute(PageContext pc, SQL sql, int maxrows, int fetchsize, TimeSpan timeout) throws PageException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    String prettySQL = null;
    Selects selects = null;
    // First Chance
    try {
        SelectParser parser = new SelectParser();
        selects = parser.parse(sql.getSQLString());
        Query q = qoq.execute(pc, sql, selects, maxrows);
        q.setExecutionTime(stopwatch.time());
        return q;
    } catch (SQLParserException spe) {
        // lucee.print.printST(spe);
        // sp
        // lucee.print.out("sql parser crash at:");
        // lucee.print.out("--------------------------------");
        // lucee.print.out(sql.getSQLString().trim());
        // lucee.print.out("--------------------------------");
        // print.e("1:"+sql.getSQLString());
        prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString());
        // print.e("2:"+prettySQL);
        try {
            Query query = executer.execute(pc, sql, prettySQL, maxrows);
            query.setExecutionTime(stopwatch.time());
            return query;
        } catch (PageException ex) {
        // lucee.print.printST(ex);
        // lucee.print.out("old executor/zql crash at:");
        // lucee.print.out("--------------------------------");
        // lucee.print.out(sql.getSQLString().trim());
        // lucee.print.out("--------------------------------");
        }
    } catch (PageException e) {
    // throw e;
    // print.out("new executor crash at:");
    // print.out("--------------------------------");
    // print.out(sql.getSQLString().trim());
    // print.out("--------------------------------");
    }
    // SECOND Chance with hsqldb
    try {
        boolean isUnion = false;
        Set<String> tables = null;
        if (selects != null) {
            HSQLUtil2 hsql2 = new HSQLUtil2(selects);
            isUnion = hsql2.isUnion();
            tables = hsql2.getInvokedTables();
        } else {
            if (prettySQL == null)
                prettySQL = SQLPrettyfier.prettyfie(sql.getSQLString());
            HSQLUtil hsql = new HSQLUtil(prettySQL);
            tables = hsql.getInvokedTables();
            isUnion = hsql.isUnion();
        }
        String strSQL = StringUtil.replace(sql.getSQLString(), "[", "", false);
        strSQL = StringUtil.replace(strSQL, "]", "", false);
        sql.setSQLString(strSQL);
        return _execute(pc, sql, maxrows, fetchsize, timeout, stopwatch, tables, isUnion);
    } catch (ParseException e) {
        throw new DatabaseException(e.getMessage(), null, sql, null);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Query(lucee.runtime.type.Query) Stopwatch(lucee.runtime.timer.Stopwatch) SQLParserException(lucee.runtime.sql.SQLParserException) Selects(lucee.runtime.sql.Selects) ParseException(lucee.runtime.sql.old.ParseException) SelectParser(lucee.runtime.sql.SelectParser) DatabaseException(lucee.runtime.exp.DatabaseException)

Aggregations

Stopwatch (lucee.runtime.timer.Stopwatch)10 Query (lucee.runtime.type.Query)10 QueryImpl (lucee.runtime.type.QueryImpl)9 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 DatabaseException (lucee.runtime.exp.DatabaseException)1 PageException (lucee.runtime.exp.PageException)1 SQLParserException (lucee.runtime.sql.SQLParserException)1 SelectParser (lucee.runtime.sql.SelectParser)1 Selects (lucee.runtime.sql.Selects)1 ParseException (lucee.runtime.sql.old.ParseException)1 Array (lucee.runtime.type.Array)1 ArrayImpl (lucee.runtime.type.ArrayImpl)1 Key (lucee.runtime.type.Collection.Key)1 QueryColumn (lucee.runtime.type.QueryColumn)1 SVArray (lucee.runtime.type.SVArray)1