Class VersionHistoryService
- java.lang.Object
-
- com.ibm.fhir.database.utils.version.VersionHistoryService
-
- All Implemented Interfaces:
IVersionHistoryService
public class VersionHistoryService extends java.lang.Object implements IVersionHistoryService
Encapsulation of the transaction needed to read the version history table
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVersionHistoryService.TypeNameVersion
-
Constructor Summary
Constructors Constructor Description VersionHistoryService(java.lang.String adminSchemaName, java.lang.String... schemaNames)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int version)Add this version (idempotent)booleanapplies(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int changeVersion)Check to see if we described object is newer than we have currently in the databasevoidclearVersionHistory(java.lang.String objectSchema)Remove the version history information for all objects in the given schemastatic VersionHistoryService.TypeNameVersioncreateTypeNameVersion(java.lang.String objectSchema, java.lang.String type, java.lang.String name, int version)Factory method for creating aVersionHistoryService.TypeNameVersiontuplejava.lang.IntegergetVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName)Get the current version of an objectvoidinit()Fetch the version history map for the given schema.voidinsertVersionHistoriesInTx(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)Insert all the entries in the versionHistoryMap.voidinsertVersionHistory(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)Insert all the entries in the versionHistoryMap in a new transaction (useful for testing).voidinsertVersionHistoryInTx(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int version)Insert the version history for the objectType/objectName/version.voidsetTarget(IDatabaseAdapter tgt)For injection of theIDatabaseTargetvoidsetTransactionProvider(ITransactionProvider tp)For injection of theIConnectionProvider
-
-
-
Method Detail
-
setTransactionProvider
public void setTransactionProvider(ITransactionProvider tp)
For injection of theIConnectionProvider- Parameters:
tp-
-
setTarget
public void setTarget(IDatabaseAdapter tgt)
For injection of theIDatabaseTarget- Parameters:
tgt-
-
init
public void init()
Fetch the version history map for the given schema. This then becomes the reference for everything we try to apply going forward. This assumes, of course. If someone else comes along and tries to update the schema after we read this map, then it's possible (likely) that we'll try to apply a change that is no longer required, which is probably going to end in tears. But it's OK. A second attempt will see that the change has already been applied, so won't try again.
-
insertVersionHistoriesInTx
public void insertVersionHistoriesInTx(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)
Insert all the entries in the versionHistoryMap. This must be called in the context of an existing transaction- Parameters:
versionHistories-
-
insertVersionHistoryInTx
public void insertVersionHistoryInTx(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int version)Insert the version history for the objectType/objectName/version.- Parameters:
objectSchema-objectType-objectName-version-
-
clearVersionHistory
public void clearVersionHistory(java.lang.String objectSchema)
Remove the version history information for all objects in the given schema- Parameters:
objectSchema-
-
insertVersionHistory
public void insertVersionHistory(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)
Insert all the entries in the versionHistoryMap in a new transaction (useful for testing).- Parameters:
versionHistories-
-
createTypeNameVersion
public static VersionHistoryService.TypeNameVersion createTypeNameVersion(java.lang.String objectSchema, java.lang.String type, java.lang.String name, int version)
Factory method for creating aVersionHistoryService.TypeNameVersiontuple- Parameters:
objectSchema-type-name-version-- Returns:
-
getVersion
public java.lang.Integer getVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName)Description copied from interface:IVersionHistoryServiceGet the current version of an object- Specified by:
getVersionin interfaceIVersionHistoryService- Returns:
- the current version of the given object or null if it doesn't exist
-
addVersion
public void addVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int version)Description copied from interface:IVersionHistoryServiceAdd this version (idempotent)- Specified by:
addVersionin interfaceIVersionHistoryService
-
applies
public boolean applies(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int changeVersion)Description copied from interface:IVersionHistoryServiceCheck to see if we described object is newer than we have currently in the database- Specified by:
appliesin interfaceIVersionHistoryService- Returns:
-
-