public static function getClassDescriptor($name)
 {
     $name = \blaze\lang\String::asNative($name);
     if (self::$classDescriptors === null) {
         self::$classDescriptors = array();
     }
     //new \blaze\collections\map\HashMap();
     $cd = isset(self::$classDescriptors[$name]) ? self::$classDescriptors[$name] : null;
     //self::$classDescriptors->get($name);
     if ($cd === null) {
         $cd = new ClassDescriptor();
         $cd->setName($name);
         self::$classDescriptors[$name] = $cd;
         //self::$classDescriptors->put($name, $cd);
     }
     return $cd;
 }
 /**
  *
  * @param \blaze\persistence\meta\ClassDescriptor $config
  * @param File $file
  */
 public function save(\blaze\persistence\meta\ClassDescriptor $config, $file)
 {
     $f = null;
     if ($file instanceof \blaze\io\File) {
         $f = $file;
     } else {
         $f = new \blaze\io\File(\blaze\lang\String::asNative($file));
     }
     $doc = new \DOMDocument();
     $root = $doc->createElement('persistence-mapping');
     $doc->appendChild($root);
     $node = $doc->createElement('class');
     $root->appendChild($node);
     AttributeUtil::set($node, 'package', $config->getPackage());
     AttributeUtil::set($node, 'name', $config->getName());
     AttributeUtil::set($node, 'schema', $config->getTableDescriptor()->getSchema());
     AttributeUtil::set($node, 'table', $config->getTableDescriptor()->getName());
     foreach ($config->getIdentifiers() as $member) {
         $this->saveId($node, $doc, $member);
     }
     foreach ($config->getSingleFields() as $member) {
         $this->saveField($node, $doc, $member);
     }
     foreach ($config->getCollectionFields() as $member) {
         $this->saveCollection($node, $doc, $member);
     }
     $doc->save($f->getAbsolutePath());
 }
Beispiel #3
0
 private function recursiveColumnLookup(\blaze\persistence\meta\ClassDescriptor $classDesc, $parts)
 {
     $part = array_shift($parts);
     foreach ($classDesc->getIdentifiers() as $member) {
         if ($member->getFieldDescriptor()->getName()->toNative() === $part) {
             return $member->getFieldDescriptor()->getColumnDescriptor();
         }
     }
     foreach ($classDesc->getSingleFields() as $member) {
         if ($member->getName()->toNative()) {
             return $member->getColumnDescriptor();
         }
     }
     foreach ($classDesc->getCollectionFields() as $member) {
         if ($member->getFieldDescriptor()->getName()->toNative()) {
             return $member->getColumnDescriptor();
         }
     }
     return null;
 }
 private function loadMapping(\blaze\persistence\meta\ClassDescriptor $class)
 {
     $fullClassName = $class->getPackage() . '\\' . $class->getName();
     $this->mapping[$fullClassName] = $class;
 }
 private function makeOneToMany(\blaze\persistence\meta\ClassDescriptor $elem, $column, $ident)
 {
     $property = new \blaze\persistence\meta\CollectionFieldDescriptor();
     $field = new \blaze\persistence\meta\SingleFieldDescriptor();
     $property->setFieldDescriptor($field);
     $ident = $ident > 0 ? '' . $ident : '';
     $field->setName($this->getMemberName($column->getTable()->getTableName() . 's' . $ident));
     //$property->setInverse('true');
     $col = new \blaze\persistence\meta\ColumnDescriptor();
     $col->apply($column);
     $property->setColumnDescriptor($col);
     $property->setClassDescriptor(\blaze\persistence\meta\ClassDescriptor::getClassDescriptor($this->getClassName($column->getTable()->getTableName())));
     $elem->addCollectionField($property);
 }