io.permazen.UntypedPermazenObject Maven / Gradle / Ivy
Show all versions of permazen-main Show documentation
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen;
import io.permazen.core.TypeNotInSchemaException;
/**
* Represents a {@link PermazenObject} whose type does not exist in the transaction's schema.
*
*
*
*
*
*
* Instances of this class are used to represent objects with a type that is defined in some other database schema
* but not in the current one. This situation can occur when a new schema drops a previously defined Java model type
* when there are objects still existing in the database. If encountered, such objects are represented by instances of
* this class.
*
*
* These objects are still fully accessible, but they must be accessed via introspection using the {@link PermazenTransaction}
* field access methods, with the {@code migrateSchema} parameter set to false (to prevent a {@link TypeNotInSchemaException}).
*
*
* For example, suppose a schema update removes the {@code Account} class and replaces fields referencing {@code Account}
* objects with a copy of the {@code accountId} field. Then a corresponding schema migration might look like this:
*
* @OnSchemaChange
* private void applySchemaChanges(Map<String, Object> oldValues) {
* if (oldValues.containsKey("account")) { // was replaced with "accountId"
* final PermazenObject acct = (PermazenObject)oldValues.get("account"); // has type UntypedPermazenObject
* final PermazenTransaction ptx = this.getTransaction();
* final String acctId = (String)ptx.readSimpleField(acct.getObjId(), "accountId", false);
* this.setAccountId(acctId);
* }
* // ...etc
* }
*
*/
public abstract class UntypedPermazenObject implements PermazenObject {
}