org.apache.jackrabbit.core.persistence.bundle.util
Class DbNameIndex

java.lang.Object
  extended by org.apache.jackrabbit.core.persistence.bundle.util.DbNameIndex
All Implemented Interfaces:
StringIndex
Direct Known Subclasses:
NGKDbNameIndex

public class DbNameIndex
extends Object
implements StringIndex

Implements a 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.


Field Summary
protected  PreparedStatement indexSelect
           
protected  PreparedStatement nameInsert
           
protected  PreparedStatement nameSelect
           
 
Constructor Summary
DbNameIndex(Connection con, String schemaObjectPrefix)
          Creates a new index that is stored in a db.
 
Method Summary
 void close()
          Closes this index and releases it's resources.
protected  void closeResultSet(ResultSet rs)
          Closes the result set
protected  void closeStatement(PreparedStatement stmt)
          closes the statement
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(Connection con, 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.
protected  void resetStatement(PreparedStatement stmt)
          Resets the given PreparedStatement by clearing the parameters and warnings contained.
 int stringToIndex(String string)
          Returns the index for a given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameSelect

protected PreparedStatement nameSelect

indexSelect

protected PreparedStatement indexSelect

nameInsert

protected PreparedStatement nameInsert
Constructor Detail

DbNameIndex

public DbNameIndex(Connection con,
                   String schemaObjectPrefix)
            throws SQLException
Creates a new index that is stored in a db.

Parameters:
con - the jdbc connection
schemaObjectPrefix - the prefix for table names
Throws:
SQLException - if the statements cannot be prepared.
Method Detail

init

protected void init(Connection con,
                    String schemaObjectPrefix)
             throws SQLException
Inits this index and prepares the statements.

Parameters:
con - the jdbc connection
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 string does not exist in the underlying index map a new index needs to be created.

Specified by:
stringToIndex in interface StringIndex
Parameters:
string - the string to return the index for
Returns:
the index of that string.

indexToString

public String indexToString(int idx)
Returns the string for a given index. if the index does not exist in the underlying index map, null is returned.

Specified by:
indexToString in interface StringIndex
Parameters:
idx - the index tp returns the string for.
Returns:
the string or null

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)
Retrieves the string from the database for the given index.

Parameters:
index - the index to retrieve the string for.
Returns:
the string or null if not found.

closeStatement

protected void closeStatement(PreparedStatement stmt)
closes the statement

Parameters:
stmt - the statement

resetStatement

protected void resetStatement(PreparedStatement stmt)
Resets the given PreparedStatement by clearing the parameters and warnings contained.

Parameters:
stmt - The PreparedStatement to reset. If null this method does nothing.

closeResultSet

protected void closeResultSet(ResultSet rs)
Closes the result set

Parameters:
rs - the result set.


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.