|
From: <de...@us...> - 2003-09-09 23:14:16
|
Update of /cvsroot/pymerase/pymerase/pymerase
In directory sc8-pr-cvs1:/tmp/cvs-serv10738
Modified Files:
ClassMembers.py
Log Message:
Add extra error checking to test to make sure something is not both a
primary and foreign key.
Removed some dead code.
Index: ClassMembers.py
===================================================================
RCS file: /cvsroot/pymerase/pymerase/pymerase/ClassMembers.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** ClassMembers.py 25 Jul 2003 00:40:34 -0000 1.26
--- ClassMembers.py 9 Sep 2003 23:14:12 -0000 1.27
***************
*** 185,188 ****
--- 185,189 ----
"""
return self.defined
+
def __str__(self):
return str(self.__dict__)
***************
*** 242,250 ****
def isIndexed(self):
return self.indexed
def setPrimaryKey(self, value):
"""Flag this attribute as being a primary key
"""
! self.primaryKey = parseBoolValue(value)
def isPrimaryKey(self):
--- 243,257 ----
def isIndexed(self):
return self.indexed
+
+ # FIXME: can something be a primary key and a foreign key?
def setPrimaryKey(self, value):
"""Flag this attribute as being a primary key
"""
! flag = parseBoolValue(value)
! if self.isForeignKey() and flag:
! raise ValueError("An attribute cannot be both a primary key and a foreign key")
! else:
! self.primaryKey = flag
def isPrimaryKey(self):
***************
*** 256,260 ****
"""Flag this attribute as being a foreign key
"""
! self.foreignKey = parseBoolValue(value)
def isForeignKey(self):
--- 263,271 ----
"""Flag this attribute as being a foreign key
"""
! flag = parseBoolValue(value)
! if self.isPrimaryKey() and flag:
! raise ValueError("An attribute cannot be both a primary key and a foreign key")
! else:
! self.foreignKey = flag
def isForeignKey(self):
***************
*** 299,302 ****
--- 310,315 ----
pass
+ return association
+
class Association(ModelElement):
"""Describe the meta info regarding the between two objects
***************
*** 323,328 ****
def removeAssociationEnd(self, associationEnd):
! if self.association.has_key(associationEnd):
! del self.association[associationEnd]
else:
raise ValueError("Attempted to remove association end that is not part"+
--- 336,342 ----
def removeAssociationEnd(self, associationEnd):
! if associationEnd in self.associationEnds:
! self.associationEnds.remove(associationEnd)
! associationEnd.setAssociation(None)
else:
raise ValueError("Attempted to remove association end that is not part"+
***************
*** 382,386 ****
"""set the Association this AssociationEnd is attached to
"""
! if isinstance(value, Association):
if self.association != value:
self.association = value
--- 396,402 ----
"""set the Association this AssociationEnd is attached to
"""
! if value is None:
! self.association = None
! elif isinstance(value, Association):
if self.association != value:
self.association = value
***************
*** 471,511 ****
return mangler.createAppender(self.getName(translatorName))
-
- # def setClassToCreate(self, classReference):
- # """Sets the object that this foreign key link should create
- # """
- ### # if we're using the class to create name as the name of this object
- ### # update it if it gets changed while resolving foreign keys
- ### if self.classToCreate is not None and self.name == self.classToCreate.name:
- ### self.setName(classReference.getName(None))
- ###
- # self.classToCreate = classReference
- #
- # def getClassToCreate(self):
- # """Returns a reference to the ClassMetaInfo object for the class
- # that this association should create.
- # """
- # return self.classToCreate
- #
- # def getClassToCreateName(self, translatorName):
- # """Get the name of what object this association should create.
- #
- # The class to create can be either the foreign or local table depending
- # on which table needs to be queried.
- # """
- # return self.classToCreate.getName(translatorName)
- #
- # def setContainingClass(self, value):
- # self.containingClass = value
- #
- # def getContainingClass(self):
- # return self.containingClass
- #
- # def getContainingClassName(self, translatorName):
- # """Returns the name of the table that has the foreign key local to it
- # """
- # mangler = self.config.getNameMangler(translatorName)
- # return mangler.mangle(self.containingClass.getName(None))
- #
class ClassMetaInfo(ModelElement):
--- 487,490 ----
***************
*** 578,627 ****
return self.associationEnds
- # def getAssociations(self):
- # """Return list of object associations in the order declared in the object
- # definition.
- # """
- # return self.associations
- #
- # def addAssociation(self, association):
- # """Add association to list and determine if we need to add to others as
- # well.
- # """
- # # FIXME: This is seeming specialized for the table.dtd version
- # self.associations.append(association)
- #
- # localClassName = association.getContainingClassName(None)
- # targetClassName = association.getTargetClassName(None)
- # warn("TargetClassName: %s" % (targetClassName), DebugWarning)
- # warn("LocalClassName : %s" % (localClassName), DebugWarning)
- #
- # localAssociationName = association.getLocalAssociationName(None)
- # foreignAssociationName = association.getForeignAssociationName(None)
- #
- # # return this association if it should be appended to another
- # # list of class associations as well (genex related, maybe mage as well)
- # if self.name != targetClassName:
- # return (self.name, copy.deepcopy(association))
- # # special case self referential objects
- # elif targetClassName == localClassName:
- # reversed = copy.deepcopy(association)
- # # swap association names
- # tempAssociation = reversed.getLocalAssociationName(None)
- # reversed.setLocalAssociationName(reversed.getForeignAssociationName(None))
- # reversed.setForeignAssociationName(tempAssociation)
- # # swap key/columns
- # attribute = reversed.getTargetAttributeName(None)
- # reversed.setTargetAttributeName(reversed.getAssociationAttributeName(None))
- # reversed.setAssociationAttributeName(attribute)
- #
- # # swap multiplicity
- # if reversed.getMultiplicity() == fkeyTypes.OneToOne:
- # reversed.setMultiplicity(fkeyTypes.ManyToOne)
- # elif reversed.getMultiplicity() == fkeyTypes.ManyToOne:
- # reversed.setMultiplicity(fkeyTypes.OneToOne)
- #
- # return (self.name, reversed)
- # else:
- # return None
def getAttributeByName(self, name, translatorName):
--- 557,560 ----
|