org.modeshape.jcr.value.binary

## Class Database

- java.lang.Object
- - org.modeshape.jcr.value.binary.Database

-     public class Database
      extends Object

  Helper class for manipulation with database.

  This class looks for database SQL statements in properties files named "`binary_store_{type}_database.properties`" located within the "org/modeshape/jcr/database" area of the classpath, where "`{type}`" is `determined` from the connection, and matches one of the following:

  - `mysql`
  - `postgres`
  - `derby`
  - `hsql`
  - `h2`
  - `sqlite`
  - `db2`
  - `db2_390`
  - `informix`
  - `interbase`
  - `firebird`
  - `sqlserver`
  - `access`
  - `oracle`
  - `sybase`
  If the corresponding file is not found on the classpath, then the "`binary_store_default_database.properties`" file is used.

  Each property file should contain the set of DDL and DML statements that are used by the binary store, and the database-specific file allows database-specific schemas and queries to be used. If the properties file that corresponds to the connection's database type is not found on the classpath, then the "`binary_store_default_database.properties`" file is used.

  ModeShape does not provide out-of-the-box properties files for each of the database types listed above. If you run into any problems, you can override the statements by providing a property file that matches the naming pattern described above, and by putting that file on the classpath. (If you want to override one of ModeShape's out-of-the-box properties files, then be sure to put your custom file first on the classpath.)

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Database.Type`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `DEFAULT_STATEMENTS_FILE_PATH`
    `static String` | `STATEMENTS_FILE_PATH`
    `protected static String` | `STATEMENTS_FILE_PREFIX`
    `protected static String` | `STATEMENTS_FILENAME_SUFFIX`
    `static String` | `TABLE_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Database(Connection connection)` Creates new instance of the database.
    `Database(Connection connection, Database.Type type, String prefix)` Creates new instance of the database.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `asString(ResultSet rs)` Provides access to query data
    `static List<String>` | `asStringList(ResultSet rs)` Provides access to query data
    `protected Database.Type` | `determineType()`
    `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.
    `Connection` | `getConnection()` The connection that this object is using.
    `Database.Type` | `getDatabaseType()` Shows type of this database.
    `void` | `initialize()` Prepare this instance and the underlying database for usage.
    `PreparedStatement` | `insertContentSQL(BinaryKey key, InputStream stream)` Create statement for store content.
    `PreparedStatement` | `markUnusedSQL(BinaryKey key)` Generates SQL statement which marks content as not used.
    `protected PreparedStatement` | `prepareStatement(String statementKey)`
    `protected InputStream` | `readStream(ResultSet rs)`
    `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.
    `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

    - #### TABLE_NAME

          public static final String TABLE_NAME

      See Also:
        Constant Field Values

    - #### STATEMENTS_FILE_PATH

          public static final String STATEMENTS_FILE_PATH

      See Also:
        Constant Field Values

    - #### STATEMENTS_FILE_PREFIX

          protected static final String STATEMENTS_FILE_PREFIX

      See Also:
        Constant Field Values

    - #### STATEMENTS_FILENAME_SUFFIX

          protected static final String STATEMENTS_FILENAME_SUFFIX

      See Also:
        Constant Field Values

    - #### DEFAULT_STATEMENTS_FILE_PATH

          protected static final String DEFAULT_STATEMENTS_FILE_PATH

      See Also:
        Constant Field Values

  - ### 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

    - #### Database

          public Database(Connection connection,
                  Database.Type type,
                  String prefix)
                   throws BinaryStoreException

      Creates new instance of the database.
      Parameters:
        `connection` - connection to a database
        `type` - the type of database; may be null if the type is to be determined
        `prefix` - the prefix for the table name; may be null or blank
      Throws:
        `BinaryStoreException` - if the database type cannot be determined

  - ### Method Detail

    - #### initialize

          public void initialize()
                          throws BinaryStoreException

      Prepare this instance and the underlying database for usage.
      Throws:
        `BinaryStoreException` - if there is a problem

    - #### prepareStatement

          protected PreparedStatement prepareStatement(String statementKey)
                                                throws SQLException

      Throws:
        `SQLException`

    - #### determineType

          protected Database.Type determineType()
                                         throws BinaryStoreException

      Throws:
        `BinaryStoreException`

    - #### disconnect

          public void disconnect()

      Closes connection with database.

    - #### getConnection

          public Connection getConnection()

      The connection that this object is using.
      Returns:
        the connection; never null

    - #### getDatabaseType

          public Database.Type getDatabaseType()

      Shows type of this database.
      Returns:
        database type identifier.

    - #### 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`

    - #### readStream

          protected InputStream readStream(ResultSet rs)
                                    throws BinaryStoreException

      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`

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