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
1cdfff35
Commit
1cdfff35
authored
Jul 26, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5b4637e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
50 deletions
+52
-50
go/zodb/connection.go
go/zodb/connection.go
+52
-8
go/zodb/zodbpy.go
go/zodb/zodbpy.go
+0
-42
No files found.
go/zodb/connection.go
View file @
1cdfff35
...
...
@@ -186,26 +186,27 @@ func (e *wrongClassError) Error() string {
//
// Use-case: in ZODB references are (pyclass, oid), so new ghost is created
// without further loading anything.
func
(
conn
*
Connection
)
get
(
class
string
,
oid
Oid
)
(
IP
yP
ersistent
,
error
)
{
func
(
conn
*
Connection
)
get
(
class
string
,
oid
Oid
)
(
IPersistent
,
error
)
{
conn
.
objmu
.
Lock
()
// XXX -> rlock
wobj
:=
conn
.
objtab
[
oid
]
var
pyobj
IPy
Persistent
var
obj
I
Persistent
checkClass
:=
false
if
wobj
!=
nil
{
if
xobj
:=
wobj
.
Get
();
xobj
!=
nil
{
pyobj
=
xobj
.
(
IPy
Persistent
)
obj
=
xobj
.
(
I
Persistent
)
}
}
if
py
obj
==
nil
{
py
obj
=
conn
.
newGhost
(
class
,
oid
)
conn
.
objtab
[
oid
]
=
weak
.
NewRef
(
py
obj
)
if
obj
==
nil
{
obj
=
conn
.
newGhost
(
class
,
oid
)
conn
.
objtab
[
oid
]
=
weak
.
NewRef
(
obj
)
}
else
{
checkClass
=
true
}
conn
.
objmu
.
Unlock
()
if
checkClass
{
if
cls
:=
pyobj
.
PyClass
();
class
!=
cls
{
// XXX get obj class via reflection?
if
cls
:=
obj
.
PyClass
();
class
!=
cls
{
return
nil
,
&
OpError
{
URL
:
conn
.
stor
.
URL
(),
Op
:
fmt
.
Sprintf
(
"@%s: get"
,
conn
.
at
),
// XXX abuse
...
...
@@ -215,10 +216,53 @@ func (conn *Connection) get(class string, oid Oid) (IPyPersistent, error) {
}
}
return
py
obj
,
nil
return
obj
,
nil
}
// Get returns in-RAM object corresponding to specified ZODB object according to current database view.
//
// If there is already in-RAM object that corresponds to oid, that in-RAM object is returned.
// Otherwise new in-RAM object is created and filled with object's class loaded from the database.
//
// The scope of the object returned is the Connection. XXX ok?
//
// The object's data is not necessarily loaded after Get returns. Use
// PActivate to make sure the object is fully loaded.
func
(
conn
*
Connection
)
Get
(
ctx
context
.
Context
,
oid
Oid
)
(
IPersistent
,
error
)
{
conn
.
objmu
.
Lock
()
// XXX -> rlock
wobj
:=
conn
.
objtab
[
oid
]
var
xobj
interface
{}
if
wobj
!=
nil
{
xobj
=
wobj
.
Get
()
}
conn
.
objmu
.
Unlock
()
// object was already there in objtab.
if
xobj
!=
nil
{
return
xobj
.
(
IPersistent
),
nil
}
// object is not there in objtab - raw load it, get its class -> get(pyclass, oid)
// XXX py hardcoded
pyclass
,
pystate
,
serial
,
err
:=
conn
.
loadpy
(
ctx
,
oid
)
if
err
!=
nil
{
return
nil
,
err
// XXX errctx
}
obj
,
err
:=
conn
.
get
(
pyclass
.
Module
+
"."
+
pyclass
.
Name
,
oid
)
if
err
!=
nil
{
return
nil
,
err
}
// XXX we are dropping just loaded pystate. Usually Get should be used
// to only load root object, so maybe that is ok.
//
// TODO -> use (pystate, serial) to activate.
_
,
_
=
pystate
,
serial
return
obj
,
nil
}
...
...
go/zodb/zodbpy.go
View file @
1cdfff35
...
...
@@ -144,48 +144,6 @@ func (d *dummyPyInstance) PySetState(pystate interface{}) error {
// ----------------------------------------
// Get returns in-RAM object corresponding to specified ZODB object according to current database view.
//
// If there is already in-RAM object that corresponds to oid, that in-RAM object is returned.
// Otherwise new in-RAM object is created and filled with object's class loaded from the database.
//
// The scope of the object returned is the Connection. XXX ok?
//
// The object's data is not necessarily loaded after Get returns. Use
// PActivate to make sure the object is fully loaded.
func
(
conn
*
Connection
)
Get
(
ctx
context
.
Context
,
oid
Oid
)
(
IPyPersistent
,
error
)
{
conn
.
objmu
.
Lock
()
// XXX -> rlock
wobj
:=
conn
.
objtab
[
oid
]
var
xobj
interface
{}
if
wobj
!=
nil
{
xobj
=
wobj
.
Get
()
}
conn
.
objmu
.
Unlock
()
// object was already there in objtab.
if
xobj
!=
nil
{
return
xobj
.
(
IPyPersistent
),
nil
// XXX if just IPersistent ?
}
// object is not there in objtab - raw load it, get its class -> get(pyclass, oid)
pyclass
,
pystate
,
serial
,
err
:=
conn
.
loadpy
(
ctx
,
oid
)
if
err
!=
nil
{
return
nil
,
err
// XXX errctx
}
obj
,
err
:=
conn
.
get
(
pyclass
,
oid
)
if
err
!=
nil
{
return
nil
,
err
}
// XXX we are dropping just loaded pystate. Usually Get should be used
// to only load root object, so maybe that is ok.
//
// TODO -> use (pystate, serial) to activate.
_
,
_
=
pystate
,
serial
return
obj
,
nil
}
// loadpy loads object specified by oid and decodes it as a ZODB Python object.
//
// loadpy does not create any in-RAM object associated with Connection.
...
...
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