use of org.geotoolkit.index.tree.StoreIndexException in project geotoolkit by Geomatys.
the class AbstractIndexer method removeDocument.
/**
* This method remove index of lucene a document identified by identifier.
*/
public void removeDocument(final String identifier) {
try {
final Directory dir = LuceneUtils.getAppropriateDirectory(getFileDirectory());
final Term t = new Term("id", identifier);
final TermQuery query = new TermQuery(t);
LOGGER.log(Level.FINER, "Term query:{0}", query);
// look for DOC ID for R-Tree removal
final NamedEnvelope env = new NamedEnvelope(getTreeCrs(), identifier);
final TreeElementMapper<NamedEnvelope> mapper = rTree.getTreeElementMapper();
final int treeID = mapper.getTreeIdentifier(env);
if (treeID != -1) {
final NamedEnvelope realEnv = mapper.getObjectFromTreeIdentifier(treeID);
boolean removed = rTree.remove(realEnv);
if (!removed) {
LOGGER.log(Level.WARNING, "unable to remove envelope for:{0}", identifier);
} else {
// remove from mapper
mapper.setTreeIdentifier(null, treeID);
mapper.flush();
rTree.flush();
}
}
final IndexWriterConfig config = new IndexWriterConfig(analyzer);
try (final IndexWriter writer = new IndexWriter(dir, config)) {
writer.deleteDocuments(query);
LOGGER.log(Level.FINER, "Metadata: {0} removed from the index", identifier);
writer.commit();
}
} catch (CorruptIndexException ex) {
LOGGER.log(Level.WARNING, "CorruptIndexException while indexing document: " + ex.getMessage(), ex);
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "IOException while indexing document: " + ex.getMessage(), ex);
} catch (StoreIndexException ex) {
LOGGER.log(Level.WARNING, "StoreIndexException while indexing document: " + ex.getMessage(), ex);
}
}
use of org.geotoolkit.index.tree.StoreIndexException in project geotoolkit by Geomatys.
the class SQLRtreeManager method buildNewTree.
private static Tree buildNewTree(final Path directory) {
if (Files.exists(directory)) {
TreeElementMapper treeMapper = null;
try {
// creating tree (R-Tree)------------------------------------------------
final Path treeFile = directory.resolve("tree.bin");
Files.createFile(treeFile);
// postgres
if (PGDataSource.isSetPGDataSource()) {
if (PGDataSource.isPostgres) {
treeMapper = LucenePostgresSQLTreeEltMapper.createTreeEltMapperWithDB(directory);
return new PGTreeWrapper(directory, PGDataSource.getDataSource(), treeMapper, DEFAULT_CRS);
} else {
treeMapper = LuceneHSQLTreeEltMapper.createTreeEltMapperWithDB(directory);
return new PGTreeWrapper(directory, PGDataSource.getDataSource(), treeMapper, DEFAULT_CRS);
}
} else {
treeMapper = LuceneDerbySQLTreeEltMapper.createTreeEltMapperWithDB(directory);
return new FileStarRTree(treeFile.toFile().toPath(), 5, DEFAULT_CRS, treeMapper);
}
} catch (SQLException | IOException | StoreIndexException ex) {
if (treeMapper != null) {
try {
treeMapper.close();
} catch (Exception bis) {
ex.addSuppressed(bis);
}
}
LOGGER.log(Level.WARNING, "Unable to create RTree", ex);
}
}
return null;
}
use of org.geotoolkit.index.tree.StoreIndexException in project geotoolkit by Geomatys.
the class PGTreeWrapper method updateTree.
private void updateTree() throws StoreIndexException {
try {
if ((System.currentTimeMillis() - lastUpdate) > (5 * 60 * 1000)) {
byte[] data = TreeAccessSQLByteArray.getData(directory, source);
TreeAccess ta = new TreeAccessSQLByteArray(directory, source, data, TreeUtilities.STAR_NUMBER, TreeUtilities.VERSION_NUMBER);
rTree = new StarRTree<>(ta, mapper);
lastUpdate = System.currentTimeMillis();
LOGGER.info("The R-tree has been updated");
}
} catch (SQLException | IOException | ClassNotFoundException | NoSuchAlgorithmException ex) {
throw new StoreIndexException(ex);
}
}
use of org.geotoolkit.index.tree.StoreIndexException in project geotoolkit by Geomatys.
the class StarRTree method insert.
/**
* {@inheritDoc }.
*/
@Override
public void insert(int identifier, double... coordinates) throws IllegalArgumentException, StoreIndexException {
try {
eltCompteur++;
Node root = getRoot();
if (root == null || root.isEmpty()) {
root = createNode(null, IS_LEAF, 0, 0, 0);
root.addChild(createNode(coordinates, IS_DATA, 1, 0, -identifier));
setRoot(root);
} else {
travelUpBeforeInsertAgain = false;
final Node newRoot = nodeInsert(root, identifier, coordinates);
if (newRoot != null) {
setRoot(newRoot);
treeAccess.writeNode((Node) newRoot);
}
/**
* Insert again. Property named Tree re-balancing.
*/
if (travelUpBeforeInsertAgain) {
travelUpBeforeInsertAgain = false;
// insert again
final int siz = listCoords.size();
assert (siz == listIdentifier.size()) : "getElementAtMore33Percent : nodeInsert : lists should have same size.";
setIA(false);
final int nbrElt = getElementsNumber();
// gere quand root == null
final int treeIdent = treeIdentifier;
for (int i = 0; i < siz; i++) {
if (!remove(listIdentifier.get(i), listCoords.get(i))) {
throw new AssertionError("remove data should succeed during re-inserting event. " + "data identifier : " + listIdentifier.get(i) + " data boundary : " + Arrays.toString(listCoords.get(i)));
}
}
for (int i = 0; i < siz; i++) {
insert(listIdentifier.get(i), listCoords.get(i));
}
setIA(true);
assert nbrElt == getElementsNumber() : "During Insert again element number within tree should not change.";
treeIdentifier = treeIdent;
}
}
} catch (IOException ex) {
throw new StoreIndexException(this.getClass().getName() + "Tree.insert(), impossible to add element.", ex);
}
}
use of org.geotoolkit.index.tree.StoreIndexException in project geotoolkit by Geomatys.
the class FileRtreeManager method get.
public static Tree<NamedEnvelope> get(final Path directory, final Object owner) {
Tree<NamedEnvelope> tree = CACHED_TREES.get(directory);
if (tree == null || tree.isClosed()) {
final Path treeFile = directory.resolve("tree.bin");
final Path mapperFile = directory.resolve("mapper.bin");
if (Files.exists(treeFile)) {
try {
// ecrire crs dans constructeur
tree = new FileStarRTree<>(treeFile.toFile().toPath(), new LuceneFileTreeEltMapper(mapperFile.toFile(), DEFAULT_CRS));
} catch (ClassNotFoundException | IllegalArgumentException | StoreIndexException | IOException ex) {
LOGGER.log(Level.SEVERE, null, ex);
}
} else {
tree = buildNewTree(directory);
}
final List<Object> owners = new ArrayList<>();
owners.add(owner);
TREE_OWNERS.put(directory, owners);
CACHED_TREES.put(directory, tree);
} else {
// look if the owner is already registred
final List<Object> owners = TREE_OWNERS.get(directory);
if (!owners.contains(owner)) {
owners.add(owner);
}
}
return tree;
}
Aggregations