Examples of ISqlJetFile


Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

            final Set<SqlJetBtreeFlags> flags = (writable ? WRITE_FLAGS : READ_FLAGS);
            final Set<SqlJetFileOpenPermission> permissions = (writable ? WRITE_PREMISSIONS : READ_PERMISSIONS);
            final SqlJetFileType type = (file != null ? SqlJetFileType.MAIN_DB : SqlJetFileType.TEMP_DB);
            btree.open(file, dbHandle, flags, type, permissions);
            // force readonly.
            ISqlJetFile file = btree.getPager().getFile();
            if (file != null) {
                Set<SqlJetFileOpenPermission> realPermissions = btree.getPager().getFile().getPermissions();
                writable = realPermissions.contains(SqlJetFileOpenPermission.READWRITE);
            }
            open = true;
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

         * example, say the page-size of pTo is 2048 bytes and the original*
         * number of pages is 5 (10 KB file). If pFrom has a page size of 1024*
         * bytes and 9 pages, then the file needs to be truncated to 9KB.
         */

        ISqlJetFile pFile = pBtTo.pPager.getFile();
        long iSize = (long) nFromPageSize * (long) nFromPage;
        long iNow = (long) ((nToPage > nNewPage) ? nToPage : nNewPage) * (long) nToPageSize;
        long iPending = ((long) pBtTo.PENDING_BYTE_PAGE() - 1) * (long) nToPageSize;

        assert (iSize <= iNow);

        /*
         * Commit phase one syncs the journal file associated with pTo*
         * containing the original data. It does not sync the database file*
         * itself. After doing this it is safe to use OsTruncate() and other*
         * file APIs on the database file directly.
         */
        pBtTo.db = pTo.db;
        pBtTo.pPager.commitPhaseOne(null, true);
        if (iSize < iNow) {
            pFile.truncate(iSize);
        }

        /*
         * The loop that copied data from database pFrom to pTo did not*
         * populate the locking page of database pTo. If the page-size of* pFrom
         * is smaller than that of pTo, this means some data will* not have been
         * copied.** This block copies the missing data from database pFrom to
         * pTo* using file APIs. This is safe because at this point we know that
         * * all of the original data from pTo has been synced into the* journal
         * file. At this point it would be safe to do anything at* all to the
         * database file except truncate it to zero bytes.
         */
        if (nFromPageSize < nToPageSize && iSize > iPending) {
            long iOff;
            for (iOff = iPending; iOff < (iPending + nToPageSize); iOff += nFromPageSize) {
                ISqlJetPage pFromPage = null;
                int iFrom = (int) (iOff / nFromPageSize) + 1;

                if (iFrom == pBtFrom.PENDING_BYTE_PAGE() || iFrom > nFromPage) {
                    continue;
                }

                pFromPage = pBtFrom.pPager.getPage(iFrom);
                ISqlJetMemoryPointer zFrom = pFromPage.getData();
                pFile.write(zFrom, nFromPageSize, iOff);
                pFromPage.unref();
            }
        }

        /* Sync the database file */
 
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

     * @throws SqlJetException
     */
    private void deleteMaster(String master) throws SqlJetException {

        boolean master_open = false;
        ISqlJetFile pMaster = null;
        /* Contents of master journal file */
        ISqlJetMemoryPointer zMasterJournal = null;
        /* Size of master journal file */
        int nMasterJournal;

        try {

            /*
             * Open the master journal file exclusively in case some other
             * process is running this routine also. Not that it makes too much
             * difference.
             */
            pMaster = fileSystem.open(new File(master), SqlJetFileType.MASTER_JOURNAL, SqlJetUtility
                    .of(SqlJetFileOpenPermission.READONLY));
            master_open = true;

            nMasterJournal = Long.valueOf(pMaster.fileSize()).intValue();

            if (nMasterJournal > 0) {

                /*
                 * Load the entire master journal file into space obtained from
                 * sqlite3_malloc() and pointed to by zMasterJournal.
                 */
                zMasterJournal = SqlJetUtility.allocatePtr(nMasterJournal);
                pMaster.read(zMasterJournal, nMasterJournal, 0);

                int nMasterPtr = 0;
                while (nMasterPtr < nMasterJournal) {

                    int zMasterPtr = SqlJetUtility.strlen(zMasterJournal, nMasterPtr);
                    String zJournal = SqlJetUtility.toString(SqlJetUtility.pointer(zMasterJournal, nMasterPtr));
                    final File journalPath = new File(zJournal);
                    boolean exists = fileSystem.access(journalPath, SqlJetFileAccesPermission.EXISTS);

                    if (exists) {
                        /*
                         * One of the journals pointed to by the master journal
                         * exists. Open it and check if it points at the master
                         * journal. If so, return without deleting the master
                         * journal file.
                         */
                        final ISqlJetFile pJournal = fileSystem.open(journalPath, SqlJetFileType.MAIN_JOURNAL,
                                SqlJetUtility.of(SqlJetFileOpenPermission.READONLY));
                        try {
                            final String readJournal = readMasterJournal(pJournal);
                            if (readJournal != null && readJournal.equals(master)) {
                                /*
                                 * We have a match. Do not delete the master
                                 * journal file.
                                 */
                                return;
                            }
                        } finally {
                            pJournal.close();
                        }
                    }
                    nMasterPtr += zMasterPtr + 1;
                }
            }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

        ISqlJetPage pPg; /* An existing page in the cache */
        int pgno; /* The page number of a page in journal */
        long cksum; /* Checksum used for sanity checking */
        ISqlJetMemoryPointer aData; /* Temporary storage for the page */
        ISqlJetFile jfd; /* The file descriptor for the journal file */

        assert (isMainJrnl || pDone != null); /*
                                               * pDone always used on
                                               * sub-journals
                                               */
        assert (isSavepnt || pDone == null); /*
                                              * pDone never used on
                                              * non-savepoint
                                              */

        aData = tmpSpace;
        assert (aData != null); /* Temp storage must have already been allocated */

        jfd = (isMainJrnl ? this.jfd : this.sjfd);

        pgno = read32bits(jfd, pOffset);
        jfd.read(aData, pageSize, pOffset + 4);
        pOffset += pageSize + 4 + (isMainJrnl ? 4 : 0);

        /*
         * Sanity checking on the page. This is more important that I originally
         * thought. If a power failure occurs while the journal is being
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

        Assert.fail("File shouldn't be opened without permissions");
    }
   
    @Test
    public void testOpenFileNullTemporary() throws Exception {
        final ISqlJetFile f = fileSystem.open(null, SqlJetFileType.TEMP_DB, PERM_TEMPORARY);
        f.close();
        Assert.assertNotNull("File should be opened without path if permissions include values:"
                + " CREATE, READWRITE, DELETEONCLOSE", f);
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

                + " CREATE, READWRITE, DELETEONCLOSE", f);
    }

    @Test(expected = AssertionError.class )
    public void testOpenFileNullReadonly() throws Exception {
        final ISqlJetFile f = fileSystem.open(null, SqlJetFileType.TEMP_DB, PERM_READONLY);
        f.close();
        Assert.fail("File shouldn't be opened without path if permission is READONLY");
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

    @Test
    public void testOpenReadonly() throws Exception {
        Assert.assertNotNull(path);
        Assert.assertTrue(path.exists());
        final ISqlJetFile f = fileSystem.open(path, SqlJetFileType.MAIN_DB, PERM_READONLY);
        f.close();
        Assert.assertNotNull("File which exists should be opened with permission READONLY", f);
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

    @Test(expected = SqlJetException.class)
    public void testOpenNewReadonly() throws Exception {
        Assert.assertNotNull(pathNew);
        Assert.assertFalse(pathNew.exists());
        final ISqlJetFile f = fileSystem.open(pathNew, SqlJetFileType.MAIN_DB, PERM_READONLY);
        f.close();
        Assert.fail("File which doesn't exists shouldn't be opened with permission READONLY");
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

    }
   
    @Test(expected = AssertionError.class)
    public void testOpenReadonlyAndWrite() throws Exception {
        Assert.assertNotNull(path);
        final ISqlJetFile f = fileSystem.open(path, SqlJetFileType.MAIN_DB, PERM_READONLY_AND_WRITE);
        f.close();
        Assert.fail("File shouldn't be opened with permissions READONLY and READWRITE");
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.internal.ISqlJetFile

        Assert.fail("File shouldn't be opened with permissions READONLY and READWRITE");
    }

    @Test(expected = AssertionError.class)
    public void testOpenNullReadonlyAndWrite() throws Exception {
        final ISqlJetFile f = fileSystem.open(null, SqlJetFileType.TEMP_DB, PERM_READONLY_AND_WRITE);
        f.close();
        Assert.fail("File shouldn't be opened with permissions READONLY and READWRITE");
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.