Search in sources :

Example 46 with Call

use of org.h2.command.dml.Call in project h2database by h2database.

the class TableFilter method prepareJoinBatch.

/**
 * Attempt to initialize batched join.
 *
 * @param jb join batch if it is already created
 * @param filters the table filters
 * @param filter the filter index (0, 1,...)
 * @return join batch if query runs over index which supports batched
 *         lookups, {@code null} otherwise
 */
public JoinBatch prepareJoinBatch(JoinBatch jb, TableFilter[] filters, int filter) {
    assert filters[filter] == this;
    joinBatch = null;
    joinFilterId = -1;
    if (getTable().isView()) {
        session.pushSubQueryInfo(masks, filters, filter, select.getSortOrder());
        try {
            ((ViewIndex) index).getQuery().prepareJoinBatch();
        } finally {
            session.popSubQueryInfo();
        }
    }
    // For globally top table filter we don't need to create lookup batch,
    // because currently it will not be used (this will be shown in
    // ViewIndex.getPlanSQL()). Probably later on it will make sense to
    // create it to better support X IN (...) conditions, but this needs to
    // be implemented separately. If isAlwaysTopTableFilter is false then we
    // either not a top table filter or top table filter in a sub-query,
    // which in turn is not top in outer query, thus we need to enable
    // batching here to allow outer query run batched join against this
    // sub-query.
    IndexLookupBatch lookupBatch = null;
    if (jb == null && select != null && !isAlwaysTopTableFilter(filter)) {
        lookupBatch = index.createLookupBatch(filters, filter);
        if (lookupBatch != null) {
            jb = new JoinBatch(filter + 1, join);
        }
    }
    if (jb != null) {
        if (nestedJoin != null) {
            throw DbException.throwInternalError();
        }
        joinBatch = jb;
        joinFilterId = filter;
        if (lookupBatch == null && !isAlwaysTopTableFilter(filter)) {
            // createLookupBatch will be called at most once because jb can
            // be created only if lookupBatch is already not null from the
            // call above.
            lookupBatch = index.createLookupBatch(filters, filter);
            if (lookupBatch == null) {
                // the index does not support lookup batching, need to fake
                // it because we are not top
                lookupBatch = JoinBatch.createFakeIndexLookupBatch(this);
            }
        }
        jb.register(this, lookupBatch);
    }
    return jb;
}
Also used : IndexLookupBatch(org.h2.index.IndexLookupBatch)

Example 47 with Call

use of org.h2.command.dml.Call in project h2database by h2database.

the class Table method validateConvertUpdateSequence.

/**
 * Validate all values in this row, convert the values if required, and
 * update the sequence values if required. This call will also set the
 * default values if required and set the computed column if there are any.
 *
 * @param session the session
 * @param row the row
 */
public void validateConvertUpdateSequence(Session session, Row row) {
    for (int i = 0; i < columns.length; i++) {
        Value value = row.getValue(i);
        Column column = columns[i];
        Value v2;
        if (column.getComputed()) {
            // force updating the value
            value = null;
            v2 = column.computeValue(session, row);
        }
        v2 = column.validateConvertUpdateSequence(session, value);
        if (v2 != value) {
            row.setValue(i, v2);
        }
    }
}
Also used : SimpleRowValue(org.h2.result.SimpleRowValue) Value(org.h2.value.Value) Constraint(org.h2.constraint.Constraint)

Example 48 with Call

use of org.h2.command.dml.Call in project h2database by h2database.

the class DateTimeFunctions method getDateFormat.

private static SimpleDateFormat getDateFormat(String format, String locale, String timeZone) {
    try {
        // currently, a new instance is create for each call
        // however, could cache the last few instances
        SimpleDateFormat df;
        if (locale == null) {
            df = new SimpleDateFormat(format);
        } else {
            Locale l = new Locale(locale);
            df = new SimpleDateFormat(format, l);
        }
        if (timeZone != null) {
            df.setTimeZone(TimeZone.getTimeZone(timeZone));
        }
        return df;
    } catch (Exception e) {
        throw DbException.get(ErrorCode.PARSE_ERROR_1, e, format + "/" + locale + "/" + timeZone);
    }
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) DbException(org.h2.message.DbException)

Example 49 with Call

use of org.h2.command.dml.Call in project h2database by h2database.

the class JdbcDatabaseMetaData method getUDTs.

/**
 * Gets the list of user-defined data types.
 * This call returns an empty result set.
 *
 * <ol>
 * <li>TYPE_CAT (String) catalog</li>
 * <li>TYPE_SCHEM (String) schema</li>
 * <li>TYPE_NAME (String) type name</li>
 * <li>CLASS_NAME (String) Java class</li>
 * <li>DATA_TYPE (short) SQL Type - see also java.sql.Types</li>
 * <li>REMARKS (String) description</li>
 * <li>BASE_TYPE (short) base type - see also java.sql.Types</li>
 * </ol>
 *
 * @param catalog ignored
 * @param schemaPattern ignored
 * @param typeNamePattern ignored
 * @param types ignored
 * @return an empty result set
 * @throws SQLException if the connection is closed
 */
@Override
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException {
    try {
        if (isDebugEnabled()) {
            debugCode("getUDTs(" + quote(catalog) + ", " + quote(schemaPattern) + ", " + quote(typeNamePattern) + ", " + quoteIntArray(types) + ");");
        }
        checkClosed();
        PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT " + "CAST(NULL AS VARCHAR) TYPE_CAT, " + "CAST(NULL AS VARCHAR) TYPE_SCHEM, " + "CAST(NULL AS VARCHAR) TYPE_NAME, " + "CAST(NULL AS VARCHAR) CLASS_NAME, " + "CAST(NULL AS SMALLINT) DATA_TYPE, " + "CAST(NULL AS VARCHAR) REMARKS, " + "CAST(NULL AS SMALLINT) BASE_TYPE " + "FROM DUAL WHERE FALSE");
        return prep.executeQuery();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException)

Example 50 with Call

use of org.h2.command.dml.Call in project h2database by h2database.

the class JdbcDatabaseMetaData method hasSynonyms.

private boolean hasSynonyms() {
    Boolean hasSynonyms = this.hasSynonyms;
    if (hasSynonyms == null) {
        SessionInterface si = conn.getSession();
        if (si instanceof SessionRemote) {
            SessionRemote sr = (SessionRemote) si;
            int clientVersion = sr.getClientVersion();
            if (clientVersion >= Constants.TCP_PROTOCOL_VERSION_17) {
                hasSynonyms = true;
            } else if (clientVersion <= Constants.TCP_PROTOCOL_VERSION_15) {
                hasSynonyms = false;
            } else {
                // 1.4.194-1.4.196
                CommandInterface c = sr.prepareCommand("CALL H2VERSION()", Integer.MAX_VALUE);
                ResultInterface result = c.executeQuery(0, false);
                result.next();
                String s = result.currentRow()[0].getString();
                result.close();
                hasSynonyms = "1.4.196".equals(s);
            }
        } else {
            hasSynonyms = true;
        }
        this.hasSynonyms = hasSynonyms;
    }
    return hasSynonyms;
}
Also used : SessionRemote(org.h2.engine.SessionRemote) ResultInterface(org.h2.result.ResultInterface) SessionInterface(org.h2.engine.SessionInterface) CommandInterface(org.h2.command.CommandInterface)

Aggregations

Task (org.h2.util.Task)69 Connection (java.sql.Connection)68 Statement (java.sql.Statement)64 PreparedStatement (java.sql.PreparedStatement)60 ResultSet (java.sql.ResultSet)48 SQLException (java.sql.SQLException)42 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)24 SimpleResultSet (org.h2.tools.SimpleResultSet)24 MVStore (org.h2.mvstore.MVStore)20 Random (java.util.Random)19 JdbcConnection (org.h2.jdbc.JdbcConnection)19 CallableStatement (java.sql.CallableStatement)14 DbException (org.h2.message.DbException)13 IOException (java.io.IOException)10 JdbcSQLException (org.h2.jdbc.JdbcSQLException)7 ArrayList (java.util.ArrayList)6 Expression (org.h2.expression.Expression)6 ValueString (org.h2.value.ValueString)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4