org.apache.jackrabbit.core.persistence.pool
Class DbNameIndex

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

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  ConnectionHelper conHelper
           
protected  String indexSelectSQL
           
protected  String nameInsertSQL
           
protected  String nameSelectSQL
           
 
Constructor Summary
DbNameIndex(ConnectionHelper conHlpr, 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  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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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:
conHelper - the ConnectionHelper
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:
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 given string is not already indexed, the implementation can either automatically index it or throw an exception.

Specified by:
stringToIndex in interface StringIndex
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 interface StringIndex
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 found
IllegalStateException


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