public class Database extends Object
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
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.)
Modifier and Type | Class and Description |
---|---|
static class |
Database.Type |
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 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.
|
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.
|
public static final String TABLE_NAME
public static final String STATEMENTS_FILE_PATH
protected static final String STATEMENTS_FILE_PREFIX
protected static final String STATEMENTS_FILENAME_SUFFIX
protected static final String DEFAULT_STATEMENTS_FILE_PATH
public Database(Connection connection) throws BinaryStoreException
connection
- connection to a databaseBinaryStoreException
- if the database type cannot be determinedpublic Database(Connection connection, Database.Type type, String prefix) throws BinaryStoreException
connection
- connection to a databasetype
- the type of database; may be null if the type is to be determinedprefix
- the prefix for the table name; may be null or blankBinaryStoreException
- if the database type cannot be determinedpublic void initialize() throws BinaryStoreException
BinaryStoreException
- if there is a problemprotected PreparedStatement prepareStatement(String statementKey) throws SQLException
SQLException
protected Database.Type determineType() throws BinaryStoreException
BinaryStoreException
public void disconnect()
public Connection getConnection()
public Database.Type getDatabaseType()
public PreparedStatement insertContentSQL(BinaryKey key, InputStream stream) throws BinaryStoreException
key
- unique content identifierstream
- content to storeBinaryStoreException
public PreparedStatement retrieveContentSQL(BinaryKey key, boolean inUse) throws BinaryStoreException
key
- content idinUse
- 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
usedBinaryStoreException
public PreparedStatement markUnusedSQL(BinaryKey key) throws BinaryStoreException
key
- the content id.BinaryStoreException
public PreparedStatement restoreContentSQL(BinaryKey key) throws BinaryStoreException
key
- the content id.BinaryStoreException
public PreparedStatement removeExpiredContentSQL(long deadline) throws BinaryStoreException
deadline
- expire timeBinaryStoreException
public PreparedStatement retrieveMimeTypeSQL(BinaryKey key) throws BinaryStoreException
key
- content idBinaryStoreException
public PreparedStatement updateMimeTypeSQL(BinaryKey key, String mimeType) throws BinaryStoreException
key
- content idmimeType
- the new value for mime typeBinaryStoreException
public PreparedStatement retrieveExtTextSQL(BinaryKey key) throws BinaryStoreException
key
- content idBinaryStoreException
public PreparedStatement updateExtTextSQL(BinaryKey key, String text) throws BinaryStoreException
key
- content idtext
- new value for the extracted textBinaryStoreException
public PreparedStatement retrieveBinaryKeys(Set<BinaryKey> keys) throws BinaryStoreException
keys
- the container into which the keys should be placedBinaryStoreException
public static void execute(PreparedStatement sql) throws BinaryStoreException
sql
- the statement to executeBinaryStoreException
public static ResultSet executeQuery(PreparedStatement sql) throws BinaryStoreException
sql
- SQL statementBinaryStoreException
public static void executeUpdate(PreparedStatement sql) throws BinaryStoreException
sql
- the statement to executeBinaryStoreException
protected InputStream readStream(ResultSet rs) throws BinaryStoreException
BinaryStoreException
public static String asString(ResultSet rs) throws BinaryStoreException
rs
- retrieved query resultBinaryStoreException
public static List<String> asStringList(ResultSet rs) throws BinaryStoreException
rs
- retrieved query resultBinaryStoreException
Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.