|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fr.gouv.culture.sdx.utils.AbstractSdxObject fr.gouv.culture.sdx.utils.lucene.LuceneDataStore fr.gouv.culture.sdx.utils.database.LuceneDatabase
public class LuceneDatabase
An implementation of database operations using Lucene.
For a detailed description of the database abstraction in SDX, please see the Database interface.
When creating a LuceneDatabase object, these steps should be followed :
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface fr.gouv.culture.sdx.utils.SdxObject |
---|
SdxObject.ConfigurationNode |
Field Summary | |
---|---|
protected java.lang.String |
DATABASE_DIR_NAME
|
protected java.lang.String |
id
|
Fields inherited from class fr.gouv.culture.sdx.utils.lucene.LuceneDataStore |
---|
ALL_FIELD, ALL_VALUE, analyzer, fsd, fsdFile, ID_FIELD, searcher, useCompoundFiles, XML_LANG_FIELD |
Fields inherited from class fr.gouv.culture.sdx.utils.AbstractSdxObject |
---|
_configuration, _context, _description, _encoding, _id, _locale, _logger, _manager, _xmlizable_objects, _xmlLang, isToSaxInitialized |
Fields inherited from interface fr.gouv.culture.sdx.utils.database.Database |
---|
CLASS_NAME_SUFFIX, DATABASE_DIR_PATH, PACKAGE_QUALNAME, SEARCH_MODE_AND, SEARCH_MODE_NOT, SEARCH_MODE_OR |
Fields inherited from interface fr.gouv.culture.sdx.utils.Encodable |
---|
DEFAULT_ENCODING |
Fields inherited from interface fr.gouv.culture.sdx.utils.save.Saveable |
---|
ALL_SAVE_ATTRIB, PATH_ATTRIB, SAVE_DIRECTORY_PARAM |
Constructor Summary | |
---|---|
LuceneDatabase()
|
|
LuceneDatabase(java.io.File dir)
Gets or creates a _database stored at a given dir. |
Method Summary | |
---|---|
void |
addProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
If the entity does not exist the method fails silently |
void |
backup(SaveParameters save_config)
Save Lucene files |
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration)
|
void |
delete(DatabaseEntity ent)
Deletes an entity from the database. |
void |
delete(DatabaseEntity[] entities)
|
void |
empty()
Empties the _database. |
boolean |
entityExists(java.lang.String id)
Checks whether an entity with the provided id exists within this database |
protected java.lang.String |
getClassNameSuffix()
Sub classes should element this method to return their class name suffix for SAX output |
DatabaseConnection |
getConnection()
|
java.lang.String |
getDatabaseDirectoryName()
If the database is a directory based file system implemenation like lucene this method should return a valid name for a directory which may be created to house the database, or in the case of hsql it will return a valid table name |
DatabaseEntity[] |
getEntities()
Returns the list of entities within the database. |
protected DatabaseEntity |
getEntity(org.apache.lucene.document.Document ldoc)
Builds an entity from a Lucene document. |
DatabaseEntity |
getEntity(java.lang.String id)
Returns an entity for a given id. |
java.lang.String |
getIndexPath()
Return's the absolute path for the directory in which the database resides |
Property[] |
getProperties(java.lang.String entityId)
Returns all properties from an entity in the database. |
java.lang.String |
getProperty(java.lang.String documentId,
java.lang.String property)
Searches database for a given document id, and then returns the content of the specified field. |
java.lang.String |
getPropertyValue(java.lang.String entityId,
java.lang.String name)
Returns a property value from an entity in the database. |
java.lang.String[] |
getPropertyValues(java.lang.String entityId,
java.lang.String propertyName)
Returns a repeatable property from an entity in the database. |
java.lang.String |
getWildcardSearchToken()
Returns a String representing the appropriate wildcard search token for the implementation |
void |
init()
Initializes the Lucene database. |
protected boolean |
initToSax()
Init the LinkedHashMap _xmlizable_objects with the objects in order to describ them in XML |
void |
optimize()
Optimizeds the index for the current FSDirectory. |
void |
releaseConnection(DatabaseConnection conn)
|
void |
removeProperty(java.lang.String propertyName,
java.lang.String propertyValue)
Removes a property with the provided name and value from the and EXISTING entity having the name/value pair It is up to the implementation to determine proper behavior if the entity with the provided id does not exist. |
void |
removeProperty(java.lang.String entityId,
java.lang.String propertyName,
java.lang.String propertyValue)
If the entity does not exist the method fails silently |
void |
restore(SaveParameters save_config)
Restore Lucene files |
void |
save(DatabaseEntity entity)
Saves an entity within the database. |
java.lang.String[] |
search(org.apache.avalon.framework.parameters.Parameters params)
Returns an array of database entity ids based upon the provided search parameters One can used Database.getEntity(id) after retrieving a list of ids with this method. |
java.lang.String[] |
search(org.apache.avalon.framework.parameters.Parameters params,
int mode)
|
long |
size()
Returns the number of entities within this database. |
void |
update(DatabaseEntity ent)
Updates an entity. |
protected void |
write(org.apache.lucene.document.Document lDoc)
Writes a document to the index |
Methods inherited from class fr.gouv.culture.sdx.utils.lucene.LuceneDataStore |
---|
delete, delete, delete, delete, finalize, freeResources, getFSDirectory, getFSDirectory, getReader, getSearcher, getWriter, getWriter, getWriter, getWriter, init, initVolatileObjectsToSax, isUsingCompoundFiles, recycleSearcher, search, search, verifyIndex, writeLuceneData |
Methods inherited from class fr.gouv.culture.sdx.utils.AbstractSdxObject |
---|
configureDescription, contextualize, enableLogging, getBaseAttributes, getConfiguration, getContext, getDescription, getEncoding, getId, getLocale, getLog, getServiceManager, getXmlLang, service, setDescription, setEncoding, setId, setLocale, setUpSdxObject, setUpSdxObject, setXmlLang, toSAX, verifyConfigurationResources |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface fr.gouv.culture.sdx.utils.SdxObject |
---|
getLog |
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled |
---|
enableLogging |
Methods inherited from interface org.apache.avalon.framework.context.Contextualizable |
---|
contextualize |
Methods inherited from interface org.apache.avalon.framework.service.Serviceable |
---|
service |
Methods inherited from interface fr.gouv.culture.sdx.utils.Identifiable |
---|
getId, setId |
Methods inherited from interface fr.gouv.culture.sdx.utils.Describable |
---|
getDescription, setDescription |
Methods inherited from interface fr.gouv.culture.sdx.utils.Encodable |
---|
getEncoding, setEncoding |
Methods inherited from interface fr.gouv.culture.sdx.utils.Localizable |
---|
getLocale, getXmlLang, setLocale, setXmlLang |
Methods inherited from interface org.apache.excalibur.xml.sax.XMLizable |
---|
toSAX |
Field Detail |
---|
protected java.lang.String DATABASE_DIR_NAME
protected java.lang.String id
Constructor Detail |
---|
public LuceneDatabase()
public LuceneDatabase(java.io.File dir) throws SDXException
One should call the enableLogging() method before using this database, otherwise errors won't be logged.
Most of all, you should call the init() method to make sure that the database can be used.
dir
- The directory where the Lucene database is stored.
SDXException
Method Detail |
---|
public void init() throws SDXException
It the database exists, nothing is done here. If it is doesn't exist, it will be created.
init
in interface Database
SDXException
public java.lang.String getProperty(java.lang.String documentId, java.lang.String property) throws SDXException
documentId
- The id of the document to search for.property
- The field name, or the property to search for.
SDXException
public DatabaseEntity getEntity(java.lang.String id) throws SDXException
getEntity
in interface Database
id
- The entity's id.
null
if no entity has this id.
SDXException
public DatabaseEntity[] getEntities() throws SDXException
getEntities
in interface Database
SDXException
protected DatabaseEntity getEntity(org.apache.lucene.document.Document ldoc) throws SDXException
ldoc
- The Lucene document.
SDXException
public void save(DatabaseEntity entity) throws SDXException
save
in interface Database
entity
- The entity to save.
SDXException
protected void write(org.apache.lucene.document.Document lDoc) throws SDXException
LuceneDataStore
write
in class LuceneDataStore
lDoc
- The lucene document to add
SDXException
public java.lang.String getPropertyValue(java.lang.String entityId, java.lang.String name) throws SDXException
getPropertyValue
in interface Database
entityId
- The needed entity's id.name
- The property's name for the desired value.
null
. If the property is
defined more than once, the first value is returned.
SDXException
public java.lang.String[] getPropertyValues(java.lang.String entityId, java.lang.String propertyName) throws SDXException
Please note that this method currently doesn't work for Lucene, which still stores (?) and retrieves only the last added repeatable property.TODO:remove this note after we commit our lucene changes
getPropertyValues
in interface Database
entityId
- The needed entity's name.propertyName
- The needed property's name.
null
if this
property is not defined for this entity.
SDXException
public Property[] getProperties(java.lang.String entityId) throws SDXException
getProperties
in interface Database
entityId
- The entity's id.
SDXException
public void delete(DatabaseEntity ent) throws SDXException
delete
in interface Database
ent
- The entity to delete (must have an id).
A new DatabaseEntity can be created with the id set to the
id of the entity desired for deletion and then this new entity
can be passed to this method and the appropriate entity corresponding
to that id will be deleted.
SDXException
public void delete(DatabaseEntity[] entities) throws SDXException
SDXException
public void update(DatabaseEntity ent) throws SDXException
update
in interface Database
ent
- The entity to update.
SDXException
delete(fr.gouv.culture.sdx.utils.database.DatabaseEntity)
,
save(fr.gouv.culture.sdx.utils.database.DatabaseEntity)
public long size()
size
in interface Database
size
in class LuceneDataStore
public void empty() throws SDXException
empty
in interface Database
SDXException
public java.lang.String getIndexPath()
LuceneDataStore
getIndexPath
in class LuceneDataStore
public void optimize() throws SDXException
LuceneDataStore
optimize
in interface Database
optimize
in class LuceneDataStore
SDXException
public boolean entityExists(java.lang.String id)
Database
entityExists
in interface Database
id
- _identifier of the entitypublic java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params) throws SDXException
Database
search
in interface Database
params
- search params
SDXException
public java.lang.String[] search(org.apache.avalon.framework.parameters.Parameters params, int mode) throws SDXException
search
in interface Database
SDXException
public void configure(org.apache.avalon.framework.configuration.Configuration configuration) throws org.apache.avalon.framework.configuration.ConfigurationException
configure
in interface org.apache.avalon.framework.configuration.Configurable
configure
in class AbstractSdxObject
org.apache.avalon.framework.configuration.ConfigurationException
public java.lang.String getDatabaseDirectoryName()
Database
getDatabaseDirectoryName
in interface Database
public DatabaseConnection getConnection() throws SDXException
getConnection
in interface Database
SDXException
public void releaseConnection(DatabaseConnection conn) throws SDXException
releaseConnection
in interface Database
SDXException
public void addProperty(java.lang.String entityId, java.lang.String propertyName, java.lang.String propertyValue) throws SDXException
addProperty
in interface Database
entityId
- propertyName
- propertyValue
-
SDXException
public void removeProperty(java.lang.String entityId, java.lang.String propertyName, java.lang.String propertyValue) throws SDXException
removeProperty
in interface Database
entityId
- propertyName
- propertyValue
-
SDXException
public void removeProperty(java.lang.String propertyName, java.lang.String propertyValue) throws SDXException
Database
removeProperty
in interface Database
propertyName
- The property to removepropertyValue
- The property value
SDXException
protected java.lang.String getClassNameSuffix()
AbstractSdxObject
getClassNameSuffix
in class AbstractSdxObject
public java.lang.String getWildcardSearchToken()
Database
getWildcardSearchToken
in interface Database
protected boolean initToSax()
AbstractSdxObject
initToSax
in class LuceneDataStore
public void backup(SaveParameters save_config) throws SDXException
LuceneDataStore
backup
in interface Saveable
backup
in class LuceneDataStore
SDXException
Saveable.backup(fr.gouv.culture.sdx.utils.save.SaveParameters)
public void restore(SaveParameters save_config) throws SDXException
LuceneDataStore
restore
in interface Saveable
restore
in class LuceneDataStore
SDXException
Saveable.restore(fr.gouv.culture.sdx.utils.save.SaveParameters)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |