From 23f73bae70d8f0ae970186cc03b54cf9449d1eb4 Mon Sep 17 00:00:00 2001 From: eiffel-org Date: Fri, 26 May 2017 12:24:13 +0000 Subject: [PATCH] Update wikipage Persistence, storage, and retrieval. (Signed-off-by:b-meyer). git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1832 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../Persistence--storage--and-retrieval.wiki | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/documentation/17.01/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-kernel/Persistence--storage--and-retrieval.wiki b/documentation/17.01/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-kernel/Persistence--storage--and-retrieval.wiki index 6af02155..14e53f7c 100644 --- a/documentation/17.01/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-kernel/Persistence--storage--and-retrieval.wiki +++ b/documentation/17.01/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-kernel/Persistence--storage--and-retrieval.wiki @@ -123,13 +123,20 @@ In case of an error during retrieval, no objects will be returned and instead th =Recoverable format= -Sometimes you will be in a position where the schema of a class will have changed between the time you stored your object and the time you are trying to retrieve it. Such changes include: -* class name changed -* attributes have been added or removed -* attributes have been renamed -* attributes type have been changed +Sometimes you will be in a position where the definition of a class (its "schema") will have changed between the time you stored your object and the time you are trying to retrieve it. Such schema changes include: -The persistence mechanism allows you to retrieve the old version of the object only if it was saved using the independent_store facility. Each time you retrieve an object of a certain base class whose schema has changed, the feature correct_mismatch will be called. This feature is defined in [[ref:libraries/base/reference/any_chart|ANY]] and by default will raise an exception. To handle the mismatch, you need to redefine correct_mismatch in the base class whose schema has been changed. For example in EiffelBase, [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] has changed between version 5.1 and version 5.2 to use SPECIAL rather than [[ref:libraries/base/reference/array_chart|ARRAY]] for its internal data storage. To retrieve a 5.1 version of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]], you need to define correct_mismatch as following: +* Renaming the class. +* Adding attributes. +* Removing attributes. +* Renaming attributes. +* Changing the types of attributes. + +The persistence mechanism allows you to retrieve the old version of the object only if it was saved using the independent_store facility. + +The mechanism lets you define precisely what will happen in the case of a scheme change, or "mismatch". Each time you retrieve an object of a certain base class whose schema has changed, the feature correct_mismatch will be called. This feature is defined in [[ref:libraries/base/reference/any_chart|ANY]] and has the following effect: +* Its default version causes an exception. This is the proper behavior since the old object might not make sense with the new schema (for example, it might violate the invariant), and you do not want to continue the computation, without warning, with wrong objects. +* To specify otherwise, and avoid the exception, just redefine correct_mismatch in the class whose schema has been changed. +For example, the important EiffelBase library class [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] changed between version 5.1 and version 5.2 to use SPECIAL rather than [[ref:libraries/base/reference/array_chart|ARRAY]] for its internal data storage. To retrieve a 5.1 version of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]], you can redefine correct_mismatch as follows: correct_mismatch -- Attempt to correct object mismatch during retrieve using `mismatch_information'. @@ -161,6 +168,6 @@ correct_mismatch end -Note the use of mismatch_information, this is a once feature of [[ref:libraries/base/reference/any_chart|ANY]] of type MISMATCH_INFORMATION which behaves like a [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]]. The keys of the table are the names of the attributes on which a mismatch occurred and the values are the corresponding object fields as they were originally stored. In this particular case of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] we know that the previous version was an [[ref:libraries/base/reference/array_chart|ARRAY]], so we do an object test and if it succeeds we assign its area to the corresponding attribute of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]]. +Note the use of mismatch_information. This is a once query of [[ref:libraries/base/reference/any_chart|ANY]] of type MISMATCH_INFORMATION which behaves like a [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]]. The keys of the table are the names of the attributes on which a mismatch occurred, and the values are the corresponding object fields as they were originally stored. In this particular case of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] we know that the previous version was an [[ref:libraries/base/reference/array_chart|ARRAY]], so we do an object test and if it succeeds we assign its area to the corresponding attribute of [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]]. -If a class name changed, then you need to create an instance of CLASS_NAME_TRANSLATIONS, it behaves like a [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] where the keys represent the old name, and the value the new name. This instance needs to be created before the call to retrieved. +If a class name changed, you should create an instance of CLASS_NAME_TRANSLATIONS, it behaves like a [[ref:libraries/base/reference/hash_table_chart|HASH_TABLE]] where the keys represent the old name, and the value the new name. This instance needs to be created before the call to retrieved.