Package org.tmatesoft.sqljet.core

Examples of org.tmatesoft.sqljet.core.SqlJetException


                PAGERTRACE("TRANSACTION %s\n", PAGERID());
                if (useJournal && !tempFile && journalMode != SqlJetPagerJournalMode.OFF) {
                    openJournal();
                }
            } else {
                throw new SqlJetException(SqlJetErrorCode.BUSY);
            }
        } else if (journalOpen && journalOff == 0) {
            /*
             * This happens when the pager was in exclusive-access mode the last
             * time a (read or write) transaction was successfully concluded by
View Full Code Here


     * @throws SqlJetException
     *
     */
    private void writeJournalHdr() throws SqlJetException {

        SqlJetException rc = null;

        ISqlJetMemoryPointer zHeader = tmpSpace;
        int nHeader = pageSize;
        int nWrite;
        int ii;
View Full Code Here

        SqlJetFileType fileType = null;

        Set<SqlJetFileOpenPermission> flags = SqlJetUtility.of(SqlJetFileOpenPermission.READWRITE,
                SqlJetFileOpenPermission.EXCLUSIVE, SqlJetFileOpenPermission.CREATE);

        SqlJetException rc = null;

        assert (state.compareTo(SqlJetPagerState.RESERVED) >= 0);
        assert (useJournal);
        assert (pagesInJournal == null);

        getPageCount();
        pagesInJournal = new BitSet(dbSize);

        try {

            if (!journalOpen) {
                if (tempFile) {
                    flags.add(SqlJetFileOpenPermission.DELETEONCLOSE);
                    fileType = SqlJetFileType.TEMP_JOURNAL;
                } else {
                    fileType = SqlJetFileType.MAIN_JOURNAL;
                }
                try {
                    if (journalMode == SqlJetPagerJournalMode.MEMORY) {
                        jfd = fileSystem.memJournalOpen();
                    } else {
                        jfd = fileSystem.open(journal, fileType, flags);
                    }
                } catch (SqlJetException e) {
                    rc = e;
                }
                assert (rc != null || jfd != null);
                journalOff = 0;
                setMaster = false;
                journalHdr = 0;

                if (rc != null) {
                    fileSystem.delete(journal, false);
                    throw rc;
                }

            }
            journalOpen = true;
            journalStarted = false;
            needSync = false;
            nRec = 0;
            if (errCode != null) {
                rc = new SqlJetException(errCode);
                throw rc;
            }
            dbOrigSize = dbSize;

            try {
                writeJournalHdr();
            } catch (SqlJetException e) {
                rc = e;
            }

            if (nSavepoint > 0 && rc == null) {
                try {
                    openSubJournal();
                } catch (SqlJetException e) {
                    rc = e;
                }
            }

            if (rc != null) {
                rc = null;
                try {
                    endTransaction(false);
                } catch (SqlJetException e) {
                    rc = e;
                }
                if (rc == null) {
                    rc = new SqlJetException(SqlJetErrorCode.FULL);
                    throw rc;
                }
            }

        } finally {
View Full Code Here

     * int, boolean)
     */
    public void commitPhaseOne(String master, boolean noSync) throws SqlJetException {

        if (errCode != null) {
            throw new SqlJetException(errCode);
        }

        /*
         * If no changes have been made, we can leave the transaction early.
         */
        if (!dbModified && (journalMode != SqlJetPagerJournalMode.DELETE || exclusiveMode())) {
            assert (!dirtyCache || !journalOpen);
            return;
        }

        PAGERTRACE("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", fileName, master, dbSize);

        /*
         * If this is an in-memory db, or no pages have been written to, or this
         * function has already been called, it is a no-op.
         */
        try {
            if (state != SqlJetPagerState.SYNCED && !memDb && dirtyCache) {

                /*
                 * If a master journal file name has already been written to the
                 * journal file, then no sync is required. This happens when it
                 * is written, then the process fails to upgrade from a RESERVED
                 * to an EXCLUSIVE lock. The next time the process tries to
                 * commit the transaction the m-j name will have already been
                 * written.
                 */
                if (!setMaster) {

                    incrChangeCounter();

                    if (journalMode != SqlJetPagerJournalMode.OFF) {

                        if (dbSize < dbOrigSize) {
                            /*
                             * If this transaction has made the database
                             * smaller, then all pages being discarded by the
                             * truncation must be written to the journal file.
                             */
                            int i;
                            long iSkip = PAGER_MJ_PGNO();
                            int dbSize = this.dbSize;
                            this.dbSize = this.dbOrigSize;
                            for (i = dbSize + 1; i <= this.dbOrigSize; i++) {
                                if (!SqlJetUtility.bitSetTest(pagesInJournal, i) && i != iSkip) {
                                    final ISqlJetPage pg = getPage(i);
                                    pg.write();
                                    pg.unref();
                                }
                            }
                            this.dbSize = dbSize;
                        }

                        writeMasterJournal(master);
                        syncJournal();
                    }
                }

                /* Write all dirty pages to the database file */
                final ISqlJetPage dirtyList = pageCache.getDirtyList();
                writePageList(dirtyList);
                /*
                 * The error might have left the dirty list all fouled up here,
                 * but that does not matter because if the if the dirty list did
                 * get corrupted, then the transaction will roll back and
                 * discard the dirty list. There is an assert in
                 * pager_get_all_dirty_pages() that verifies that no attempt is
                 * made to use an invalid dirty list.
                 */
                pageCache.cleanAll();

                if (dbSize != dbFileSize) {
                    assert (state.compareTo(SqlJetPagerState.EXCLUSIVE) >= 0);
                    doTruncate(dbSize - (dbSize == PAGER_MJ_PGNO() ? 1 : 0));
                }

                /* Sync the database file. */
                if (!this.noSync && !noSync) {
                    fd.sync(syncFlags);
                }

                state = SqlJetPagerState.SYNCED;

            }

        } catch (SqlJetIOException e) {
            if (e.getIoErrorCode() == SqlJetIOErrorCode.IOERR_BLOCKED) {
                /*
                 * pager_incr_changecounter() may attempt to obtain an exclusive
                 * lock to spill the cache and return IOERR_BLOCKED. But since
                 * there is no chance the cache is inconsistent, it is better to
                 * return SQLITE_BUSY.
                 */
                throw new SqlJetException(SqlJetErrorCode.BUSY);
            }
        }
    }
View Full Code Here

     *
     * @see org.tmatesoft.sqljet.core.ISqlJetPager#commitPhaseTwo()
     */
    public void commitPhaseTwo() throws SqlJetException {
        if (null != errCode) {
            throw new SqlJetException(errCode);
        }
        if (state.compareTo(SqlJetPagerState.RESERVED) < 0) {
            throw new SqlJetException(SqlJetErrorCode.ERROR);
        }
        if (!dbModified && (journalMode != SqlJetPagerJournalMode.DELETE || !exclusiveMode())) {
            assert (!dirtyCache || !journalOpen);
            return;
        }
View Full Code Here

            endTransaction(setMaster);
        } else if (null != errCode && errCode != SqlJetErrorCode.FULL) {
            if (state.compareTo(SqlJetPagerState.EXCLUSIVE) >= 0) {
                playback(false);
            }
            throw new SqlJetException(errCode);
        } else {
            try {
                if (state == SqlJetPagerState.RESERVED) {
                    try {
                        playback(false);
View Full Code Here

     * If there are less than (iSavepoint+1) active savepoints when this
     * function is called it is a no-op.
     */
    public void savepoint(SqlJetSavepointOperation op, int iSavepoint) throws SqlJetException {

        SqlJetException rc = null;

        assert (op == SqlJetSavepointOperation.RELEASE || op == SqlJetSavepointOperation.ROLLBACK);

        if (iSavepoint < this.nSavepoint) {
            int ii;
            int nNew = iSavepoint + (op == SqlJetSavepointOperation.ROLLBACK ? 1 : 0);
            for (ii = nNew; ii < nSavepoint; ii++) {
                aSavepoint[ii].pInSavepoint = null;
            }
            nSavepoint = nNew;

            if (op == SqlJetSavepointOperation.ROLLBACK && jfd != null) {
                PagerSavepoint pSavepoint = (nNew == 0) ? null : aSavepoint[nNew - 1];
                try {
                    playbackSavepoint(pSavepoint);
                } catch (SqlJetException e) {
                    rc = e;
                    assert (rc.getErrorCode() != SqlJetErrorCode.DONE);
                }
            }

            /*
             * If this is a release of the outermost savepoint, truncate the
View Full Code Here

        flags = SqlJetUtility.noneOf(SqlJetVdbeMemFlags.class);

        flags.add(enc == null ? SqlJetVdbeMemFlags.Blob : SqlJetVdbeMemFlags.Str);

        if (nByte > iLimit) {
            throw new SqlJetException(SqlJetErrorCode.TOOBIG);
        }

        this.z = z;
        this.n = nByte;
        this.enc = (enc == null ? SqlJetEncoding.UTF8 : enc);
View Full Code Here

    public void setPageSize(int pageSize, int reserve) throws SqlJetException {
        assert (reserve >= -1 && reserve <= 255);
        enter();
        try {
            if (pBt.pageSizeFixed) {
                throw new SqlJetException(SqlJetErrorCode.READONLY);
            }
            if (reserve < 0) {
                reserve = pBt.pageSize - pBt.usableSize;
            }
            assert (reserve >= 0 && reserve <= 255);
View Full Code Here

    public void setAutoVacuum(SqlJetAutoVacuumMode autoVacuum) throws SqlJetException {
        boolean av = autoVacuum != SqlJetAutoVacuumMode.NONE;
        enter();
        try {
            if (pBt.pageSizeFixed && av != pBt.autoVacuum) {
                throw new SqlJetException(SqlJetErrorCode.READONLY);
            } else {
                pBt.autoVacuum = av;
            }
        } finally {
            leave();
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.SqlJetException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.