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
74f0c47b
Commit
74f0c47b
authored
Oct 01, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fa18a91d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
12 deletions
+31
-12
go/zodb/connection.go
go/zodb/connection.go
+1
-1
go/zodb/persistent.go
go/zodb/persistent.go
+29
-10
go/zodb/persistent_test.go
go/zodb/persistent_test.go
+1
-1
No files found.
go/zodb/connection.go
View file @
74f0c47b
...
...
@@ -166,7 +166,7 @@ func (conn *Connection) get(class string, oid Oid) (IPersistent, error) {
conn
.
objmu
.
Unlock
()
if
checkClass
{
if
cls
:=
zc
lassOf
(
obj
);
class
!=
cls
{
if
cls
:=
C
lassOf
(
obj
);
class
!=
cls
{
var
err
error
=
&
wrongClassError
{
class
,
cls
}
xerr
.
Contextf
(
&
err
,
"get %s"
,
Xid
{
conn
.
at
,
oid
})
return
nil
,
err
...
...
go/zodb/persistent.go
View file @
74f0c47b
...
...
@@ -278,15 +278,33 @@ type zclass struct {
var
classTab
=
make
(
map
[
string
]
*
zclass
)
// {} class -> zclass
var
typeTab
=
make
(
map
[
reflect
.
Type
]
*
zclass
)
// {} type -> zclass
//
zc
lassOf returns ZODB class of a Go object.
//
C
lassOf returns ZODB class of a Go object.
//
// If ZODB class was not registered for obj's type, "" is returned.
func
zclassOf
(
obj
IPersistent
)
string
{
zc
,
ok
:=
typeTab
[
reflect
.
TypeOf
(
obj
)
.
Elem
()]
if
!
ok
{
return
""
// If ZODB class was not registered for obj's type, "" is returned. // XXX
// XXX -> keep obj IPersistent and add TypeOf(interface{}) ?
//func ClassOf(obj IPersistent) string {
func
ClassOf
(
obj
interface
{})
string
{
zb
,
broken
:=
obj
.
(
*
Broken
)
if
broken
{
return
fmt
.
Sprintf
(
"ZODB.Broken(%q)"
,
zb
.
class
)
}
return
zc
.
class
typ
:=
reflect
.
TypeOf
(
obj
)
zc
,
ok
:=
typeTab
[
typ
.
Elem
()]
if
ok
{
return
zc
.
class
}
// XXX can we get vvv at all if obj is IPersistent? -> yes, if type was not registered.
// not Broken and type not registered to ZODB -> Broken(fullGoType(obj))
fullType
:=
"go:"
+
typ
.
PkgPath
()
if
typ
.
PkgPath
()
!=
""
{
// it could be builtin type, e.g. string
fullType
+=
"."
}
fullType
+=
typ
.
Name
()
//return fmt.Sprintf("ZODB.Broken(%q)", fullType)
return
fullType
}
var
rIPersistent
=
reflect
.
TypeOf
((
*
IPersistent
)(
nil
))
.
Elem
()
// typeof(IPersistent)
...
...
@@ -476,9 +494,10 @@ func (b *brokenState) SetState(state *mem.Buf) error {
}
// XXX how to print zodb.Broken("BTrees.IOBTree.IOBTree"), but not long noise for types that don't define GoString?
func
(
b
*
Broken
)
GoString
()
string
{
return
fmt
.
Sprintf
(
"&zodb.Broken(%q)"
,
b
.
class
)
}
// XXX -> zodb.ClassOf
// func (b *Broken) GoString() string {
// return fmt.Sprintf("&zodb.Broken(%q)", b.class)
// }
// brokenZClass is used for Persistent.zclass for Broken objects.
var
brokenZClass
=
&
zclass
{
...
...
go/zodb/persistent_test.go
View file @
74f0c47b
...
...
@@ -120,7 +120,7 @@ func TestPersistent(t *testing.T) {
checkObj
(
obj
,
nil
,
11
,
InvalidTid
,
GHOST
,
0
,
nil
)
assert
.
Equal
(
zc
lassOf
(
obj
),
"t.zodb.MyObject"
)
assert
.
Equal
(
C
lassOf
(
obj
),
"t.zodb.MyObject"
)
// TODO activate - jar has to load, state changes
...
...
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