|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.lucene.store.Directory
org.apache.lucene.store.jdbc.JdbcDirectory
public class JdbcDirectory
A Jdbc based implementation of a Lucene Directory
allowing the storage of a Lucene index
within a database. Uses a jdbc DataSource
, Dialect
specific for the database used,
and an optional JdbcDirectorySettings
and JdbcTable
for configuration.
Blob
. Each "file"
has an entry in the database, and different FileEntryHandler
can be defines for different files (or
files groups).
Most of the files will not be deleted from the database when the directory delete method is called, but will
only be marked to be deleted (see MarkDeleteFileEntryHandler
. It is
done since other readers or searchers might be working with the database, and still use the files. The ability to
purge mark deleted files based on a "delta" is acheived using deleteMarkDeleted()
and
deleteMarkDeleted(long)
. Note, the purging process is not called by the directory code, so it will have
to be managed by the application using the jdbc directory.
For transaction management, all the operations performed against the database do not call commit
or
rollback
. They simply open a connection (using
DataSourceUtils.getConnection(javax.sql.DataSource)
), and close it
using DataSourceUtils.releaseConnection(java.sql.Connection)
). This
results in the fact that transcation management is simple and wraps the directory operations, allowing it to span
as many operations as needed.
For none managed applications (i.e. applications that do not use JTA or Spring transaction manager), the jdbc directory
implementation comes with TransactionAwareDataSourceProxy
which wraps
a DataSource
(should be a pooled one, like Jakartat DBCP). Using it with the
DataSourceUtils
, or the provided DirectoryTemplate
should make
integrating or using jdbc directory simple.
Also, for none managed applications, there is an option working with autoCommit=true mode. The system will work much
slower, and it is only supported on a portion of the databases, but any existing code that uses Lucene with any
other Directory
implemenation should work as is.
If working within managed environments, an external transaction management should be performed (using JTA for example).
Simple solutions can be using CMT or Spring Framework abstraction of transaction managers. Currently, the jdbc directory
implementation does not implement a transaction management abstraction, since there is a very good solution out there
already (Spring and JTA). Note, when using Spring and the DataSourceTransactionManager
, to provide the jdbc directory
with a Spring's TransactionAwareDataSourceProxy
.
Field Summary |
---|
Fields inherited from class org.apache.lucene.store.Directory |
---|
lockFactory |
Constructor Summary | |
---|---|
JdbcDirectory(DataSource dataSource,
Dialect dialect,
JdbcDirectorySettings settings,
String tableName)
Creates a new jdbc directory. |
|
JdbcDirectory(DataSource dataSource,
Dialect dialect,
String tableName)
Creates a new jdbc directory. |
|
JdbcDirectory(DataSource dataSource,
JdbcDirectorySettings settings,
String tableName)
Creates a new jdbc directory. |
|
JdbcDirectory(DataSource dataSource,
JdbcTable table)
Creates a new jdbc directory. |
|
JdbcDirectory(DataSource dataSource,
String tableName)
Creates a new jdbc directory. |
Method Summary | |
---|---|
void |
close()
Closes the directory. |
void |
create()
Creates a new database table. |
protected Lock |
createLock()
|
IndexOutput |
createOutput(String name)
|
void |
delete()
Deletes the database table (drops it) from the database. |
void |
deleteContent()
Deletes the contents of the database, except for the commit and write lock. |
void |
deleteFile(String name)
|
List |
deleteFiles(List names)
Deletes the given file names. |
void |
deleteMarkDeleted()
Delets all the file entries that are marked to be deleted, and they were marked "delta" time ago (base on database time, if possible by dialect). |
void |
deleteMarkDeleted(long delta)
Delets all the file entries that are marked to be deleted, and they were marked "delta" time ago (base on database time, if possible by dialect). |
boolean |
fileExists(String name)
|
long |
fileLength(String name)
|
long |
fileModified(String name)
|
void |
forceDeleteFile(String name)
|
DataSource |
getDataSource()
|
Dialect |
getDialect()
|
protected FileEntryHandler |
getFileEntryHandler(String name)
|
JdbcTemplate |
getJdbcTemplate()
|
JdbcDirectorySettings |
getSettings()
|
JdbcTable |
getTable()
|
String[] |
list()
|
Lock |
makeLock(String name)
|
IndexInput |
openInput(String name)
|
void |
renameFile(String from,
String to)
|
boolean |
tableExists()
Returns true if the database table exists. |
void |
touchFile(String name)
|
Methods inherited from class org.apache.lucene.store.Directory |
---|
clearLock, copy, ensureOpen, getLockFactory, getLockID, openInput, setLockFactory, sync |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JdbcDirectory(DataSource dataSource, String tableName) throws JdbcStoreException
JdbcDirectorySettings
using it's default values.
Uses DialectResolver
to try and automatically reolve the Dialect
.
dataSource
- The data source to usetableName
- The table name
JdbcStoreException
public JdbcDirectory(DataSource dataSource, Dialect dialect, String tableName)
JdbcDirectorySettings
using it's default values.
dataSource
- The data source to usedialect
- The dialecttableName
- The table namepublic JdbcDirectory(DataSource dataSource, JdbcDirectorySettings settings, String tableName) throws JdbcStoreException
DialectResolver
to try and automatically reolve the Dialect
.
dataSource
- The data source to usesettings
- The settings to configure the directorytableName
- The table name that will be used
JdbcStoreException
public JdbcDirectory(DataSource dataSource, Dialect dialect, JdbcDirectorySettings settings, String tableName)
dataSource
- The data source to usedialect
- The dialectsettings
- The settings to configure the directorytableName
- The table name that will be usedpublic JdbcDirectory(DataSource dataSource, JdbcTable table)
dataSource
- The data source to usetable
- The Jdbc table definitionsMethod Detail |
---|
public boolean tableExists() throws IOException, UnsupportedOperationException
true
if the database table exists.
true
if the database table exists, false
otherwise
IOException
UnsupportedOperationException
- If the database dialect does not support itpublic void delete() throws IOException
IOException
public void create() throws IOException
IOException
public void deleteContent() throws IOException
IOException
public void deleteMarkDeleted() throws IOException
JdbcDirectorySettings.getDeleteMarkDeletedDelta()
.
IOException
public void deleteMarkDeleted(long delta) throws IOException
IOException
public String[] list() throws IOException
list
in class Directory
IOException
public boolean fileExists(String name) throws IOException
fileExists
in class Directory
IOException
public long fileModified(String name) throws IOException
fileModified
in class Directory
IOException
public void touchFile(String name) throws IOException
touchFile
in class Directory
IOException
public void deleteFile(String name) throws IOException
deleteFile
in class Directory
IOException
public void forceDeleteFile(String name) throws IOException
IOException
public List deleteFiles(List names) throws IOException
MultiDeleteDirectory
deleteFiles
in interface MultiDeleteDirectory
IOException
public void renameFile(String from, String to) throws IOException
renameFile
in class Directory
IOException
public long fileLength(String name) throws IOException
fileLength
in class Directory
IOException
public IndexInput openInput(String name) throws IOException
openInput
in class Directory
IOException
public IndexOutput createOutput(String name) throws IOException
createOutput
in class Directory
IOException
public Lock makeLock(String name)
makeLock
in class Directory
public void close() throws IOException
close
in class Directory
IOException
protected FileEntryHandler getFileEntryHandler(String name)
protected Lock createLock() throws IOException
IOException
public Dialect getDialect()
public JdbcTemplate getJdbcTemplate()
public JdbcTable getTable()
public JdbcDirectorySettings getSettings()
public DataSource getDataSource()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |