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
    --- | ---
    `protected class` | `Database.DatabaseBinaryStream`
    `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
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Database(Connection connection)` Creates new instance of the database.
    `protected` | `Database(Connection connection, Database.Type type, String prefix)` Creates new instance of the database.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `contentExists(BinaryKey key, boolean inUse, Connection connection)`
    `protected Database.Type` | `determineType(DatabaseMetaData metaData)`
    `protected Set<BinaryKey>` | `getBinaryKeys(Connection connection)`
    `protected String` | `getExtractedText(BinaryKey key, Connection connection)`
    `protected String` | `getMimeType(BinaryKey key, Connection connection)`
    `protected String` | `getTableName()`
    `protected void` | `insertContent(BinaryKey key, InputStream stream, long size, Connection connection)`
    `protected void` | `markUnused(Iterable<BinaryKey> keys, Connection connection)`
    `protected PreparedStatement` | `prepareStatement(String statementKey, Connection connection)`
    `protected InputStream` | `readContent(BinaryKey key, Connection connection)` Attempts to return the content stream for a given binary value.
    `protected void` | `removeExpiredContent(long deadline, Connection connection)`
    `protected void` | `restoreContent(Connection connection, Iterable<BinaryKey> keys)`
    `protected void` | `setExtractedText(BinaryKey key, String text, Connection connection)`
    `protected void` | `setMimeType(BinaryKey key, String mimeType, Connection connection)`
    `protected static void` | `tryToClose(Connection connection)`
    `protected static void` | `tryToClose(PreparedStatement statement)`

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

          protected Database(Connection connection)
                      throws IOException,
                             SQLException

      Creates new instance of the database.
      Parameters:
        `connection` - a `Connection` instance; may not be null
      Throws:
        `IOException` - if the statements cannot be processed
        `SQLException` - if the db initialization sequence fails

    - #### Database

          protected Database(Connection connection,
                  Database.Type type,
                  String prefix)
                      throws IOException,
                             SQLException

      Creates new instance of the database.
      Parameters:
        `connection` - a `Connection` instance; may not be null
        `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:
        `IOException` - if the statements cannot be processed
        `SQLException` - if the db initialization sequence fails

  - ### Method Detail

    - #### getTableName

          protected String getTableName()

    - #### prepareStatement

          protected PreparedStatement prepareStatement(String statementKey,
                                           Connection connection)
                                                throws SQLException

      Throws:
        `SQLException`

    - #### determineType

          protected Database.Type determineType(DatabaseMetaData metaData)
                                         throws SQLException

      Throws:
        `SQLException`

    - #### insertContent

          protected void insertContent(BinaryKey key,
                           InputStream stream,
                           long size,
                           Connection connection)
                                throws SQLException

      Throws:
        `SQLException`

    - #### contentExists

          protected boolean contentExists(BinaryKey key,
                              boolean inUse,
                              Connection connection)
                                   throws SQLException

      Throws:
        `SQLException`

    - #### readContent

          protected InputStream readContent(BinaryKey key,
                                Connection connection)
                                     throws SQLException

      Attempts to return the content stream for a given binary value.
      Parameters:
        `key` - a `BinaryKey` the key of the binary value, may not be null
        `connection` - a `Connection` instance, may not be null
      Returns:
        either a stream that wraps the input stream of the binary value and closes the connection and the statement when it terminates or `null`, meaning that the binary was not found.
      Throws:
        `SQLException` - if anything unexpected fails

    - #### markUnused

          protected void markUnused(Iterable<BinaryKey> keys,
                        Connection connection)
                             throws SQLException

      Throws:
        `SQLException`

    - #### restoreContent

          protected void restoreContent(Connection connection,
                            Iterable<BinaryKey> keys)
                                 throws SQLException

      Throws:
        `SQLException`

    - #### removeExpiredContent

          protected void removeExpiredContent(long deadline,
                                  Connection connection)
                                       throws SQLException

      Throws:
        `SQLException`

    - #### getMimeType

          protected String getMimeType(BinaryKey key,
                           Connection connection)
                                throws SQLException

      Throws:
        `SQLException`

    - #### setMimeType

          protected void setMimeType(BinaryKey key,
                         String mimeType,
                         Connection connection)
                              throws SQLException

      Throws:
        `SQLException`

    - #### getExtractedText

          protected String getExtractedText(BinaryKey key,
                                Connection connection)
                                     throws SQLException

      Throws:
        `SQLException`

    - #### setExtractedText

          protected void setExtractedText(BinaryKey key,
                              String text,
                              Connection connection)
                                   throws SQLException

      Throws:
        `SQLException`

    - #### getBinaryKeys

          protected Set<BinaryKey> getBinaryKeys(Connection connection)
                                          throws SQLException

      Throws:
        `SQLException`

    - #### tryToClose

          protected static void tryToClose(PreparedStatement statement)

    - #### tryToClose

          protected static void tryToClose(Connection connection)

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