Search in sources :

Example 6 with DBException

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

the class GMLHSQLIndex method shutdownDatabase.

@Override
protected void shutdownDatabase() throws DBException {
    try {
        // No need to shutdown if we have opened something
        if (conn != null) {
            Statement stmt = conn.createStatement();
            stmt.executeQuery("SHUTDOWN");
            stmt.close();
            conn.close();
            if (LOG.isDebugEnabled())
                LOG.debug("GML index: {}/{} closed", getDataDir(), db_file_name_prefix);
        }
    } catch (SQLException e) {
        throw new DBException(e.getMessage());
    } finally {
        conn = null;
    }
}
Also used : DBException(org.exist.storage.btree.DBException) SQLException(java.sql.SQLException) Statement(java.sql.Statement)

Example 7 with DBException

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

the class LuceneIndexWorker method removeCollection.

@Override
public void removeCollection(Collection collection, DBBroker broker, boolean reindex) {
    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)

Example 8 with DBException

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

the class LuceneIndex method remove.

@Override
public void remove() throws DBException {
    close();
    Path dir = getDataDir().resolve(getDirName());
    try (Stream<Path> stream = Files.list(dir)) {
        stream.forEach(FileUtils::deleteQuietly);
    } catch (Exception e) {
        // never abort at this point, so recovery can continue
        LOG.warn(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) FileUtils(org.exist.util.FileUtils) DBException(org.exist.storage.btree.DBException) IOException(java.io.IOException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) XPathException(org.exist.xquery.XPathException)

Example 9 with DBException

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

the class LuceneIndex method close.

@Override
public synchronized void close() throws DBException {
    try {
        if (searcherManager != null) {
            searcherManager.close();
            searcherManager = null;
        }
        if (readerManager != null) {
            readerManager.close();
            readerManager = null;
        }
        if (cachedWriter != null) {
            commit();
            cachedTaxonomyWriter.close();
            cachedWriter.close();
            cachedTaxonomyWriter = null;
            cachedWriter = null;
        }
        taxoDirectory.close();
        directory.close();
    } catch (IOException e) {
        throw new DBException("Caught exception while closing lucene indexes: " + e.getMessage());
    }
}
Also used : 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