]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Oct 2005 03:46:20 +0000 (03:46 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 23 Oct 2005 03:46:20 +0000 (03:46 +0000)
examples/adjacencytree/byroot_tree.py
examples/adjacencytree/tables.py
lib/sqlalchemy/databases/postgres.py
lib/sqlalchemy/mapper.py
lib/sqlalchemy/objectstore.py
lib/sqlalchemy/util.py

index d352db4c711756a86abd4e1936fc72594a3f5815..ee1dd4a4953ab1dcb984204065f093e3718cf6e3 100644 (file)
@@ -3,7 +3,7 @@ from sqlalchemy.schema import *
 from sqlalchemy.sql import *
 import sqlalchemy.util as util
 import tables
-import string, sys
+import string, sys, time
 
 """a more advanced example of basic_tree.py.  illustrates MapperExtension objects which
 add application-specific functionality to a Mapper object."""
@@ -79,7 +79,7 @@ class TreeLoader(MapperExtension):
         if instance.root is instance:
             mapper.primarytable.update(TreeNode.c.id==instance.id, values=dict(root_node_id=instance.id)).execute()
             instance.root_id = instance.id
-    def append_result(self, mapper, row, imap, result, instance, populate_existing=False):
+    def append_result(self, mapper, row, imap, result, instance, isnew, populate_existing=False):
         """runs as results from a SELECT statement are processed, and newly created or already-existing
         instances that correspond to each row are appended to result lists.  This method will only
         append root nodes to the result list, and will attach child nodes to their appropriate parent
@@ -88,8 +88,9 @@ class TreeLoader(MapperExtension):
         if instance.parent_id is None:
             result.append(instance)
         else:
-            parentnode = imap[mapper.identity_key(instance.parent_id)]
-            parentnode.children.append(instance, _mapper_nohistory=True)
+            if isnew or populate_existing:
+                parentnode = imap[mapper.identity_key(instance.parent_id)]
+                parentnode.children.append(instance, _mapper_nohistory=True)
         return False
             
 class TreeData(object):
index 3c144afe60d3e88c5c730457ddc314b27eaf4a71..e82c8ee598d8172c056c5e7f1eece92841234912 100644 (file)
@@ -4,6 +4,7 @@ import sqlalchemy.engine
 #engine = sqlalchemy.engine.create_engine('sqlite', ':memory:', {}, echo = True)
 engine = sqlalchemy.engine.create_engine('postgres', {'database':'test', 'host':'127.0.0.1', 'user':'scott', 'password':'tiger'}, echo=True)
 
+
 """create the treenodes table.  This is ia basic adjacency list model table.
 One additional column, "root_node_id", references a "root node" row and is used
 in the 'byroot_tree' example."""
index 74c2b53666031ec330e87d17d33569ebc571ddd2..1d0349a07b7069a6e1f982131ed34f557501f06b 100644 (file)
@@ -23,6 +23,10 @@ import sqlalchemy.schema as schema
 import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
 from sqlalchemy.ansisql import *
+try:
+    import psycopg2 as psycopg
+except:
+    import psycopg
 
 class PGNumeric(sqltypes.Numeric):
     def get_col_spec(self):
@@ -67,6 +71,7 @@ class PGSQLEngine(ansisql.ANSISQLEngine):
     def __init__(self, opts, module = None, **params):
         if module is None:
             self.module = __import__('psycopg2')
+            #self.module = psycopg
         else:
             self.module = module
         self.opts = opts or {}
index 787cfd27e610a3731daab91a4bc680f9d126d7f5..5f65f02942d28159a3dabb0b84c2498a3af03fe2 100644 (file)
@@ -518,6 +518,7 @@ class Mapper(object):
         if objectstore.uow().has_key(identitykey):
             instance = objectstore.uow()._get(identitykey)
 
+            isnew = False
             if populate_existing:
                 isnew = not imap.has_key(identitykey)
                 if isnew:
@@ -525,7 +526,7 @@ class Mapper(object):
                 for prop in self.props.values():
                     prop.execute(instance, row, identitykey, imap, isnew)
 
-            if self.extension.append_result(self, row, imap, result, instance, populate_existing=populate_existing):
+            if self.extension.append_result(self, row, imap, result, instance, isnew, populate_existing=populate_existing):
                 if result is not None:
                     result.append_nohistory(instance)
 
@@ -561,7 +562,7 @@ class Mapper(object):
         for prop in self.props.values():
             prop.execute(instance, row, identitykey, imap, isnew)
 
-        if self.extension.append_result(self, row, imap, result, instance, populate_existing=populate_existing):
+        if self.extension.append_result(self, row, imap, result, instance, isnew, populate_existing=populate_existing):
             if result is not None:
                 result.append_nohistory(instance)
             
@@ -1128,7 +1129,7 @@ class BinaryVisitor(sql.ClauseVisitor):
 class MapperExtension(object):
     def create_instance(self, mapper, row, imap, class_):
         return None
-    def append_result(self, mapper, row, imap, result, instance, populate_existing=False):
+    def append_result(self, mapper, row, imap, result, instance, isnew, populate_existing=False):
         return True
     def after_insert(self, mapper, instance):
         pass
index 8f7509f5e5269e0ce299f506ee91daafa9219567..4fe35272b8914c60b55ada5c0ba584ed08dc5f7d 100644 (file)
@@ -431,20 +431,18 @@ class UOWTask(object):
         """executes this UOWTask.  saves objects to be saved, processes all dependencies
         that have been registered, and deletes objects to be deleted. """
         if self.circular is not None:
-            print "CIRCULAR !"
             self.circular.execute(trans)
-            print "CIRCULAR DONE !"
             return
 
-        print "task " + str(self) + " tosave: " + repr(self.tosave_objects())
+#        print "task " + str(self) + " tosave: " + repr(self.tosave_objects())
         self.mapper.save_obj(self.tosave_objects(), trans)
         for dep in self.save_dependencies():
             (processor, targettask, isdelete) = dep
             processor.process_dependencies(targettask, [elem.obj for elem in targettask.tosave_elements()], trans, delete = False)
-            print "processed dependencies on " + repr([elem.obj for elem in targettask.tosave_elements()])
#           print "processed dependencies on " + repr([elem.obj for elem in targettask.tosave_elements()])
         for element in self.tosave_elements():
             if element.childtask is not None:
-                print "execute elem childtask " + str(element.childtask)
+#                print "execute elem childtask " + str(element.childtask)
                 element.childtask.execute(trans)
         for dep in self.delete_dependencies():
             (processor, targettask, isdelete) = dep
@@ -553,6 +551,7 @@ class UOWTask(object):
         if self.circular is not None:
             s += " Circular Representation:"
             s += self.circular.dump(indent + "  ")
+            s += "\n----------------------"
             return s
         saveobj = self.tosave_elements()
         if len(saveobj) > 0:
index 1425d231bb854f83f2d1ddbfdf039c163a90146b..da5e7c7e82df5eb761d9fc44dd66518c957c3ba8 100644 (file)
@@ -16,7 +16,7 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 __ALL__ = ['OrderedProperties', 'OrderedDict']
-import thread, weakref, UserList
+import thread, weakref, UserList,string
 
 class OrderedProperties(object):
     """an object that maintains the order in which attributes are set upon it.
@@ -399,7 +399,6 @@ class DependencySorter(object):
                     childnode.parent.children.append(parentnode)
                 parentnode.children.append(childnode)
                 childnode.parent = parentnode
-            #print str(head)
 
         # go through the total list of items.  for those 
         # that had no dependency tuples, and therefore are not
@@ -417,5 +416,6 @@ class DependencySorter(object):
                     n = DependencySorter.Node(item)
                     head.children.append(n)
                     n.parent = head
+        #print str(head)
         return head
             
\ No newline at end of file