ModeShape Distribution 3.0.0.Beta4

org.modeshape.jcr.value.binary
Class Database

java.lang.Object
  extended by org.modeshape.jcr.value.binary.Database

public class Database
extends Object

Helper class for manipulation with database.


Nested Class Summary
 class Database.SQLBuilder
          Database specific SQL query builder.
static class Database.Type
           
 
Field Summary
protected  Connection connection
           
protected  Database.Type databaseType
           
 
Constructor Summary
Database(Connection connection)
          Creates new instance of the database.
 
Method Summary
static InputStream asStream(ResultSet rs)
          Provides access to query data
static String asString(ResultSet rs)
          Provides access to query data
static List<String> asStringList(ResultSet rs)
          Provides access to query data
 void createTable()
          Creates table for storage.
 void disconnect()
          Closes connection with database.
static void execute(PreparedStatement sql)
          Executes specifies statement.
static ResultSet executeQuery(PreparedStatement sql)
          Runs SQL statement
static void executeUpdate(PreparedStatement sql)
          Executes specifies update statement.
 Database.Type getDatabaseType()
          Shows type of this database.
 PreparedStatement insertContentSQL(BinaryKey key, InputStream stream)
          Create statement for store content.
 PreparedStatement markUnusedSQL(BinaryKey key)
          Generates SQL statement which marks content as not used.
 PreparedStatement removeExpiredContentSQL(long deadline)
          Generates SQL statement which removes expired content.
 PreparedStatement restoreContentSQL(BinaryKey key)
          Generates SQL statement which marks content as used.
 PreparedStatement retrieveBinaryKeys(Set<BinaryKey> keys)
          Generates SQL statement for retrieving the binary keys in the store.
 PreparedStatement retrieveContentSQL(BinaryKey key, boolean inUse)
          Generates SQL statement for content retrieve.
 PreparedStatement retrieveExtTextSQL(BinaryKey key)
          Generate SQL statement which returns extracted text.
 PreparedStatement retrieveMimeTypeSQL(BinaryKey key)
          Generates SQL statement for mime type retrieve.
protected  void setDatabaseType(Database.Type databaseType)
          Modifies database type.
 void setPrefix(String prefix)
          Configures table name prefix.
 boolean tableExists()
          Checks database for CONTENT_STORE table
 PreparedStatement updateExtTextSQL(BinaryKey key, String text)
          Generates SQL statement which updates extracted text field.
 PreparedStatement updateMimeTypeSQL(BinaryKey key, String mimeType)
          Generates SQL statement which modifies mime type value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected final Connection connection

databaseType

protected Database.Type databaseType
Constructor Detail

Database

public Database(Connection connection)
         throws BinaryStoreException
Creates new instance of the database.

Parameters:
connection - connection to a database
Throws:
BinaryStoreException - if the database type cannot be determined
Method Detail

getDatabaseType

public Database.Type getDatabaseType()
Shows type of this database.

Returns:
database type identifier.

setDatabaseType

protected void setDatabaseType(Database.Type databaseType)
Modifies database type.

Parameters:
databaseType - new database type identifier.

setPrefix

public void setPrefix(String prefix)
Configures table name prefix.

Parameters:
prefix - table name prefix.

insertContentSQL

public PreparedStatement insertContentSQL(BinaryKey key,
                                          InputStream stream)
                                   throws BinaryStoreException
Create statement for store content.

Parameters:
key - unique content identifier
stream - content to store
Returns:
SQL statement.
Throws:
BinaryStoreException

retrieveContentSQL

public PreparedStatement retrieveContentSQL(BinaryKey key,
                                            boolean inUse)
                                     throws BinaryStoreException
Generates SQL statement for content retrieve.

Parameters:
key - content id
inUse - true if the binary given by the key is expected to be still be in use, or false if the binary can be no longer used
Returns:
executable SQL statement
Throws:
BinaryStoreException

markUnusedSQL

public PreparedStatement markUnusedSQL(BinaryKey key)
                                throws BinaryStoreException
Generates SQL statement which marks content as not used.

Parameters:
key - the content id.
Returns:
SQL statement.
Throws:
BinaryStoreException

restoreContentSQL

public PreparedStatement restoreContentSQL(BinaryKey key)
                                    throws BinaryStoreException
Generates SQL statement which marks content as used.

Parameters:
key - the content id.
Returns:
SQL statement.
Throws:
BinaryStoreException

removeExpiredContentSQL

public PreparedStatement removeExpiredContentSQL(long deadline)
                                          throws BinaryStoreException
Generates SQL statement which removes expired content.

Parameters:
deadline - expire time
Returns:
SQL statement.
Throws:
BinaryStoreException

retrieveMimeTypeSQL

public PreparedStatement retrieveMimeTypeSQL(BinaryKey key)
                                      throws BinaryStoreException
Generates SQL statement for mime type retrieve.

Parameters:
key - content id
Returns:
SQL statement.
Throws:
BinaryStoreException

updateMimeTypeSQL

public PreparedStatement updateMimeTypeSQL(BinaryKey key,
                                           String mimeType)
                                    throws BinaryStoreException
Generates SQL statement which modifies mime type value.

Parameters:
key - content id
mimeType - the new value for mime type
Returns:
SQL statement
Throws:
BinaryStoreException

retrieveExtTextSQL

public PreparedStatement retrieveExtTextSQL(BinaryKey key)
                                     throws BinaryStoreException
Generate SQL statement which returns extracted text.

Parameters:
key - content id
Returns:
SQL statement
Throws:
BinaryStoreException

updateExtTextSQL

public PreparedStatement updateExtTextSQL(BinaryKey key,
                                          String text)
                                   throws BinaryStoreException
Generates SQL statement which updates extracted text field.

Parameters:
key - content id
text - new value for the extracted text
Returns:
SQL statement
Throws:
BinaryStoreException

retrieveBinaryKeys

public PreparedStatement retrieveBinaryKeys(Set<BinaryKey> keys)
                                     throws BinaryStoreException
Generates SQL statement for retrieving the binary keys in the store.

Parameters:
keys - the container into which the keys should be placed
Returns:
executable SQL statement
Throws:
BinaryStoreException

execute

public static void execute(PreparedStatement sql)
                    throws BinaryStoreException
Executes specifies statement.

Parameters:
sql - the statement to execute
Throws:
BinaryStoreException

executeQuery

public static ResultSet executeQuery(PreparedStatement sql)
                              throws BinaryStoreException
Runs SQL statement

Parameters:
sql - SQL statement
Returns:
result of statement execution
Throws:
BinaryStoreException

executeUpdate

public static void executeUpdate(PreparedStatement sql)
                          throws BinaryStoreException
Executes specifies update statement.

Parameters:
sql - the statement to execute
Throws:
BinaryStoreException

asStream

public static InputStream asStream(ResultSet rs)
                            throws BinaryStoreException
Provides access to query data

Parameters:
rs - retrieved single value
Returns:
result as input stream.
Throws:
BinaryStoreException

asString

public static String asString(ResultSet rs)
                       throws BinaryStoreException
Provides access to query data

Parameters:
rs - retrieved query result
Returns:
result as string.
Throws:
BinaryStoreException

asStringList

public static List<String> asStringList(ResultSet rs)
                                 throws BinaryStoreException
Provides access to query data

Parameters:
rs - retrieved query result
Returns:
result as string.
Throws:
BinaryStoreException

tableExists

public boolean tableExists()
                    throws BinaryStoreException
Checks database for CONTENT_STORE table

Returns:
true if table exists
Throws:
BinaryStoreException

createTable

public void createTable()
                 throws BinaryStoreException
Creates table for storage.

Throws:
BinaryStoreException

disconnect

public void disconnect()
Closes connection with database.


ModeShape Distribution 3.0.0.Beta4

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.