Search in sources :

Example 1 with Stopwatch

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

the class DBInfo method typeIndex.

private void typeIndex(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);
    ResultSet tables = metaData.getIndexInfo(dbname, schema, table, false, true);
    lucee.runtime.type.Query qry = new QueryImpl(tables, "query", pageContext.getTimeZone());
    // type int 2 string
    int rows = qry.getRecordcount();
    String strType;
    int type, card;
    for (int row = 1; row <= rows; row++) {
        // type
        switch(type = Caster.toIntValue(qry.getAt(KeyConstants._type, row))) {
            case 0:
                strType = "Table Statistic";
                break;
            case 1:
                strType = "Clustered Index";
                break;
            case 2:
                strType = "Hashed Index";
                break;
            case 3:
                strType = "Other Index";
                break;
            default:
                strType = Caster.toString(type);
        }
        qry.setAt(KeyConstants._type, row, strType);
        // CARDINALITY
        card = Caster.toIntValue(qry.getAt(CARDINALITY, row), 0);
        qry.setAt(CARDINALITY, row, Caster.toDouble(card));
    }
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Stopwatch(lucee.runtime.timer.Stopwatch) ResultSet(java.sql.ResultSet) Query(lucee.runtime.type.Query)

Example 2 with Stopwatch

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

the class DBInfo method typeProcedureColumns.

private void typeProcedureColumns(DatabaseMetaData metaData) throws SQLException, PageException {
    required("procedure", procedure);
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    procedure = setCase(metaData, procedure);
    pattern = setCase(metaData, pattern);
    if (StringUtil.isEmpty(pattern, true))
        pattern = null;
    String schema = null;
    int index = procedure.indexOf('.');
    if (index > 0) {
        schema = procedure.substring(0, index);
        procedure = procedure.substring(index + 1);
    }
    lucee.runtime.type.Query qry = new QueryImpl(metaData.getProcedureColumns(dbname, schema, procedure, 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 3 with Stopwatch

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

the class DBInfo method typeVersion.

private void typeVersion(DatabaseMetaData metaData) throws PageException, SQLException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    Key[] columns = new Key[] { DATABASE_PRODUCTNAME, DATABASE_VERSION, DRIVER_NAME, DRIVER_VERSION, JDBC_MAJOR_VERSION, JDBC_MINOR_VERSION };
    String[] types = new String[] { "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "DOUBLE", "DOUBLE" };
    lucee.runtime.type.Query qry = new QueryImpl(columns, types, 1, "query");
    qry.setAt(DATABASE_PRODUCTNAME, 1, metaData.getDatabaseProductName());
    qry.setAt(DATABASE_VERSION, 1, metaData.getDatabaseProductVersion());
    qry.setAt(DRIVER_NAME, 1, metaData.getDriverName());
    qry.setAt(DRIVER_VERSION, 1, metaData.getDriverVersion());
    qry.setAt(JDBC_MAJOR_VERSION, 1, new Double(metaData.getJDBCMajorVersion()));
    qry.setAt(JDBC_MINOR_VERSION, 1, new Double(metaData.getJDBCMinorVersion()));
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Stopwatch(lucee.runtime.timer.Stopwatch) Key(lucee.runtime.type.Collection.Key) Query(lucee.runtime.type.Query)

Example 4 with Stopwatch

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

the class DBInfo method typeTables.

private void typeTables(DatabaseMetaData metaData) throws PageException, SQLException {
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    pattern = setCase(metaData, pattern);
    lucee.runtime.type.Query qry = new QueryImpl(metaData.getTables(dbname, null, pattern, null), "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 5 with Stopwatch

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

the class DBInfo method typeColumns.

private void typeColumns(DatabaseMetaData metaData) throws PageException, SQLException {
    required("table", table);
    Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
    stopwatch.start();
    table = setCase(metaData, table);
    pattern = setCase(metaData, pattern);
    if (StringUtil.isEmpty(pattern, true))
        pattern = null;
    String schema = null;
    int index = table.indexOf('.');
    if (index > 0) {
        schema = table.substring(0, index);
        table = table.substring(index + 1);
    }
    checkTable(metaData);
    Query qry = new QueryImpl(metaData.getColumns(dbname, schema, table, pattern), "query", pageContext.getTimeZone());
    int len = qry.getRecordcount();
    if (qry.getColumn(COLUMN_DEF, null) != null)
        qry.rename(COLUMN_DEF, COLUMN_DEFAULT_VALUE);
    else if (qry.getColumn(COLUMN_DEFAULT, null) != null)
        qry.rename(COLUMN_DEFAULT, COLUMN_DEFAULT_VALUE);
    // make sure decimal digits exists
    QueryColumn col = qry.getColumn(DECIMAL_DIGITS, null);
    if (col == null) {
        Array arr = new ArrayImpl();
        for (int i = 1; i <= len; i++) {
            arr.append(lucee.runtime.op.Constants.DOUBLE_ZERO);
        }
        qry.addColumn(DECIMAL_DIGITS, arr);
    }
    // add is primary
    Map primaries = new HashMap();
    String tblName;
    Array isPrimary = new ArrayImpl();
    Set set;
    Object o;
    for (int i = 1; i <= len; i++) {
        // decimal digits
        o = qry.getAt(DECIMAL_DIGITS, i, null);
        if (o == null)
            qry.setAtEL(DECIMAL_DIGITS, i, lucee.runtime.op.Constants.DOUBLE_ZERO);
        set = (Set) primaries.get(tblName = (String) qry.getAt(TABLE_NAME, i));
        if (set == null) {
            set = toSet(metaData.getPrimaryKeys(dbname, null, tblName), true, "COLUMN_NAME");
            primaries.put(tblName, set);
        }
        isPrimary.append(set.contains(qry.getAt(COLUMN_NAME, i)) ? "YES" : "NO");
    }
    qry.addColumn(IS_PRIMARYKEY, isPrimary);
    // add is foreignkey
    Map foreigns = new HashMap();
    Array isForeign = new ArrayImpl();
    Array refPrim = new ArrayImpl();
    Array refPrimTbl = new ArrayImpl();
    // Map map,inner;
    Map<String, Map<String, SVArray>> map;
    Map<String, SVArray> inner;
    for (int i = 1; i <= len; i++) {
        map = (Map) foreigns.get(tblName = (String) qry.getAt(TABLE_NAME, i));
        if (map == null) {
            map = toMap(metaData.getImportedKeys(dbname, schema, table), true, "FKCOLUMN_NAME", new String[] { "PKCOLUMN_NAME", "PKTABLE_NAME" });
            foreigns.put(tblName, map);
        }
        inner = map.get(qry.getAt(COLUMN_NAME, i));
        if (inner != null) {
            isForeign.append("YES");
            refPrim.append(inner.get("PKCOLUMN_NAME"));
            refPrimTbl.append(inner.get("PKTABLE_NAME"));
        } else {
            isForeign.append("NO");
            refPrim.append("N/A");
            refPrimTbl.append("N/A");
        }
    }
    qry.addColumn(IS_FOREIGNKEY, isForeign);
    qry.addColumn(REFERENCED_PRIMARYKEY, refPrim);
    qry.addColumn(REFERENCED_PRIMARYKEY_TABLE, refPrimTbl);
    qry.setExecutionTime(stopwatch.time());
    pageContext.setVariable(name, qry);
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) Query(lucee.runtime.type.Query) HashMap(java.util.HashMap) ArrayImpl(lucee.runtime.type.ArrayImpl) Stopwatch(lucee.runtime.timer.Stopwatch) SVArray(lucee.runtime.type.SVArray) Array(lucee.runtime.type.Array) QueryImpl(lucee.runtime.type.QueryImpl) QueryColumn(lucee.runtime.type.QueryColumn) SVArray(lucee.runtime.type.SVArray) HashMap(java.util.HashMap) Map(java.util.Map)

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