19 public function getClassMap($module, $name, $associative=FALSE)
23 if (isset($this->classMaps[$module][$name]))
25 return $this->classMaps[$module][$name];
27 if (isset($this->xmlMaps[$module][$name]))
29 $xml = $this->xmlMaps[$module][$name];
33 $file =
$MIOLO->GetModulePath($module,
'db/map/'.$name.
'.xml');
34 if (! file_exists( $file ))
36 $file =
$MIOLO->GetModulePath($module,
'classes/map/'.$name.
'.xml');
39 $tree = $xmlTree->getTree();
40 $xml = $xmlTree->getXMLTreeElement($tree);
41 $this->xmlMaps[$module][$name] = $xml;
44 $MIOLO->UsesBusiness($module,$name);
48 $database = (string)$xml->databaseName;
49 $className = (string)$xml->moduleName . (
string)$xml->className;
50 $cm =
new ClassMap($className, $database, $this->broker);
53 $tableMap->setName((
string)$xml->tableName);
54 $tableMap->setDatabaseMap($dm);
55 if (isset($xml->extends))
57 $superClassName = (string)$xml->extends->moduleName . (
string)$xml->extends->className;
58 $cm->setSuperClass($superClassName, $this->broker);
60 $attributes = $this->getAsArray($xml->attribute);
61 foreach($attributes as $attr)
64 $converter = $this->
getConverter(isset($attr->converter) ? $attr->converter :
null);
65 if (isset($attr->attributeIndex))
67 $am->setIndex($attr->attributeIndex);
69 if (isset($attr->columnName))
71 $colm =
new ColumnMap($attr->columnName, $tableMap, $converter);
73 if (isset($attr->key))
75 if ($attr->key ==
'primary')
77 $colm->setKeyType(
'primary');
78 if (isset($attr->idgenerator))
80 $idGenerator = $attr->idgenerator;
81 $colm->setIdGenerator($idGenerator);
84 elseif ($attr->key ==
'foreign')
86 $colm->setKeyType(
'foreign');
91 $colm->setKeyType(
'none');
93 $am->setColumnMap($colm);
95 $am->setProxy(isset($attr->proxy) ? $attr->proxy :
null);
96 if ((isset($attr->reference)) && ($cm->getSuperClass() != NULL) )
98 $referenceAttribute = $cm->getSuperClass()->getAttributeMap($attr->reference);
99 if ($referenceAttribute)
100 $am->setReference($referenceAttribute);
102 if ($attr->attributeName ==
'timestamp')
104 $cm->setTimestampAttributeMap($am);
108 $cm->addAttributeMap($am);
111 $this->classMaps[$module][$name] = $cm;
114 if (isset($xml->association))
117 $associations = $this->getAsArray($xml->association);
118 foreach($associations as $assoc)
120 $toModule = $assoc->toClassModule;
121 $toName = $assoc->toClassName;
122 $toClassMap = $this->
getClassMap($toModule, $toName);
124 $am->setForClass($toClassMap);
125 $am->setTargetName($assoc->target);
126 $am->setTarget($fromClassMap->getAttributeMap($assoc->target));
127 $am->setDeleteAutomatic($assoc->deleteAutomatic);
128 $am->setSaveAutomatic($assoc->saveAutomatic);
129 $am->setRetrieveAutomatic($assoc->retrieveAutomatic);
130 $am->setJoinAutomatic($assoc->joinAutomatic);
131 if (isset($assoc->indexAttribute))
133 $am->setIndexAttribute($assoc->indexAttribute->indexAttributeName);
135 $am->setInverse($assoc->inverse);
136 $am->setCardinality($assoc->cardinality);
137 if ($assoc->cardinality ==
'manyToMany')
139 $associativeModule = $assoc->associativeClassModule;
140 $associativeName = $assoc->associativeClassName;
141 $associativeClassMap = $this->
getClassMap($associativeModule, $associativeName,
true);
142 $am->setAssociativeClass($associativeClassMap);
143 foreach($assoc->direction as $direction)
145 $am->addDirection($direction);
150 $entries = $this->getAsArray($assoc->entry);
151 foreach($entries as $entry)
153 $fromAttribute = $entry->fromAttribute;
154 $toAttribute = $entry->toAttribute;
155 if ($am->isInverse())
157 $e =
new UDAMapEntry($toClassMap->getAttributeMap($fromAttribute), $fromClassMap->getAttributeMap($toAttribute));
161 $e =
new UDAMapEntry($fromClassMap->getAttributeMap($fromAttribute), $toClassMap->getAttributeMap($toAttribute));
166 if (isset($assoc->orderAttribute))
168 $orderEntry = array();
169 $orderAttributes = $this->getAsArray($assoc->orderAttribute);
170 foreach($orderAttributes as $order)
172 $ascend = ($order->orderAttributeDirection ==
'ascend');
174 $attributeMap = $am->getForClass()->getAttributeMap($order->orderAttributeName);
175 $orderEntry[] =
new OrderEntry($attributeMap, $ascend);
177 if (count($orderEntry))
179 $am->setOrderAttributes($orderEntry);
182 $fromClassMap->putAssociationMap($am);