当前位置: 首页>>代码示例>>Java>>正文


Java DbException.getErrorCode方法代码示例

本文整理汇总了Java中org.h2.message.DbException.getErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java DbException.getErrorCode方法的具体用法?Java DbException.getErrorCode怎么用?Java DbException.getErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.message.DbException的用法示例。


在下文中一共展示了DbException.getErrorCode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Parse the statement, but don't prepare it for execution.
 *
 * @param sql the SQL statement to parse
 * @return the prepared object
 */
Prepared parse(String sql) {
    Prepared p;
    try {
        // first, try the fast variant
        p = parse(sql, false);
    } catch (DbException e) {
        if (e.getErrorCode() == ErrorCode.SYNTAX_ERROR_1) {
            // now, get the detailed exception
            p = parse(sql, true);
        } else {
            throw e.addSQL(sql);
        }
    }
    p.setPrepareAlways(recompileAlways);
    p.setParameterList(parameters);
    return p;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:Parser.java

示例2: updateRows

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Update a list of rows in this table.
 *
 * @param prepared the prepared statement
 * @param session the session
 * @param rows a list of row pairs of the form old row, new row, old row,
 *            new row,...
 */
public void updateRows(Prepared prepared, Session session, RowList rows) {
    // in case we need to undo the update
    Session.Savepoint rollback = session.setSavepoint();
    // remove the old rows
    int rowScanCount = 0;
    for (rows.reset(); rows.hasNext();) {
        if ((++rowScanCount & 127) == 0) {
            prepared.checkCanceled();
        }
        Row o = rows.next();
        rows.next();
        removeRow(session, o);
        session.log(this, UndoLogRecord.DELETE, o);
    }
    // add the new rows
    for (rows.reset(); rows.hasNext();) {
        if ((++rowScanCount & 127) == 0) {
            prepared.checkCanceled();
        }
        rows.next();
        Row n = rows.next();
        try {
            addRow(session, n);
        } catch (DbException e) {
            if (e.getErrorCode() == ErrorCode.CONCURRENT_UPDATE_1) {
                session.rollbackTo(rollback, false);
                session.startStatementWithinTransaction();
                rollback = session.setSavepoint();
            }
            throw e;
        }
        session.log(this, UndoLogRecord.INSERT, n);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:43,代码来源:Table.java

示例3: convert

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Convert a value to this column's type.
 *
 * @param v the value
 * @return the value
 */
public Value convert(Value v) {
    try {
        return v.convertTo(type);
    } catch (DbException e) {
        if (e.getErrorCode() == ErrorCode.DATA_CONVERSION_ERROR_1) {
            String target = (table == null ? "" : table.getName() + ": ") +
                    getCreateSQL();
            throw DbException.get(
                    ErrorCode.DATA_CONVERSION_ERROR_1,
                    v.getSQL() + " (" + target + ")");
        }
        throw e;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:21,代码来源:Column.java

示例4: filterConcurrentUpdate

import org.h2.message.DbException; //导入方法依赖的package包/类
private long filterConcurrentUpdate(DbException e, long start) {
    if (e.getErrorCode() != ErrorCode.CONCURRENT_UPDATE_1) {
        throw e;
    }
    long now = System.nanoTime() / 1000000;
    if (start != 0 && now - start > session.getLockTimeout()) {
        throw DbException.get(ErrorCode.LOCK_TIMEOUT_1, e.getCause(), "");
    }
    Database database = session.getDatabase();
    int sleep = 1 + MathUtils.randomInt(10);
    while (true) {
        try {
            if (database.isMultiThreaded()) {
                Thread.sleep(sleep);
            } else {
                database.wait(sleep);
            }
        } catch (InterruptedException e1) {
            // ignore
        }
        long slept = System.nanoTime() / 1000000 - now;
        if (slept >= sleep) {
            break;
        }
    }
    return start == 0 ? now : start;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:28,代码来源:Command.java

示例5: replace

import org.h2.message.DbException; //导入方法依赖的package包/类
private void replace(Row row) {
    int count = update(row);
    if (count == 0) {
        try {
            table.validateConvertUpdateSequence(session, row);
            boolean done = table.fireBeforeRow(session, null, row);
            if (!done) {
                table.lock(session, true, false);
                table.addRow(session, row);
                session.log(table, UndoLogRecord.INSERT, row);
                table.fireAfterRow(session, null, row, false);
            }
        } catch (DbException e) {
            if (e.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
                // possibly a concurrent replace or insert
                Index index = (Index) e.getSource();
                if (index != null) {
                    // verify the index columns match the key
                    Column[] indexColumns = index.getColumns();
                    boolean indexMatchesKeys = false;
                    if (indexColumns.length <= keys.length) {
                        for (int i = 0; i < indexColumns.length; i++) {
                            if (indexColumns[i] != keys[i]) {
                                indexMatchesKeys = false;
                                break;
                            }
                        }
                    }
                    if (indexMatchesKeys) {
                        throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, table.getName());
                    }
                }
            }
            throw e;
        }
    } else if (count != 1) {
        throw DbException.get(ErrorCode.DUPLICATE_KEY_1, table.getSQL());
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:40,代码来源:Replace.java

示例6: next

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Get the next trunk page or null if no next trunk page.
 *
 * @return the next trunk page or null
 */
PageStreamTrunk next() {
    canDelete = false;
    if (first == 0) {
        first = next;
    } else if (first == next) {
        return null;
    }
    if (next == 0 || next >= store.getPageCount()) {
        return null;
    }
    Page p;
    current = next;
    try {
        p = store.getPage(next);
    } catch (DbException e) {
        if (e.getErrorCode() == ErrorCode.FILE_CORRUPTED_1) {
            // wrong checksum means end of stream
            return null;
        }
        throw e;
    }
    if (p == null || p instanceof PageStreamTrunk ||
            p instanceof PageStreamData) {
        canDelete = true;
    }
    if (!(p instanceof PageStreamTrunk)) {
        return null;
    }
    PageStreamTrunk t = (PageStreamTrunk) p;
    if (previous > 0 && t.parent != previous) {
        return null;
    }
    previous = next;
    next = t.nextTrunk;
    return t;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:PageStreamTrunk.java

示例7: connectEmbeddedOrServer

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Open a new (remote or embedded) session.
 *
 * @param openNew whether to open a new session in any case
 * @return the session
 */
public SessionInterface connectEmbeddedOrServer(boolean openNew) {
    ConnectionInfo ci = connectionInfo;
    if (ci.isRemote()) {
        connectServer(ci);
        return this;
    }
    // create the session using reflection,
    // so that the JDBC layer can be compiled without it
    boolean autoServerMode = Boolean.parseBoolean(
            ci.getProperty("AUTO_SERVER", "false"));
    ConnectionInfo backup = null;
    try {
        if (autoServerMode) {
            backup = ci.clone();
            connectionInfo = ci.clone();
        }
        if (openNew) {
            ci.setProperty("OPEN_NEW", "true");
        }
        if (sessionFactory == null) {
            sessionFactory = (SessionFactory) Class.forName(
                    "org.h2.engine.Engine").getMethod("getInstance").invoke(null);
        }
        return sessionFactory.createSession(ci);
    } catch (Exception re) {
        DbException e = DbException.convert(re);
        if (e.getErrorCode() == ErrorCode.DATABASE_ALREADY_OPEN_1) {
            if (autoServerMode) {
                String serverKey = ((JdbcSQLException) e.getSQLException()).
                        getSQL();
                if (serverKey != null) {
                    backup.setServerKey(serverKey);
                    // OPEN_NEW must be removed now, otherwise
                    // opening a session with AUTO_SERVER fails
                    // if another connection is already open
                    backup.removeProperty("OPEN_NEW", null);
                    connectServer(backup);
                    return this;
                }
            }
        }
        throw e;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:51,代码来源:SessionRemote.java

示例8: autoReconnect

import org.h2.message.DbException; //导入方法依赖的package包/类
/**
 * Automatically re-connect if necessary and if configured to do so.
 *
 * @param count the retry count index
 * @return true if reconnected
 */
private boolean autoReconnect(int count) {
    if (!isClosed()) {
        return false;
    }
    if (!autoReconnect) {
        return false;
    }
    if (!cluster && !autoCommit) {
        return false;
    }
    if (count > SysProperties.MAX_RECONNECT) {
        return false;
    }
    lastReconnect++;
    while (true) {
        try {
            embedded = connectEmbeddedOrServer(false);
            break;
        } catch (DbException e) {
            if (e.getErrorCode() != ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE) {
                throw e;
            }
            // exclusive mode: re-try endlessly
            try {
                Thread.sleep(500);
            } catch (Exception e2) {
                // ignore
            }
        }
    }
    if (embedded == this) {
        // connected to a server somewhere else
        embedded = null;
    } else {
        // opened an embedded connection now -
        // must connect to this database in server mode
        // unfortunately
        connectEmbeddedOrServer(true);
    }
    recreateSessionState();
    if (eventListener != null) {
        eventListener.setProgress(DatabaseEventListener.STATE_RECONNECTED,
                databaseName, count, SysProperties.MAX_RECONNECT);
    }
    return true;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:53,代码来源:SessionRemote.java

示例9: handleOnDuplicate

import org.h2.message.DbException; //导入方法依赖的package包/类
private void handleOnDuplicate(DbException de) {
    if (de.getErrorCode() != ErrorCode.DUPLICATE_KEY_1) {
        throw de;
    }
    if (duplicateKeyAssignmentMap == null ||
            duplicateKeyAssignmentMap.isEmpty()) {
        throw de;
    }

    ArrayList<String> variableNames = new ArrayList<String>(
            duplicateKeyAssignmentMap.size());
    for (int i = 0; i < columns.length; i++) {
        String key = table.getSchema().getName() + "." +
                table.getName() + "." + columns[i].getName();
        variableNames.add(key);
        session.setVariable(key,
                list.get(getCurrentRowNumber() - 1)[i].getValue(session));
    }

    StatementBuilder buff = new StatementBuilder("UPDATE ");
    buff.append(table.getSQL()).append(" SET ");
    for (Column column : duplicateKeyAssignmentMap.keySet()) {
        buff.appendExceptFirst(", ");
        Expression ex = duplicateKeyAssignmentMap.get(column);
        buff.append(column.getSQL()).append("=").append(ex.getSQL());
    }
    buff.append(" WHERE ");
    Index foundIndex = searchForUpdateIndex();
    if (foundIndex == null) {
        throw DbException.getUnsupportedException(
                "Unable to apply ON DUPLICATE KEY UPDATE, no index found!");
    }
    buff.append(prepareUpdateCondition(foundIndex).getSQL());
    String sql = buff.toString();
    Prepared command = session.prepare(sql);
    for (Parameter param : command.getParameters()) {
        Parameter insertParam = parameters.get(param.getIndex());
        param.setValue(insertParam.getValue(session));
    }
    command.update();
    for (String variableName : variableNames) {
        session.setVariable(variableName, ValueNull.INSTANCE);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:45,代码来源:Insert.java

示例10: openExisting

import org.h2.message.DbException; //导入方法依赖的package包/类
private void openExisting() {
    try {
        file = database.openFile(fileName, accessMode, true);
    } catch (DbException e) {
        if (e.getErrorCode() == ErrorCode.IO_EXCEPTION_2) {
            if (e.getMessage().contains("locked")) {
                // in Windows, you can't open a locked file
                // (in other operating systems, you can)
                // the exact error message is:
                // "The process cannot access the file because
                // another process has locked a portion of the file"
                throw DbException.get(
                        ErrorCode.DATABASE_ALREADY_OPEN_1, e, fileName);
            }
        }
        throw e;
    }
    lockFile();
    readStaticHeader();
    freeListPagesPerList = PageFreeList.getPagesAddressed(pageSize);
    fileLength = file.length();
    pageCount = (int) (fileLength / pageSize);
    if (pageCount < MIN_PAGE_COUNT) {
        if (database.isReadOnly()) {
            throw DbException.get(ErrorCode.FILE_CORRUPTED_1,
                    fileName + " pageCount: " + pageCount);
        }
        file.releaseLock();
        file.close();
        FileUtils.delete(fileName);
        openNew();
        return;
    }
    readVariableHeader();
    log = new PageLog(this);
    log.openForReading(logKey, logFirstTrunkPage, logFirstDataPage);
    boolean old = database.isMultiVersion();
    // temporarily disabling multi-version concurrency, because
    // the multi-version index sometimes compares rows
    // and the LOB storage is not yet available.
    database.setMultiVersion(false);
    boolean isEmpty = recover();
    database.setMultiVersion(old);
    if (!database.isReadOnly()) {
        readMode = true;
        if (!isEmpty || !SysProperties.MODIFY_ON_WRITE || tempObjects != null) {
            openForWriting();
            removeOldTempIndexes();
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:52,代码来源:PageStore.java


注:本文中的org.h2.message.DbException.getErrorCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。