[Checkins] SVN: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/
added a simple two-way relation with mentor and project in
the sample
Charith Paranaliyanage
paranaliyanage at gmail.com
Fri Jun 27 13:57:05 EDT 2008
Log message for revision 87832:
added a simple two-way relation with mentor and project in the sample
Changed:
U Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
U Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py
U Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py
U Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py
-=-
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py 2008-06-27 16:05:14 UTC (rev 87831)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py 2008-06-27 17:56:08 UTC (rev 87832)
@@ -6,10 +6,10 @@
from zope.component import getUtilitiesFor
from zope.app.catalog.interfaces import ICatalog
from zope.app.intid import IIntIds
+import zc.relation.interfaces
from ocql.interfaces import IDB
from ocql.database.index import AllIndex
-#from ocql.testing.database import MClass
class MetaType:
def get_property(self, name):
@@ -67,6 +67,7 @@
def __init__(self,context=None):
#all the interfaces are retrieved from the catalog
#items = list(searchInterfaceUtilities(self))
+
catalogs = getUtilitiesFor(ICatalog)
intids = getUtility(IIntIds)
for name, catalog in catalogs:
@@ -81,6 +82,15 @@
self.db.__setitem__(interface.__name__,obj_list)
self.classes.__setitem__(interface.__name__,MClass(interface))
+ catalogs = getUtilitiesFor(zc.relation.interfaces.ICatalog)
+ for name, catalog in catalogs:
+ for index in catalog:
+ results = catalog.iterValueIndexInfo()
+ for result in results:
+ continue
+ #need to continue if this is required
+
+
def getAll(self, klass):
return self.db[klass]
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py 2008-06-27 16:05:14 UTC (rev 87831)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/interfaces.py 2008-06-27 17:56:08 UTC (rev 87832)
@@ -1,4 +1,4 @@
-from zope.interface import Interface
+from zope.interface import Interface,Attribute
from zope.schema import Text, TextLine, Field, Choice
from zope.app.container.constraints import ContainerTypesConstraint, ItemTypePrecondition
from zope.app.container.constraints import contains, containers
@@ -57,4 +57,10 @@
class IOrganizationContainer(IContainer):
"""Organization is also a container for projects, students and mentors"""
- contains(".IProject", ".IStudent", ".IMentor")
\ No newline at end of file
+ contains(".IProject", ".IStudent", ".IMentor")
+
+class IProjectRelation(Interface):
+ mentor = Attribute('assigned mentor for the project')
+ project = Attribute('mentoring project')
+
+
\ No newline at end of file
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py 2008-06-27 16:05:14 UTC (rev 87831)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/sample/project.py 2008-06-27 17:56:08 UTC (rev 87832)
@@ -3,7 +3,7 @@
from zope.interface import Interface
import persistent
-from ocql.testing.sample.interfaces import IProject
+from ocql.testing.sample.interfaces import IProject, IProjectRelation
class Project(persistent.Persistent):
"""A simple implementation of a Project .
@@ -32,3 +32,11 @@
def __repr__(self):
return "%s <%s>" % (self.__class__.__name__, self.name)
+
+
+class ProjectRelation(object):
+ implements(IProjectRelation)
+
+ def __init__(self, mentor, project):
+ self.mentor = mentor
+ self.project = project
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py 2008-06-27 16:05:14 UTC (rev 87831)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/testing/utils.py 2008-06-27 17:56:08 UTC (rev 87832)
@@ -19,26 +19,49 @@
from zope.app.keyreference.testing import SimpleKeyReference
from ocql.testing.sample.interfaces import IOrganization
-from ocql.testing.sample.interfaces import IProject
+from ocql.testing.sample.interfaces import IProject, IProjectRelation
from ocql.testing.sample.interfaces import IStudent
from ocql.testing.sample.interfaces import IMentor
from ocql.testing.sample.mentor import Mentor
-from ocql.testing.sample.project import Project
+from ocql.testing.sample.project import Project, ProjectRelation
from ocql.testing.sample.student import Student
from ocql.testing.sample.organization import Organization
+
+import zc.relation.catalog
+import zc.relation.interfaces
+import zc.relation.queryfactory
+import BTrees
+_obj = {}
+_relation = {}
+
def setupInterfaces(test):
provideInterface('', IOrganization)
provideInterface('', IProject)
provideInterface('', IStudent)
provideInterface('', IMentor)
+def dumpObj(obj, catalog, cache):
+ if _obj.setdefault(obj.name,obj) is not obj:
+ raise ValueError('mentor can only take one project')
+ return obj
+
+def loadObj(token, catalog, cache):
+ return _obj[token]
+
+def dumpRelation(obj, catalog, cache):
+ if _relation.setdefault(id(obj),obj) is not obj:
+ raise ValueError('same relation')
+ return id(obj)
+
+def loadRelation(token, catalog, cache):
+ return _relation[token]
+
def setupCatalog(test):
intids = IntIds()
component.provideUtility(intids, IIntIds)
component.provideAdapter(SimpleKeyReference)
-
cat = Catalog()
cat['org_name'] = FieldIndex('name', IOrganization)
@@ -85,11 +108,21 @@
o1.name = u"Zope.org"
id = intids.register(o1)
cat.index_doc(id, o1)
+
+ cat2 = zc.relation.catalog.Catalog(dumpRelation, loadRelation)
+ cat2.addValueIndex(IProjectRelation['project'], dumpObj, loadObj, btree=BTrees.family32.OO)
+ cat2.addValueIndex(IProjectRelation['mentor'], dumpObj, loadObj, btree=BTrees.family32.OO)
+ cat2.addDefaultQueryFactory(zc.relation.queryfactory.TransposingTransitive('project','mentor'))
+ rel = ProjectRelation(m1, p1)
+ cat2.index(rel)
+ component.provideUtility(cat2, zc.relation.interfaces.ICatalog, name='rel-catalog')
component.provideUtility(cat, ICatalog, name='foo-catalog')
def queryCatalog():
cat = component.getUtility(ICatalog, name='foo-catalog')
+ cat2 = component.getUtility(zc.relation.interfaces.ICatalog, name='rel-catalog')
+ query = cat2.tokenizeQuery
intids = component.getUtility(IIntIds)
results = cat.apply({'student_name':('Charith','Charith')})
@@ -102,4 +135,12 @@
for r in results:
obj = intids.getObject(r)
- print obj
\ No newline at end of file
+ print obj
+
+ rel_mentor = cat.apply({'all_mentors':(1,1)})
+
+ for r in rel_mentor:
+ obj = intids.getObject(r)
+ for p in cat2.findValueTokens('project',query(mentor=obj)):
+ print p.name
+
\ No newline at end of file
More information about the Checkins
mailing list