[rhmessaging-commits] rhmessaging commits: r1204 - mgmt/mint.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Thu Nov 1 13:35:07 EDT 2007
Author: nunofsantos
Date: 2007-11-01 13:35:06 -0400 (Thu, 01 Nov 2007)
New Revision: 1204
Modified:
mgmt/mint/schemaparser.py
Log:
add stats foreign key relation
Modified: mgmt/mint/schemaparser.py
===================================================================
--- mgmt/mint/schemaparser.py 2007-11-01 17:13:28 UTC (rev 1203)
+++ mgmt/mint/schemaparser.py 2007-11-01 17:35:06 UTC (rev 1204)
@@ -1,4 +1,4 @@
-import mllib
+import qpid.mllib
from sqlobject import connectionForURI, sqlhub, MixedCaseUnderscoreStyle
@@ -27,7 +27,7 @@
self.startTable(name, type)
for elem in elements:
self.generateColumn(elem)
- self.endTable()
+ self.endTable(name, type)
def startTable(self, name, type):
if (type == "config"):
@@ -36,7 +36,9 @@
actualName = name + "_stats"
self.sqlOutput += "CREATE TABLE " + actualName + " (\n"
self.sqlOutput += " id BIGSERIAL PRIMARY KEY,\n"
- if (type == "inst"):
+ if (type == "config"):
+ self.sqlOutput += " " + name + "_stats_id BIGINT,\n"
+ else:
self.sqlOutput += " " + name + "_id BIGINT REFERENCES " + name + " ,\n"
self.generateTimestampColumn("rec")
if (type == "config"):
@@ -59,15 +61,17 @@
params = ""
if (elem["@name"].endswith("Ref")):
foreignKeyTable = "mgmt_" + actualName.replace("_ref", "")
- self.sqlOutput += " " + foreignKeyTable + "_id BIGINT REFERENCES " + foreignKeyTable + " ,\n"
+ self.sqlOutput += " " + foreignKeyTable + "_id BIGINT REFERENCES " + foreignKeyTable + ",\n"
else:
self.sqlOutput += " " + actualName + " " + self.dataTypesMap[actualType] + params + ",\n"
if (elem["@type"].endswith("_wm") and suffix == ""):
self.generateColumn(elem, "High")
self.generateColumn(elem, "Low")
- def endTable(self):
+ def endTable(self, name, type):
self.sqlOutput = self.sqlOutput[:-2] + "\n);\n\n"
+ if (type == "inst"):
+ self.sqlOutput += "ALTER TABLE " + name + " ADD FOREIGN KEY (" + name + "_stats_id) REFERENCES " + name + "_stats;\n\n"
def getCode(self):
return self.sqlOutput
@@ -93,14 +97,15 @@
def generate(self, name, elements):
name = self.attrNameFromDbColumn(name)
+ self.startClass(name + "Stats")
+ self.endClass()
self.startClass(name)
for elem in elements:
self.generateMethod(elem)
- self.endClass()
- self.startClass(name + "Stats")
- self.endClass()
+ self.endClass(name)
def generateForeignKeys(self, name, elements):
+ dbName = name
name = self.attrNameFromDbColumn(name)
for elem in elements:
refName = elem["@name"]
@@ -123,7 +128,10 @@
self.pythonOutput += comment
self.pythonOutput += " pass\n\n"
- def endClass(self):
+ def endClass(self, name=""):
+ if (name != "" and not name.endswith("Stats")):
+ # add missing attribute (not added correctly with SqlObject 0.7.7; may need to be removed in later versions)
+ self.pythonOutput += " _SO_class_" + self.style.pythonAttrToDBColumn(name).capitalize() + "_stats = " + name + "Stats()\n"
self.pythonOutput += "\n"
def getCode(self):
@@ -147,7 +155,7 @@
self.sqlGen = SqlGenerator(self.style)
def parseConfigFile(self):
- config = mllib.xml_parse("config.xml")
+ config = qpid.mllib.xml_parse("config.xml")
configOptions = config.query["config/configOption"]
for opt in configOptions:
self.options[opt["@name"]] = opt["@value"]
@@ -157,7 +165,7 @@
sqlhub.processConnection = conn
sqlFile = open(self.options["sqlOutput"], "w")
pythonFile = open(self.options["pythonOutput"], "w")
- schema = mllib.xml_parse(self.options["schemaXML"])
+ schema = qpid.mllib.xml_parse(self.options["schemaXML"])
objects = schema.query["schema/object"]
for obj in objects:
actualName = "mgmt_" + obj["@name"]
More information about the rhmessaging-commits
mailing list