|
From: <de...@us...> - 2002-12-14 02:13:48
|
Update of /cvsroot/pymerase/pymerase
In directory sc8-pr-cvs1:/tmp/cvs-serv11116
Modified Files:
ClassMembers.py
Log Message:
Add functions for returning a foreign key name.
move CreateAssociations from parseXMI as it's now shared between
parseXMI and parseGenexTableDTD.
Index: ClassMembers.py
===================================================================
RCS file: /cvsroot/pymerase/pymerase/ClassMembers.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ClassMembers.py 12 Dec 2002 20:54:25 -0000 1.14
--- ClassMembers.py 14 Dec 2002 02:13:44 -0000 1.15
***************
*** 188,191 ****
--- 188,225 ----
return self.primaryKey
+ def createAssociation(pymeraseConfig, thisEnd, otherEnd, associationName=None, associationUUID=None):
+ """Helper function to create association with provided associationEnds
+ """
+ # Make sure the AssociationEnds are bound to an Association
+ if associationName is None:
+ associationName = thisEnd.getName(None) + otherEnd.getName(None)
+
+ if associationUUID is None:
+ associationUUID = thisEnd.getName(None) + otherEnd.getName(None)
+
+ if thisEnd.getAssociation() is None and otherEnd.getAssociation() is None:
+ print "no associations"
+ association = Association(pymeraseConfig, associationName)
+ association.setUUID(associationUUID)
+ thisEnd.setAssociation(association)
+ association.addAssociationEnd(thisEnd)
+ otherEnd.setAssociation(association)
+ association.addAssociationEnd(otherEnd)
+ # since we always construct both ends at a time is this code actually
+ # needed?
+ elif thisEnd.getAssociation() is None:
+ print "this is none"
+ association = otherEnd.getAssociation()
+ thisEnd.setAssociation(association)
+ association.addAssociationEnd(thisEnd)
+ elif otherEnd.getAssociation() is None:
+ print "other is none"
+ association = thisEnd.getAssociation()
+ otherEnd.setAssociation(association)
+ association.addAssociationEnd(otherEnd)
+ else:
+ # everything is already set up
+ pass
+
class Association(ModelElement):
"""Describe the meta info regarding the between two objects
***************
*** 412,415 ****
--- 446,450 ----
self.primaryKeyName = None
self.primaryKeyConstructed = 0
+ self.foreignKeyName = None
self.security = []
self.indices = []
***************
*** 646,660 ****
def getPrimaryKeyName(self, translatorName):
"""return primary key name
"""
! if not self.primaryKeyConstructed:
self.setPrimaryKeyName()
! if self.primaryKeyName is not None:
! mangler = self.config.getNameMangler(translatorName)
! return mangler.mangle(self.primaryKeyName)
else:
! # we inherit from some other class (which has the primary key)
! return None
def getIndices(self):
return []
--- 681,724 ----
def getPrimaryKeyName(self, translatorName):
"""return primary key name
+
+ Default to user defined key otherwise use the primary key name
+ of the base class.
"""
!
! if self.primaryKeyName is not None:
! primaryKeyName = self.primaryKeyName
! elif self.isRootClass() and not self.primaryKeyConstructed:
self.setPrimaryKeyName()
+ primaryKeyName = self.primaryKeyName
+ else:
+ return self.getBasePrimaryKeyName(translatorName)
+
+ mangler = self.config.getNameMangler(translatorName)
+ return mangler.mangle(self.primaryKeyName)
!
! def setForeignKeyName(self, keyName):
! """Set the foreign key name that should be used for this class.
! """
! self.foreignKeyName = keyName
!
! def getForeignKeyName(self, translatorName):
! """Return the foreign key name that should be used for this class.
! """
! mangler = self.config.getNameMangler(translatorName)
!
! if self.foreignKeyName is not None:
! return mangler.mangle(self.foreignKeyName)
! elif not self.isRootClass():
! rootClass = self.getRootClass()
! return rootClass.getForeignKeyName(translatorName)
else:
! warn("No foreign key name set for %s, making one up" % (self.name),
! InfoWarning)
! primaryKeyName = self.getPrimaryKeyName(None)
! self.foreignKeyName = util.NameMangling.RelationalKey().getForeignKey(primaryKeyName)
! return self.foreignKeyName
+
def getIndices(self):
return []
|