|
From: <de...@us...> - 2003-09-10 02:08:25
|
Update of /cvsroot/pymerase/pymerase/pymerase/input
In directory sc8-pr-cvs1:/tmp/cvs-serv10514
Modified Files:
parseXMI.py
Log Message:
Make model attributes private.
Add support for knowing which association end has the foreign key.
Index: parseXMI.py
===================================================================
RCS file: /cvsroot/pymerase/pymerase/pymerase/input/parseXMI.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** parseXMI.py 9 Sep 2003 21:50:15 -0000 1.26
--- parseXMI.py 10 Sep 2003 02:08:21 -0000 1.27
***************
*** 107,118 ****
def __init__(self, pymeraseConfig, name=None):
AssociationEnd.__init__(self, pymeraseConfig, name)
! self.attributeName = None
!
! def setAttributeName(self, value):
! self.attributeName = value
def getAttributeName(self, translatorName):
! mangler = self.config.getNameMangler(translatorName)
! if self.attributeName is None:
#return "TargetAttributeName"
--- 107,115 ----
def __init__(self, pymeraseConfig, name=None):
AssociationEnd.__init__(self, pymeraseConfig, name)
! self.setAttributeName(None)
def getAttributeName(self, translatorName):
! mangler = self.__config.getNameMangler(translatorName)
! if self.getAttributeName() is None:
#return "TargetAttributeName"
***************
*** 122,126 ****
attributeName = self.getType().getBasePrimaryKeyName()
else:
! attributeName = self.getName
attributeName = self.getType().getRootClass().getName(None)+"_fk"
else:
--- 119,123 ----
attributeName = self.getType().getBasePrimaryKeyName()
else:
! attributeName = self.getName()
attributeName = self.getType().getRootClass().getName(None)+"_fk"
else:
***************
*** 158,162 ****
"""Given a name return its ClassAttribute structure
"""
! if not self.primaryKeyConstructed:
self.setPrimaryKeyName()
--- 155,159 ----
"""Given a name return its ClassAttribute structure
"""
! if not self.isPrimaryKeyConstructed():
self.setPrimaryKeyName()
***************
*** 167,171 ****
definition.
"""
! if not self.primaryKeyConstructed:
self.setPrimaryKeyName()
--- 164,168 ----
definition.
"""
! if not self.isPrimaryKeyConstructed():
self.setPrimaryKeyName()
***************
*** 176,180 ****
# always return true
return 1
!
def setPrimaryKeyName(self, name=None):
"""Indicate what field in the table should be the primary key.
--- 173,177 ----
# always return true
return 1
!
def setPrimaryKeyName(self, name=None):
"""Indicate what field in the table should be the primary key.
***************
*** 194,213 ****
# FIXME: we also need to allow the user some method of defining
# FIXME: the primary key name
! if self.primaryKeyName is None:
# Construct a primary key object
! self.primaryKeyName = self.name + "_pk"
! primaryKey = ClassAttribute(self.config, self.primaryKeyName)
primaryKey.setType(PymeraseType('serial'))
primaryKey.setPrimaryKey(1)
self.addAttribute(primaryKey, insert=1)
else:
! self.primaryKeyName = name
! warn("Setting primary_key_name: %s" % ( self.primaryKeyName ),
DebugWarning)
# well actually this indicates that we tried to construct a key,
# if it's not needed we don't bother trying again.
! self.primaryKeyConstructed = 1
--- 191,210 ----
# FIXME: we also need to allow the user some method of defining
# FIXME: the primary key name
! if self._ClassMetaInfo__primaryKeyName is None:
# Construct a primary key object
! self.setPrimaryKeyName(self.getName(None) + "_pk")
! primaryKey = ClassAttribute(self.config, self._ClassMetaInfo__primaryKeyName)
primaryKey.setType(PymeraseType('serial'))
primaryKey.setPrimaryKey(1)
self.addAttribute(primaryKey, insert=1)
else:
! self._ClassMetaInfo__primaryKeyName = name
! warn("Setting primary_key_name: %s" % ( self._ClassMetaInfo__primaryKeyName ),
DebugWarning)
# well actually this indicates that we tried to construct a key,
# if it's not needed we don't bother trying again.
! self.setPrimaryKeyConstructed(1)
***************
*** 218,222 ****
## # check to see if the field is going to automatically get an index
## column_name = index.getColumnName()
! ## column_field = self.attributes.get(column_name, None)
## if column_field is not None :
## if column_field.isUnique():
--- 215,219 ----
## # check to see if the field is going to automatically get an index
## column_name = index.getColumnName()
! ## column_field = self.__attributes.get(column_name, None)
## if column_field is not None :
## if column_field.isUnique():
***************
*** 229,244 ****
## DebugWarning)
## # tag field as being indexed, and append it to the list of indexes.
! ## self.indices.append(index)
##
## def getIndices(self):
! ## return self.indices
##
## def getSecurity(self):
! ## return self.security
##
## def appendSecurity(self, attributes):
## """Add information about user security to table
## """
! ## self.security.append(XMISecurity(attributes))
# End extended classes
--- 226,241 ----
## DebugWarning)
## # tag field as being indexed, and append it to the list of indexes.
! ## self.__indices.append(index)
##
## def getIndices(self):
! ## return self.__indices
##
## def getSecurity(self):
! ## return self.__security
##
## def appendSecurity(self, attributes):
## """Add information about user security to table
## """
! ## self.__security.append(XMISecurity(attributes))
# End extended classes
***************
*** 273,276 ****
--- 270,285 ----
# Handle: one to many
# put the key in the other end
+ hasKey = otherEnd
+ elif thisEnd.getMultiplicity() != fkeyTypes.OneToOne:
+ # Handle: many to one
+ # put the key in this end
+ hasKey = thisEnd
+ else:
+ if thisEnd.getUUID() <= otherEnd.getUUID():
+ hasKey = thisEnd
+ else:
+ hasKey = otherEnd
+
+ if hasKey == otherEnd:
#fkeyName = thisEndType.getRootClass().getName(None) + "_fk"
# FIXME: should we use the association name or the primary key name?
***************
*** 283,289 ****
fkeyName)
otherEndType.addAttribute(foreignKey)
else:
- # Handel: many to one or one to one
- # put the key in this end
# FIXME: should we use the association name or the primary key name?
#fkeyName = otherEndType.getRootClass().getName(None) + "_fk"
--- 292,297 ----
fkeyName)
otherEndType.addAttribute(foreignKey)
+ otherEnd.setHasForeignKey(1)
else:
# FIXME: should we use the association name or the primary key name?
#fkeyName = otherEndType.getRootClass().getName(None) + "_fk"
***************
*** 295,300 ****
fkeyName)
thisEndType.addAttribute(foreignKey)
!
!
return classesInModel
--- 303,308 ----
fkeyName)
thisEndType.addAttribute(foreignKey)
! thisEnd.setHasForeignKey(1)
!
return classesInModel
***************
*** 346,354 ****
association = createAssociation(pymeraseConfig, thisEnd, otherEnd, attribute.getName(None))
!
# modify current attribute to be of FK type?
! attribute.setType(PymeraseType('integer'))
# FIXME: converting to fk type needs to have a more general solution
! attribute.setName(attribute.getName(None) + "_fk")
else:
warn("Attribute %s of type %s and uuid %s in class %s was not defined in model" % (
--- 354,362 ----
association = createAssociation(pymeraseConfig, thisEnd, otherEnd, attribute.getName(None))
! thisEndType.removeAttributeByName(attribute.getName(None))
# modify current attribute to be of FK type?
! #attribute.setType(PymeraseType('integer'))
# FIXME: converting to fk type needs to have a more general solution
! #attribute.setName(attribute.getName(None) + "_fk")
else:
warn("Attribute %s of type %s and uuid %s in class %s was not defined in model" % (
|