Search in sources :

Example 1 with DBException

use of org.exist.storage.btree.DBException in project exist by eXist-db.

the class NativeStructuralIndex method open.

@Override
public void open() throws DatabaseConfigurationException {
    final Path file = getDataDir().resolve(FILE_NAME);
    LOG.debug("Creating '{}'...", FileUtils.fileName(file));
    try {
        btree = new BTreeStore(pool, STRUCTURAL_INDEX_ID, FILE_FORMAT_VERSION_ID, false, file, pool.getCacheManager());
    } catch (final DBException e) {
        LOG.error("Failed to initialize structural index: {}", e.getMessage(), e);
        throw new DatabaseConfigurationException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) BTreeStore(org.exist.storage.index.BTreeStore) DBException(org.exist.storage.btree.DBException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException)

Example 2 with DBException

use of org.exist.storage.btree.DBException in project exist by eXist-db.

the class RangeIndexWorker method removeCollection.

@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) throws PermissionDeniedException {
    if (LOG.isDebugEnabled())
        LOG.debug("Removing collection {}", collection.getURI());
    IndexWriter writer = null;
    try {
        writer = index.getWriter();
        for (Iterator<DocumentImpl> i = collection.iterator(broker); i.hasNext(); ) {
            DocumentImpl doc = i.next();
            final BytesRefBuilder bytes = new BytesRefBuilder();
            NumericUtils.intToPrefixCoded(doc.getDocId(), 0, bytes);
            Term dt = new Term(FIELD_DOC_ID, bytes.toBytesRef());
            writer.deleteDocuments(dt);
        }
    } catch (IOException | PermissionDeniedException | LockException e) {
        LOG.error("Error while removing lucene index: {}", e.getMessage(), e);
    } finally {
        index.releaseWriter(writer);
        if (reindex) {
            try {
                index.sync();
            } catch (DBException e) {
                LOG.warn("Exception during reindex: {}", e.getMessage(), e);
            }
        }
        mode = ReindexMode.STORE;
    }
    if (LOG.isDebugEnabled())
        LOG.debug("Collection removed.");
}
Also used : DBException(org.exist.storage.btree.DBException) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) LockException(org.exist.util.LockException) PermissionDeniedException(org.exist.security.PermissionDeniedException) IOException(java.io.IOException) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

Example 3 with DBException

use of org.exist.storage.btree.DBException in project exist by eXist-db.

the class SortIndex method open.

@Override
public void open() throws DatabaseConfigurationException {
    final Path file = getDataDir().resolve(FILE_NAME);
    LOG.debug("Creating '{}'...", FileUtils.fileName(file));
    try {
        btree = new BTreeStore(pool, SORT_INDEX_ID, FILE_FORMAT_VERSION_ID, false, file, pool.getCacheManager());
    } catch (final DBException e) {
        LOG.error("Failed to initialize structural index: {}", e.getMessage(), e);
        throw new DatabaseConfigurationException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) BTreeStore(org.exist.storage.index.BTreeStore) DBException(org.exist.storage.btree.DBException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException)

Example 4 with DBException

use of org.exist.storage.btree.DBException in project exist by eXist-db.

the class GMLHSQLIndex method removeIndexContent.

@Override
protected void removeIndexContent() throws DBException {
    try {
        // deleteDatabase() should be far more efficient ;-)
        if (conn != null) {
            Statement stmt = conn.createStatement();
            int nodeCount = stmt.executeUpdate("DELETE FROM " + GMLHSQLIndex.TABLE_NAME + ";");
            stmt.close();
            if (LOG.isDebugEnabled())
                LOG.debug("GML index: {}/{}. {} nodes removed", getDataDir(), db_file_name_prefix, nodeCount);
        }
    } catch (SQLException e) {
        throw new DBException(e.getMessage());
    }
}
Also used : DBException(org.exist.storage.btree.DBException) SQLException(java.sql.SQLException) Statement(java.sql.Statement)

Example 5 with DBException

use of org.exist.storage.btree.DBException in project exist by eXist-db.

the class GMLHSQLIndex method deleteDatabase.

@Override
protected void deleteDatabase() throws DBException {
    final Path directory = getDataDir();
    try {
        final List<Path> files = FileUtils.list(directory, path -> FileUtils.fileName(path).startsWith(db_file_name_prefix));
        boolean deleted = true;
        for (final Path file : files) {
            deleted &= FileUtils.deleteQuietly(file);
        }
    } catch (final IOException e) {
        LOG.error(e);
        throw new DBException(e.getMessage());
    }
// TODO : raise an error if deleted == false ?
}
Also used : Path(java.nio.file.Path) DBException(org.exist.storage.btree.DBException) IOException(java.io.IOException)

Aggregations

DBException (org.exist.storage.btree.DBException)9 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)3 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)2 PermissionDeniedException (org.exist.security.PermissionDeniedException)2 BTreeStore (org.exist.storage.index.BTreeStore)2 LockException (org.exist.util.LockException)2 DocumentImpl (org.exist.dom.persistent.DocumentImpl)1 FileUtils (org.exist.util.FileUtils)1 XPathException (org.exist.xquery.XPathException)1