public class DbNameIndex extends Object implements StringIndex
StringIndex
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.
Modifier and Type | Field and Description |
---|---|
protected ConnectionHelper |
conHelper |
protected String |
indexSelectSQL |
protected String |
nameInsertSQL |
protected String |
nameSelectSQL |
Constructor and Description |
---|
DbNameIndex(ConnectionHelper conHlpr,
String schemaObjectPrefix)
Creates a new index that is stored in a db.
|
Modifier and Type | Method and 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.
|
protected final ConnectionHelper conHelper
protected String nameSelectSQL
protected String indexSelectSQL
protected String nameInsertSQL
public DbNameIndex(ConnectionHelper conHlpr, String schemaObjectPrefix) throws SQLException
conHlpr
- the ConnectionHelper
schemaObjectPrefix
- the prefix for table namesSQLException
- if the statements cannot be prepared.protected void init(String schemaObjectPrefix) throws SQLException
schemaObjectPrefix
- the prefix for table namesSQLException
- if the statements cannot be prepared.public void close()
public int stringToIndex(String string)
stringToIndex
in interface StringIndex
string
- the indexed (or to be indexed) stringpublic String indexToString(int idx) throws IllegalArgumentException
indexToString
in interface StringIndex
idx
- index of a stringIllegalArgumentException
- if the indexed string does not existprotected int insertString(String string)
string
- the string to insertprotected int getIndex(String string)
string
- the string to retrieve the index forprotected String getString(int index) throws IllegalArgumentException, IllegalStateException
index
- the index to retrieve the string for.IllegalArgumentException
- if the string is not foundIllegalStateException
Copyright © 2004–2024 The Apache Software Foundation. All rights reserved.