Class RegistryMetadataManagement
java.lang.Object
org.gcube.informationsystem.resourceregistry.persistence.orientdb.types.RegistryMetadataManagement
Reads and persists the
RegistryMetadata singleton, stored as a document of a plain
OrientDB class of its own (no superclass).- Author:
- Luca Frosini (ISTI - CNR)
-
Constructor Summary
ConstructorsConstructorDescriptionRegistryMetadataManagement(com.orientechnologies.orient.core.db.document.ODatabaseDocument db) Creates a new instance of RegistryMetadataManagement. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSets the version of a model's type, only if the model holds it, with a single server-side update.booleanReports whether the singleton class exists, tolerating a stale per-session schema cache.voidCreates the OrientDB class holding the singleton, if it does not exist.org.gcube.informationsystem.registry.RegistryMetadataget()Retrieves the current RegistryMetadata document from the database.incrementRevisionCount(String modelName) Advances the globalrevisionCountand the given model's by one, with a single server-side update, atomic in OrientDB, so that concurrent increments from different instances cannot lose each other.booleanAdds a type to a model, or sets its version, with a single server-side update.ReadsrevisionCountalone.booleanremoveType(String modelName, String typeName) Removes a type from a model, if the model holds it, with a single server-side update.voidsave(org.gcube.informationsystem.registry.RegistryMetadata metadata) Persists the whole RegistryMetadata singleton document.
-
Constructor Details
-
RegistryMetadataManagement
public RegistryMetadataManagement(com.orientechnologies.orient.core.db.document.ODatabaseDocument db) Creates a new instance of RegistryMetadataManagement.- Parameters:
db- the active OrientDB database session
-
-
Method Details
-
createClassIfMissing
public void createClassIfMissing()Creates the OrientDB class holding the singleton, if it does not exist. Schema changes are not transactional: call it outside any transaction. -
get
public org.gcube.informationsystem.registry.RegistryMetadata get()Retrieves the current RegistryMetadata document from the database. If none exists, returns null.- Returns:
- the RegistryMetadata singleton, or null if not initialized
-
save
public void save(org.gcube.informationsystem.registry.RegistryMetadata metadata) Persists the whole RegistryMetadata singleton document. Only for bootstrap, migration and System Restore: at runtime the record is changed field by field, by the server-side updates below, so that concurrent instances cannot overwrite each other.- Parameters:
metadata- the RegistryMetadata document to save
-
classExists
public boolean classExists()Reports whether the singleton class exists, tolerating a stale per-session schema cache.Sessions come from long-lived pools, so one opened before the class was created -- possibly by another service instance -- still caches a schema without it. The cache is reloaded once before concluding, only on the apparent-absence path.
- Returns:
trueif the class exists
-
incrementRevisionCount
Advances the globalrevisionCountand the given model's by one, with a single server-side update, atomic in OrientDB, so that concurrent increments from different instances cannot lose each other.- Parameters:
modelName- the model the written type belongs to, ornullto advance the global counter alone- Returns:
- the new global value, or
nullwhen no record exists
-
readRevisionCount
ReadsrevisionCountalone.- Returns:
- the current value, or
nullwhen the class or the record does not exist
-
putType
Adds a type to a model, or sets its version, with a single server-side update.- Parameters:
modelName- the model nametypeName- the type nameversion- the type version- Returns:
trueif the record was updated,falsewhen no record exists
-
alignType
Sets the version of a model's type, only if the model holds it, with a single server-side update.- Parameters:
modelName- the model nametypeName- the type nameversion- the type version- Returns:
trueif the model holds the type and its version was set
-
removeType
Removes a type from a model, if the model holds it, with a single server-side update.- Parameters:
modelName- the model nametypeName- the type name- Returns:
trueif the model held the type and it was removed
-