2022-07-23 02:42:48 +02:00
|
|
|
package it.cavallium.dbengine.lucene;
|
|
|
|
|
|
|
|
import static it.cavallium.dbengine.lucene.LuceneUtils.warnLuceneThread;
|
|
|
|
|
2023-02-22 16:59:35 +01:00
|
|
|
import it.cavallium.dbengine.utils.DBException;
|
2022-07-23 02:42:48 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Set;
|
|
|
|
import org.apache.lucene.store.Directory;
|
|
|
|
import org.apache.lucene.store.IOContext;
|
|
|
|
import org.apache.lucene.store.IndexInput;
|
|
|
|
import org.apache.lucene.store.IndexOutput;
|
|
|
|
import org.apache.lucene.store.Lock;
|
|
|
|
|
|
|
|
public class CheckOutputDirectory extends Directory {
|
|
|
|
|
|
|
|
private final Directory directory;
|
|
|
|
|
|
|
|
public CheckOutputDirectory(Directory directory) {
|
|
|
|
this.directory = directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public String[] listAll() {
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return directory.listAll();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void deleteFile(String name) {
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
directory.deleteFile(name);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public long fileLength(String name) {
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return directory.fileLength(name);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public IndexOutput createOutput(String name, IOContext context) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return new CheckIndexOutput(directory.createOutput(name, context));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public IndexOutput createTempOutput(String prefix, String suffix, IOContext context) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return new CheckIndexOutput(directory.createTempOutput(prefix, suffix, context));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void sync(Collection<String> names) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
directory.sync(names);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void syncMetaData() {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
directory.syncMetaData();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void rename(String source, String dest) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
directory.rename(source, dest);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public IndexInput openInput(String name, IOContext context) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return new CheckIndexInput(directory.openInput(name, context));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public Lock obtainLock(String name) {
|
2023-02-22 22:31:36 +01:00
|
|
|
LuceneUtils.warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return directory.obtainLock(name);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public void close() {
|
2022-07-23 02:42:48 +02:00
|
|
|
warnLuceneThread();
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
directory.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-02-09 23:34:25 +01:00
|
|
|
public Set<String> getPendingDeletions() {
|
2023-02-22 16:59:35 +01:00
|
|
|
try {
|
|
|
|
return directory.getPendingDeletions();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new DBException(e);
|
|
|
|
}
|
2022-07-23 02:42:48 +02:00
|
|
|
}
|
|
|
|
}
|