Commit 1ebc3574 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3fed3756
......@@ -299,7 +299,7 @@ var rPyStateful = reflect.TypeOf((*PyStateful)(nil)).Elem() // typeof(PyStatef
//
// Only registered classes can be saved to database, and are converted to
// corresponding application-level objects on load. When ZODB loads an object
// whose class is not know, it will represent it as Broken object.
// whose class is not known, it will represent it as Broken object.
//
// class is a full class path for registered class, e.g. "BTrees.LOBTree.LOBucket".
// typ is Go type corresponding to class.
......@@ -358,6 +358,38 @@ func RegisterClass(class string, typ, stateType reflect.Type) {
typeTab[typ] = zc
}
// RegisterClassAlias registers alias for a ZODB class.
//
// When ZODB loads an object whose class is alias, it will be handled like
// object with specified ZODB class.
//
// Class aliases are useful for backward compatibility - sometimes class name
// of an object changes, but to support loading previously-saved objects, the
// old class name have to be also supported.
func RegisterClassAlias(alias, class string) {
badf := func(format string, argv ...interface{}) {
msg := fmt.Sprintf(format, argv...)
panic(fmt.Sprintf("zodb: register class alias (%q -> %q): %s", alias, class, msg))
}
if alias == "" {
badf("alias must be not empty")
}
if class == "" {
badf("class must be not empty")
}
if zc, already := classTab[alias]; already {
badf("class %q already registered for type %q", alias, zc.typ)
}
if _, already := classTab[class]; !already {
badf("class %q is not yet registered", class)
}
classTab[alias] = classTab[class]
// don't touch typeTab - this way type -> zclass will always go to
// original class, not alias.
}
// NewPersistent creates new instance of persistent type.
//
// typ must embed Persistent and must be registered with RegisterClass.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment