Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
1ebc3574
Commit
1ebc3574
authored
Sep 03, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3fed3756
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
go/zodb/persistent.go
go/zodb/persistent.go
+33
-1
No files found.
go/zodb/persistent.go
View file @
1ebc3574
...
...
@@ -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 know
n
, 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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment