Examples of SqlJetException


Examples of org.tmatesoft.sqljet.core.SqlJetException

        checkOpen();
        runWithLock(new ISqlJetRunnableWithLock() {
            public Object runWithLock(SqlJetDb db) throws SqlJetException {
                refreshSchema();
                if (transaction) {
                    throw new SqlJetException(SqlJetErrorCode.MISUSE, TRANSACTION_ALREADY_STARTED);
                } else {
                    btree.beginTrans(mode);
                    transaction = true;
                    transactionMode = mode;
                    return null;
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

                    btree.closeAllCursors();
                    btree.commit();
                    transaction = false;
                    transactionMode = null;
                } else {
                    throw new SqlJetException(SqlJetErrorCode.MISUSE, "Transaction wasn't started");
                }
                return null;
            }
        });
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

            releaseLockInfo();

            try {
                file.close();
            } catch (IOException e) {
                throw new SqlJetException(SqlJetErrorCode.IOERR, e);
            } finally {
                file = null;
            }

        }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

    public synchronized long fileSize() throws SqlJetException {
        assert (file != null);
        try {
            return file.getChannel().size();
        } catch (IOException e) {
            throw new SqlJetException(SqlJetErrorCode.IOERR, e);
        }
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

     */
    public ISqlJetFile open(final File path, final SqlJetFileType type, final Set<SqlJetFileOpenPermission> permissions)
            throws SqlJetException {

        if (null == type)
            throw new SqlJetException(SqlJetErrorCode.BAD_PARAMETER, "File type must not be null to open file");

        if (null == permissions || permissions.isEmpty())
            throw new SqlJetException(SqlJetErrorCode.BAD_PARAMETER,
                    "Permissions must not be null or empty to open file");

        boolean isExclusive = permissions.contains(SqlJetFileOpenPermission.EXCLUSIVE);
        boolean isDelete = permissions.contains(SqlJetFileOpenPermission.DELETEONCLOSE);
        boolean isCreate = permissions.contains(SqlJetFileOpenPermission.CREATE);
        boolean isReadonly = permissions.contains(SqlJetFileOpenPermission.READONLY);
        boolean isReadWrite = permissions.contains(SqlJetFileOpenPermission.READWRITE);

        /*
         * Check the following statements are true:
         *
         * (a) Exactly one of the READWRITE and READONLY flags must be set, and
         * (b) if CREATE is set, then READWRITE must also be set, and (c) if
         * EXCLUSIVE is set, then CREATE must also be set. (d) if DELETEONCLOSE
         * is set, then CREATE must also be set.
         */
        assert ((!isReadonly || !isReadWrite) && (isReadWrite || isReadonly));
        assert (!isCreate || isReadWrite);
        assert (!isExclusive || isCreate);
        assert (!isDelete || isCreate);

        /*
         * The main DB, main journal, and master journal are never automatically
         * deleted
         */

        assert (SqlJetFileType.MAIN_DB != type || !isDelete);
        assert (SqlJetFileType.MAIN_JOURNAL != type || !isDelete);
        assert (SqlJetFileType.MASTER_JOURNAL != type || !isDelete);

        final File filePath;

        if (null != path) {
            try {
                filePath = path.getCanonicalFile();
            } catch (IOException e) {
                // TODO may through exception for missing file.
                throw new SqlJetException(SqlJetErrorCode.CANTOPEN, e);
            }
        } else {

            assert (isDelete && !(isCreate && (SqlJetFileType.MASTER_JOURNAL == type || SqlJetFileType.MAIN_JOURNAL == type)));
            try {
                filePath = getTempFile();
            } catch (IOException e) {
                throw new SqlJetException(SqlJetErrorCode.CANTOPEN, e);
            }

            assert (null != filePath);
        }

        if (!isReadWrite && !(filePath.isFile() && filePath.canRead())) {
            throw new SqlJetException(SqlJetErrorCode.CANTOPEN);
        }

        String mode = "rw";
        if (isReadonly && !isReadWrite && !isCreate && !isExclusive) {
            mode = "r";
        } else if (isReadWrite && !isExclusive && filePath.isFile() && !filePath.canWrite() && filePath.canRead()) {
            // force opening as read only.
            Set<SqlJetFileOpenPermission> ro = EnumSet.copyOf(permissions);
            ro.remove(SqlJetFileOpenPermission.READWRITE);
            ro.remove(SqlJetFileOpenPermission.CREATE);
            ro.add(SqlJetFileOpenPermission.READONLY);

            return open(filePath, type, ro);
        }

        RandomAccessFile file = null;
        try {
            file = SqlJetFileUtil.openFile(filePath, mode);
        } catch (FileNotFoundException e) {

            if (isReadWrite && !isExclusive) {
                /* Failed to open the file for read/write access. Try read-only. */
                Set<SqlJetFileOpenPermission> ro = EnumSet.copyOf(permissions);
                ro.remove(SqlJetFileOpenPermission.READWRITE);
                ro.remove(SqlJetFileOpenPermission.CREATE);
                ro.add(SqlJetFileOpenPermission.READONLY);
                return open(filePath, type, ro);
            }

            throw new SqlJetException(SqlJetErrorCode.CANTOPEN);
        }

        boolean noLock = SqlJetFileType.MAIN_DB != type;

        return new SqlJetFile(this, file, filePath, type, permissions, noLock);
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

        case READWRITE:
            return path.canRead() && path.canWrite();

        default:
            throw new SqlJetException(SqlJetErrorCode.INTERNAL, "Unhandled SqlJetFileAccesPermission value :"
                    + permission.name());
        }

    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

                // System.err.println(sql);
                final CommonTree ast = (CommonTree) parseTable(sql).getTree();
                if (!isCreateVirtualTable(ast)) {
                    final SqlJetTableDef tableDef = new SqlJetTableDef(ast, page);
                    if (!name.equals(tableDef.getName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    tableDef.setRowId(table.getRowId());
                    tableDefs.put(name, tableDef);
                } else {
                    final SqlJetVirtualTableDef virtualTableDef = new SqlJetVirtualTableDef(ast, page);
                    if (!name.equals(virtualTableDef.getTableName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    virtualTableDef.setRowId(table.getRowId());
                    virtualTableDefs.put(name, virtualTableDef);
                }
            } else if (INDEX_TYPE.equals(type)) {
                final String tableName = table.getTableField();
                final String sql = table.getSqlField();
                if (null != sql) {
                    // System.err.println(sql);
                    final CommonTree ast = (CommonTree) parseIndex(sql).getTree();
                    final SqlJetIndexDef indexDef = new SqlJetIndexDef(ast, page);
                    if (!name.equals(indexDef.getName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    if (!tableName.equals(indexDef.getTableName())) {
                        throw new SqlJetException(SqlJetErrorCode.CORRUPT);
                    }
                    indexDef.setRowId(table.getRowId());
                    indexDefs.put(name, indexDef);
                } else {
                    SqlJetBaseIndexDef indexDef = new SqlJetBaseIndexDef(name, tableName, page);
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

            SqlLexer lexer = new SqlLexer(chars);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SqlParser parser = new SqlParser(tokens);
            return parser.schema_create_table_stmt();
        } catch (RecognitionException re) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Invalid sql statement: " + sql);
        }
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

            SqlLexer lexer = new SqlLexer(chars);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SqlParser parser = new SqlParser(tokens);
            return parser.create_view_stmt();
        } catch (RecognitionException re) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Invalid sql statement: " + sql);
        }
    }
View Full Code Here

Examples of org.tmatesoft.sqljet.core.SqlJetException

            SqlLexer lexer = new SqlLexer(chars);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            SqlParser parser = new SqlParser(tokens);
            return parser.create_trigger_stmt();
        } catch (RecognitionException re) {
            throw new SqlJetException(SqlJetErrorCode.ERROR, "Invalid sql statement: " + sql);
        }
    }
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.