|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gcube.contentmanagement.baselayer.rdbmsImpl.GenericJDBCDatabase
public class GenericJDBCDatabase
Manager for raw file content and relationships and properties backed by a relational database. It tries to be as generic as possible and therefore SQL standard compliant to work with as many RDBMSs as possible. This goal is not easy to achieve, in particular since the handling of BLOBs has been introduced in the SQL standard comparably late and therefore not all databases comply to the standard entirely. It might be necessary to subclass or customize this class for particular databases, that do not work right-away. It has been thoroughly tested and should work fine with Apache Derby 10.1.x and 10.2, MySQL 4.1.x and 5.0. For PostgreSQL 7.3 and prior, raw content handling has been disabled since this did not follow the standard for BLOBs and provides a custom interface that would be should be used in a subclass. Starting with PostgreSQL 8.0, the commonly used BLOB interface is provided and this generic implementation should provide full support for raw content and relationships and properties - but this has not been thoroughly tested.
| Field Summary |
|---|
| Fields inherited from interface org.gcube.contentmanagement.baselayer.InstantiableManager |
|---|
MANAGER_INSTANTIATION_METHOD_NAME |
| Constructor Summary | |
|---|---|
GenericJDBCDatabase(java.lang.String dataSourceName,
java.lang.String driverClassName,
java.lang.String sourceURL)
Constructs the manager given the number of maximum parallel connections |
|
GenericJDBCDatabase(java.lang.String dataSourceName,
java.lang.String driverClassName,
java.lang.String driverURL,
java.lang.String maxParallelConnections)
Constructs the manager given the number of maximum parallel connections |
|
| Method Summary | |
|---|---|
void |
addLinkContentLocation(java.lang.String oid,
RawContentLocation location)
Registers a location for the content of the information object |
void |
addReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole,
long position,
java.lang.String propagationRule)
Adds a new reference between two information objects. |
long |
countReferences(java.lang.String oid,
boolean isSource,
java.lang.String role,
java.lang.String secondaryRole)
Counts the references of an object |
java.lang.String |
createInfoObject(java.lang.String name,
java.lang.String type,
BasicStorageHints hints)
Creates a new information object |
boolean |
deleteBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
Removes the binary content from storage |
void |
ensureResponsibleFor(RawContentLocation rcl)
|
boolean |
existsBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
Checks whether there is content associated with this content id |
boolean |
existsInfoObject(java.lang.String oid)
Checks, whether an information object with the given ID exists. |
boolean |
existsReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
Check if a reference exists |
BaseLayerStream |
getBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
Opens the content for reading and passes the input stream to the caller WARNING: This method will leave the database connection open, to give direct access to te BLOB field. |
java.sql.Connection |
getConnection()
Convenience method to retrieve a connection from pool including proper failure handling. |
java.lang.String |
getDataProvider()
|
static java.lang.String |
getExpliciteMapping(int javaSQLType)
Returns mapped type for mappings that have been set explicitely. |
BasicInfoObjectDescription |
getInfoObjectDescription(java.lang.String oid)
Retrieves an existing information object with all available information |
BasicInfoObjectDescription |
getInfoObjectDescription(java.lang.String oid,
boolean includeProperties,
boolean includeReferences,
boolean includeReferred)
Retrieves an existing information object with some tuning parameters, to remove unrequired information |
static GenericJDBCDatabase |
getManagerInstance(java.lang.String[] params,
java.lang.String managerName)
Generic factory method that returns an instance responsible for a particular directory |
java.lang.String |
getNativeType(int javaSQLType)
Determines the appropriate datatype for the currently used database for a given Java type. In some rare cases the database driver may not declare a mapping. |
BasicPropertyDescription |
getProperty(java.lang.String oid,
java.lang.String name)
Retrieves a particular property of an information object |
BasicReferenceDescription |
getReference(java.lang.String sourceoid,
java.lang.String targetoid)
Retrieves a single reference |
java.lang.String |
getUniqueStorageLocationIDFor(java.lang.String objectID)
|
boolean |
handles(java.lang.String dataprovider)
Checks whether the RawFileContentManager can handle this data. |
boolean |
hasProperty(java.lang.String oid,
java.lang.String name)
Returnes whether an information object has a particular property set |
boolean |
hasRawContent(java.lang.String oid)
Returns whether there exists raw content associated with an information object |
static boolean |
isBlacklistedDatatype(java.lang.String dbDataType,
java.lang.String databaseProductName,
java.lang.String databaseProductVersion)
Checks whether a type is in the list of types that shoulod be avoided due to known issues. |
boolean |
isPerformAdditionalChecks()
|
RawContentLocation |
makePermanentLocation(RawContentLocation currentLocation,
BasicStorageHints hints)
Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints. |
void |
releaseConnection(java.sql.Connection connection)
Convenience method to give a connection back to the pool including proper failure handling. |
boolean |
removeAllRawContentOf(java.lang.String oid,
BasicStorageHints hints)
Unregisters all locations for the content of the information object and deltes the content physically. |
boolean |
removeInfoObject(java.lang.String oid)
Deletes an information object. |
boolean |
removeLinkContentLocation(RawContentLocation location)
Unregisters a location for the content of the information object |
boolean |
removeReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
Deletes any reference with having the given parameters. To insure consistency, this method will propagate any defined deletion event. |
java.util.List<RawContentLocation> |
retrieveObjectContentLocations(java.lang.String oid)
Adds to the list all locations known for a particular object |
java.util.Map<java.lang.String,BasicPropertyDescription> |
retrieveObjectProperties(java.lang.String oid)
Retrieves all properties of an information object |
java.util.List<java.lang.String> |
retrieveOIDByProperty(java.lang.String name,
java.lang.String value)
Deprecated. prefer #retrieveOIDByProperty(String, String, Collection)
because of more effecient handling |
java.util.List<BasicReferenceDescription> |
retrieveReferences(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
Adds all references from this object to the list |
java.util.List<BasicReferenceDescription> |
retrieveReferencesOrderedByPosition(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
Adds all references from this object to the list |
java.util.List<BasicReferenceDescription> |
retrieveReferred(java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
Retrieves all references which point to this target object. |
java.util.List<java.lang.String> |
retrieveReferredSourceOIDs(java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
Adds all source object IDs to this object to the list |
java.util.List<java.lang.String> |
retrieveReferredTargetOIDs(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
Retrieves all object OIDs of information object, which have a reference from this source object. |
RawContentLocation |
saveBinaryContent(java.lang.String uniqueStorageID,
BaseLayerStream binaryFileContent,
BasicStorageHints hints)
Saves the passed binary content in the managed resource. |
void |
setPerformAdditionalChecks(boolean performAdditionalChecks)
|
void |
setProperty(java.lang.String oid,
java.lang.String name,
java.lang.String type,
java.lang.String value)
Sets the storage property of a given name for a particular information object. |
boolean |
supportsAppending()
Tells whether this content manager supports appending content in addition to overwriting the content when storing |
boolean |
unsetProperty(java.lang.String oid,
java.lang.String name)
Removes a property (or all properties) of an information object |
void |
updateLinkContentLocations(java.lang.String oid,
RawContentLocation newestLocation)
Updates the locations for the content of the information object |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GenericJDBCDatabase(java.lang.String dataSourceName,
java.lang.String driverClassName,
java.lang.String driverURL,
java.lang.String maxParallelConnections)
throws BaseLayerException
dataSourceName - a user-defined name for the datasource that will get used e.g.
as data provider for raw content locationsdriverClassName - the class of the JDBC driverdriverURL - the URL of the JDBC connection StringmaxParallelConnections - the number of maximum parallel connections that should be ued
concurrently in the connection pool
BaseLayerException - if something goes wrong
public GenericJDBCDatabase(java.lang.String dataSourceName,
java.lang.String driverClassName,
java.lang.String sourceURL)
throws BaseLayerException
dataSourceName - a user-defined name for the datasource that will get used e.g.
as data provider for raw content locationsdriverClassName - the class of the JDBC driversourceURL - the URL of the JDBC connection String
BaseLayerException - if something goes wrong| Method Detail |
|---|
public java.sql.Connection getConnection()
throws TemporaryUnavailableException
BaseLayerException - if connection cannot be established, e.g. because number of
concurrent connections and an exceeded timeout
TemporaryUnavailableExceptionpublic void releaseConnection(java.sql.Connection connection)
connection - the connection to add to the pool
public RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID,
BaseLayerStream binaryFileContent,
BasicStorageHints hints)
throws BaseLayerException
saveBinaryContent in interface RawFileContentManagerbinaryFileContent - the content to storeuniqueStorageID - a unique ID to access the contenthints - the hints that should be used
BaseLayerException - in case of failure of underlying storage system
public BaseLayerStream getBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
throws BaseLayerException
dispose() method of
BaseLayerStream.
getBinaryContent in interface RawFileContentManagerrcl - the location to access the contenthints - the hints that should be used
BaseLayerException - in case of failure of underlying storage system
public boolean deleteBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
throws BaseLayerException
deleteBinaryContent in interface RawFileContentManagerrcl - the RawContentLocation where the content is accessiblehints - the hints that should be used
BaseLayerException - in case of failure of underlying storage system
public boolean existsBinaryContent(RawContentLocation rcl,
BasicStorageHints hints)
throws BaseLayerException
existsBinaryContent in interface RawFileContentManagerrcl - the location of the content
BaseLayerException - in case of failure of underlying storage system
public java.lang.String createInfoObject(java.lang.String name,
java.lang.String type,
BasicStorageHints hints)
throws BaseLayerException
createInfoObject in interface RelationshipAndPropertyManagername - a human readable name (does not need to be unique, can also be null)type - the type of the information objecthints - hints that should be taken into account, e.g. BasicStorageHints#HINT_NAME_PREDEFINED_ID.
BaseLayerException - if something goes wrong
public BasicInfoObjectDescription getInfoObjectDescription(java.lang.String oid)
throws BaseLayerException
getInfoObjectDescription in interface RelationshipAndPropertyManageroid - the object ID of the object
BaseLayerException - if something goes wrong
public BasicInfoObjectDescription getInfoObjectDescription(java.lang.String oid,
boolean includeProperties,
boolean includeReferences,
boolean includeReferred)
throws BaseLayerException
getInfoObjectDescription in interface RelationshipAndPropertyManageroid - the object ID of the objectincludeProperties - if set to true, properties will be retrieved; otherwise
properties will not be retrievedincludeReferences - if set to true, references to other info objects will be
retrieved; otherwise references will not be retrievedincludeReferred - if set to true, references from other info objects will be
retrieved; otherwise those references will not be retrieved
BaseLayerException - if something goes wrong
public boolean existsInfoObject(java.lang.String oid)
throws BaseLayerException
existsInfoObject in interface RelationshipAndPropertyManageroid - the object ID of the object
BaseLayerException - if something goes wrong
public boolean removeInfoObject(java.lang.String oid)
throws BaseLayerException
removeInfoObject in interface RelationshipAndPropertyManageroid - the object ID of the object that should be deleted
BaseLayerException - if something goes wrong
public boolean removeAllRawContentOf(java.lang.String oid,
BasicStorageHints hints)
throws BaseLayerException
removeAllRawContentOf in interface RelationshipAndPropertyManageroid - the object ID of the object who's raw content should be
deleted
BaseLayerException - if something goes wrong
public void addReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole,
long position,
java.lang.String propagationRule)
throws BaseLayerException
addReference in interface RelationshipAndPropertyManagersourceoid - the object ID of the starting information object of the relationtargetoid - the object Id of the referenced information objectrole - the role of the information object (sourceoid) with respect to
this referenceposition - an attribute to allow for position preserving representation,
set to ReferenceDescription.UNDEFINED_POSITION if
not in use.secondaryRole - similar to role, but for the secondary role used by Metadata
CatalogpropagationRule - rule for propagation of deletion.
BaseLayerException - if something goes wrongorg.gcube.contentmanagement.layerindependent.descriptions.BasicReferenceDescription
public boolean removeReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
removeReference in interface RelationshipAndPropertyManagersourceoid - the object ID of the starting information object of the
relationtargetoid - the object Id of the referenced information objectrole - the role of the information object (sourceoid) with respect
this reference. Can be set to
ReferenceDescription.ANY_ROLE to match all
possible values of role.secondaryRole - similar to role, but for the secondary role used by Metadata
Catalog
BaseLayerException - if something goes wrong
public long countReferences(java.lang.String oid,
boolean isSource,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
countReferences in interface RelationshipAndPropertyManageroid - the oid of the known objectisSource - true, if oid is the object ID of the source object, false if
oid is the target oidrole - the role, or ReferenceDescription.ANY_ROLEsecondaryRole - similar to role, but for the secondary role used by Metadata
Catalog
java.sql.SQLException
BaseLayerException - if something goes wrong
public java.util.List<BasicReferenceDescription> retrieveReferences(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
retrieveReferences in interface RelationshipAndPropertyManagersourceoid - the oid of the source objectrole - the role, or ReferenceDescription.ANY_ROLEsecondaryRole - similar to role, but for the secondary role used by Metadata
CatalogrefDescList - the list to which the references should be added
java.sql.SQLException
BaseLayerException - if something goes wrong
public BasicReferenceDescription getReference(java.lang.String sourceoid,
java.lang.String targetoid)
throws BaseLayerException
getReference in interface RelationshipAndPropertyManagersourceoid - the object ID of the starting information object of the
relationtargetoid - the object ID of the target information object of the relation
BaseLayerException - if something goes wrong
public java.util.List<BasicReferenceDescription> retrieveReferencesOrderedByPosition(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
retrieveReferencesOrderedByPosition in interface RelationshipAndPropertyManagersourceoid - the oid of the source objectrole - the role, or ReferenceDescription.ANY_ROLEsecondaryRole - similar to role, but for the secondary role used by Metadata Catalog
java.sql.SQLException
BaseLayerException - if something goes wrong
public java.util.List<BasicReferenceDescription> retrieveReferred(java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
retrieveReferred in interface RelationshipAndPropertyManagertargetoid - the object Id of the referenced information objectrole - the role of the information object (sourceoid) with respect
this reference. Can be set to
BasicReferenceDescription.ANY_ROLE to match all
possible values of role.secondaryRole - similar to role, but for the secondary role used by Metadata
CatalogrefDescriptions - a collection to which elements of type
BasicReferenceDescription will be added
BasicReferenceDescription
BaseLayerException - if something goes wrong
public java.util.List<java.lang.String> retrieveReferredSourceOIDs(java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
retrieveReferredSourceOIDs in interface RelationshipAndPropertyManagertargetoid - the oid of the target objectrole - the role, or ReferenceDescription.ANY_ROLEsecondaryRole - similar to role, but for the secondary role used by Metadata
CatalogrefDescList - the list to which the references should be added
java.sql.SQLException
BaseLayerException - if something goes wrong
public java.util.List<java.lang.String> retrieveReferredTargetOIDs(java.lang.String sourceoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
retrieveReferredTargetOIDs in interface RelationshipAndPropertyManagersourceoid - the object Id of the referenced information objectrole - the role of the information object (sourceoid) with respect
this reference. Can be set to
BasicReferenceDescription.ANY_ROLE to match all
possible values of role.secondaryRole - similar to role, but for the secondary role used by Metadata
Catalogoids - a collection to which elements of type String
will be added
BaseLayerException - if something goes wrong
public java.util.Map<java.lang.String,BasicPropertyDescription> retrieveObjectProperties(java.lang.String oid)
throws BaseLayerException
retrieveObjectProperties in interface RelationshipAndPropertyManageroidthe - object ID of the information object
PropertyDescription will be
added, the key is the property name
BaseLayerException
public java.util.List<java.lang.String> retrieveOIDByProperty(java.lang.String name,
java.lang.String value)
throws BaseLayerException
#retrieveOIDByProperty(String, String, Collection)
because of more effecient handling
retrieveOIDByProperty in interface RelationshipAndPropertyManagername - the name of the propertyvalue - the value of the property
BaseLayerException - if something goes wrong
public void setProperty(java.lang.String oid,
java.lang.String name,
java.lang.String type,
java.lang.String value)
throws BaseLayerException
If this property already exists, it will be updated. If not, it will be added with the given values.
setProperty in interface RelationshipAndPropertyManageroid - the object ID of the information objectname - the name of the property (use prefixes, e.g. namespace
prefixes to disambiguate)type - the type of the value of the propertyvalue - the value of the property
BaseLayerException - if something goes wrong
public BasicPropertyDescription getProperty(java.lang.String oid,
java.lang.String name)
throws BaseLayerException
getProperty in interface RelationshipAndPropertyManageroid - the object ID of the information objectname - the name of the property
ObjectNotFoundException - if either the OID is invalid or there is no property with
this name defined for this information object
BaseLayerException - if something goes wrong
public boolean hasProperty(java.lang.String oid,
java.lang.String name)
throws BaseLayerException
hasProperty in interface RelationshipAndPropertyManageroid - the object ID of the information objectname - the name of the property
ObjectNotFoundException - if the OID is invalid
BaseLayerException - if something goes wrong
public boolean existsReference(java.lang.String sourceoid,
java.lang.String targetoid,
java.lang.String role,
java.lang.String secondaryRole)
throws BaseLayerException
RelationshipAndPropertyManager
existsReference in interface RelationshipAndPropertyManagersourceoid - the object ID of the starting information object of the relationtargetoid - the object Id of the referenced information objectrole - the role of the information object (sourceoid) with respect to this referencesecondaryRole - similar to role, but for the secondary role used by Metadata Catalog
true if the reference has been found, false otherwise.
BaseLayerException - if something goes wrongorg.gcube.contentmanagement.layerindependent.descriptions.BasicReferenceDescription
public boolean unsetProperty(java.lang.String oid,
java.lang.String name)
throws BaseLayerException
unsetProperty in interface RelationshipAndPropertyManageroid - the object ID of the information objectname - the name of the property, or PropertyDescription.ANY_NAME for
all
BaseLayerException - if something goes wrongpublic boolean handles(java.lang.String dataprovider)
This means that it can handle the requests for content stored at this dataprovider. In the ideal case, this also checks if it has all required access rights. But this cannot be enforced as a strong requirement before the actual calls take place.
handles in interface RawFileContentManagerdataprovider -
public boolean isPerformAdditionalChecks()
public void setPerformAdditionalChecks(boolean performAdditionalChecks)
public void addLinkContentLocation(java.lang.String oid,
RawContentLocation location)
throws BaseLayerException
addLinkContentLocation in interface RelationshipAndPropertyManageroid - the object ID of the information objectlocation - the location where the content resides
BaseLayerException - if something goes wrong
public void updateLinkContentLocations(java.lang.String oid,
RawContentLocation newestLocation)
throws BaseLayerException
updateLinkContentLocations in interface RelationshipAndPropertyManageroid - the object ID of the information objectnewestLocation - the location where most recent version of the content resides
BaseLayerException - if something goes wrong
public boolean removeLinkContentLocation(RawContentLocation location)
throws BaseLayerException
removeLinkContentLocation in interface RelationshipAndPropertyManagerlocation - the location where the content no longer resides
BaseLayerException - if something goes wrong
public java.util.List<RawContentLocation> retrieveObjectContentLocations(java.lang.String oid)
throws BaseLayerException
retrieveObjectContentLocations in interface RelationshipAndPropertyManageroid - the oid of the info object or UNLINKED_RAW_CONTENT
java.sql.SQLException
BaseLayerException - if something goes wrong
public boolean hasRawContent(java.lang.String oid)
throws BaseLayerException
hasRawContent in interface RelationshipAndPropertyManageroid - the object ID of the information object
BaseLayerException - if something goes wrong
public void ensureResponsibleFor(RawContentLocation rcl)
throws ValueNotValidException
ValueNotValidExceptionpublic java.lang.String getDataProvider()
getDataProvider in interface RawFileContentManagerpublic java.lang.String getNativeType(int javaSQLType)
null will be returned.
javaSQLType - the Java datatype according to java.sql.Types
public static boolean isBlacklistedDatatype(java.lang.String dbDataType,
java.lang.String databaseProductName,
java.lang.String databaseProductVersion)
dbDataType - the String as used in SQL DDL statementsdatabaseProductName - the database product name as in the connetion metadatadatabaseProductVersion - the database product version as in the connection metadata
public static java.lang.String getExpliciteMapping(int javaSQLType)
javaSQLType - the Java SQL Type
public boolean supportsAppending()
supportsAppending in interface RawFileContentManagerBasicStorageHints#HINT_NAME_APPEND_CONTENT
public RawContentLocation makePermanentLocation(RawContentLocation currentLocation,
BasicStorageHints hints)
throws ValueNotValidException
This is of particular interest for username / password combinations.
makePermanentLocation in interface RawFileContentManagercurrentLocation - the location, where content can be accessed currently (may
require information from the hints)hints - hints, that may be needed to request the content
ValueNotValidException - If some hints was not defined correctly or there is no
possibility to include that in the permanent location.
public static GenericJDBCDatabase getManagerInstance(java.lang.String[] params,
java.lang.String managerName)
throws BaseLayerException
params - the first String contains the directory that will be managed.
If array is empty, the manager will be able to manage any
directorymanagerName - the name of the manager (currently not in use)
BaseLayerException - if location is not manageable by this kind of manager, e.g.
because directory does not existpublic java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
getUniqueStorageLocationIDFor in interface RawFileContentManager
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||