Class DbNameIndex
- java.lang.Object
-
- org.apache.jackrabbit.core.persistence.pool.DbNameIndex
-
- All Implemented Interfaces:
StringIndex
- Direct Known Subclasses:
NGKDbNameIndex
,PostgreSQLNameIndex
public class DbNameIndex extends Object implements StringIndex
Implements aStringIndex
that stores and retrieves the names from a table in a database.Note that this class is not threadsafe by itself. it needs to be synchronized by the using application.
Due to a bug with oracle that treats empty strings a null values (see JCR-815), all empty strings are replaced by a ' '. since names never start with a space, this it not problematic yet.
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionHelper
conHelper
protected String
indexSelectSQL
protected String
nameInsertSQL
protected String
nameSelectSQL
-
Constructor Summary
Constructors Constructor Description DbNameIndex(ConnectionHelper conHlpr, String schemaObjectPrefix)
Creates a new index that is stored in a db.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this index and releases it's resources.protected int
getIndex(String string)
Retrieves the index from the database for the given string.protected String
getString(int index)
Retrieves the string from the database for the given index.String
indexToString(int idx)
Returns the string for a given index.protected void
init(String schemaObjectPrefix)
Inits this index and prepares the statements.protected int
insertString(String string)
Inserts a string into the database and returns the new index.int
stringToIndex(String string)
Returns the index for a given string.
-
-
-
Field Detail
-
conHelper
protected final ConnectionHelper conHelper
-
nameSelectSQL
protected String nameSelectSQL
-
indexSelectSQL
protected String indexSelectSQL
-
nameInsertSQL
protected String nameInsertSQL
-
-
Constructor Detail
-
DbNameIndex
public DbNameIndex(ConnectionHelper conHlpr, String schemaObjectPrefix) throws SQLException
Creates a new index that is stored in a db.- Parameters:
conHlpr
- theConnectionHelper
schemaObjectPrefix
- the prefix for table names- Throws:
SQLException
- if the statements cannot be prepared.
-
-
Method Detail
-
init
protected void init(String schemaObjectPrefix) throws SQLException
Inits this index and prepares the statements.- Parameters:
schemaObjectPrefix
- the prefix for table names- Throws:
SQLException
- if the statements cannot be prepared.
-
close
public void close()
Closes this index and releases it's resources.
-
stringToIndex
public int stringToIndex(String string)
Returns the index for a given string. If the given string is not already indexed, the implementation can either automatically index it or throw an exception.- Specified by:
stringToIndex
in interfaceStringIndex
- Parameters:
string
- the indexed (or to be indexed) string- Returns:
- index of the string
-
indexToString
public String indexToString(int idx) throws IllegalArgumentException
Returns the string for a given index.- Specified by:
indexToString
in interfaceStringIndex
- Parameters:
idx
- index of a string- Returns:
- the indexed string
- Throws:
IllegalArgumentException
- if the indexed string does not exist
-
insertString
protected int insertString(String string)
Inserts a string into the database and returns the new index.- Parameters:
string
- the string to insert- Returns:
- the new index.
-
getIndex
protected int getIndex(String string)
Retrieves the index from the database for the given string.- Parameters:
string
- the string to retrieve the index for- Returns:
- the index or -1 if not found.
-
getString
protected String getString(int index) throws IllegalArgumentException, IllegalStateException
Retrieves the string from the database for the given index.- Parameters:
index
- the index to retrieve the string for.- Returns:
- the string
- Throws:
IllegalArgumentException
- if the string is not foundIllegalStateException
-
-