|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfr.gouv.culture.sdx.utils.SdxObjectImpl
fr.gouv.culture.sdx.utils.lucene.LuceneDataStore
fr.gouv.culture.sdx.utils.database.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 :
Field Summary | |
protected java.lang.String |
DATABASE_DIR_NAME
|
protected java.lang.String |
id
|
protected org.apache.avalon.framework.component.ComponentManager |
manager
Hashtable of property values |
protected java.util.Hashtable |
props
|
Fields inherited from class fr.gouv.culture.sdx.utils.lucene.LuceneDataStore |
ALL_FIELD, ALL_VALUE, analyzer, fsd, fsdFile, ID_FIELD, LUCENE_CHECK_FILE, searcher, XML_LANG_FIELD |
Fields inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl |
encoding, logger |
Fields inherited from interface fr.gouv.culture.sdx.utils.database.Database |
DATABASE_DIR_PATH, SEARCH_MODE_AND, SEARCH_MODE_NOT, SEARCH_MODE_OR |
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 |
compose(org.apache.avalon.framework.component.ComponentManager manager)
Compose the object so that we get the Component s we need from the
ComponentManager . |
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 |
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 |
getId()
|
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. |
void |
optimize()
Utility method for database maintenance, normally used to optimize indices of Lucene based repositories It is the responsibility of the Repository to ensure that unnecessary optimizations are not performed when this method is called. |
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 |
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. |
void |
setId(java.lang.String id)
|
void |
setProperties(java.util.Hashtable props)
Provides a list of properties of this class which can be used at configuration and/or initialization time |
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, getReader, getSearcher, getWriter, getWriter, init, recycleSearcher, search, search, verifyIndex, writeLuceneData |
Methods inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl |
enableLogging, getChildLogger, setEncoding |
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 |
setEncoding |
Methods inherited from interface org.apache.avalon.framework.logger.LogEnabled |
enableLogging |
Field Detail |
protected org.apache.avalon.framework.component.ComponentManager manager
protected java.util.Hashtable props
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.Method Detail |
public void compose(org.apache.avalon.framework.component.ComponentManager manager) throws org.apache.avalon.framework.component.ComponentException
Component
s we need from the
ComponentManager
.
compose
in interface org.apache.avalon.framework.component.Composable
manager
- The component manager from Cocoon that allow us to acquire a database selector component.
org.apache.avalon.framework.component.ComponentException
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
Database
optimize
in interface Database
optimize
in class LuceneDataStore
SDXException
public void setProperties(java.util.Hashtable props)
Database
setProperties
in interface Database
props
- 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 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
org.apache.avalon.framework.configuration.ConfigurationException
public java.lang.String getDatabaseDirectoryName()
Database
getDatabaseDirectoryName
in interface Database
public void setId(java.lang.String id)
setId
in interface Database
public java.lang.String getId()
getId
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
public java.lang.String getWildcardSearchToken()
Database
getWildcardSearchToken
in interface Database
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |