Class VersionHistoryService
- java.lang.Object
-
- org.linuxforhealth.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 class
VersionHistoryService.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 void
addVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int version)
Add this version (idempotent)boolean
applies(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 databasevoid
clearVersionHistory(java.lang.String objectSchema)
Remove the version history information for all objects in the given schemastatic VersionHistoryService.TypeNameVersion
createTypeNameVersion(java.lang.String objectSchema, java.lang.String type, java.lang.String name, int version)
Factory method for creating aVersionHistoryService.TypeNameVersion
tuplejava.lang.Integer
getVersion(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName)
Get the current version of an objectvoid
init()
Fetch the version history map for the given schema.void
insertVersionHistoriesInTx(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)
Insert all the entries in the versionHistoryMap.void
insertVersionHistory(java.util.Collection<VersionHistoryService.TypeNameVersion> versionHistories)
Insert all the entries in the versionHistoryMap in a new transaction (useful for testing).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.void
setTarget(IDatabaseAdapter tgt)
For injection of theIDatabaseTarget
void
setTransactionProvider(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.TypeNameVersion
tuple- 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:IVersionHistoryService
Get the current version of an object- Specified by:
getVersion
in 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:IVersionHistoryService
Add this version (idempotent)- Specified by:
addVersion
in interfaceIVersionHistoryService
-
applies
public boolean applies(java.lang.String objectSchema, java.lang.String objectType, java.lang.String objectName, int changeVersion)
Description copied from interface:IVersionHistoryService
Check to see if we described object is newer than we have currently in the database- Specified by:
applies
in interfaceIVersionHistoryService
- Returns:
-
-