Example #1
0
 public function __construct(Classmap $classMap, $index = NULL)
 {
     $this->classMap = $classMap;
     $this->baseObject = $this->classMap->getObject();
     $this->manager = PersistentManager::getInstance();
     $this->index = $index;
 }
 public static function getInstance($load_estragegy = NULL)
 {
     Logger::getInstance()->pm_log("PM::getInstance");
     if (!self::$instance) {
         // Definicion de estrategia de carga. Por defecto es Lazy.
         $po_loader = NULL;
         switch ($load_estragegy) {
             case self::LAZY_LOAD_ESTRATEGY:
                 YuppLoader::load("core.persistent", "LazyLoadStrategy");
                 $po_loader = new LazyLoadStrategy();
                 break;
             case self::CASCADE_LOAD_ESTRATEGY:
                 YuppLoader::load("core.persistent", "CascadeLoadStrategy");
                 $po_loader = new CascadeLoadStrategy();
                 break;
             default:
                 YuppLoader::load("core.persistent", "LazyLoadStrategy");
                 $po_loader = new LazyLoadStrategy();
                 break;
         }
         // /Definicion de estrategia de carga.
         self::$instance = new PersistentManager($po_loader);
     }
     return self::$instance;
 }
 public function queryAction()
 {
     $q = new Query();
     $q->addAggregation(SelectAggregation::AGTN_DISTINTC, 'p', 'nombre')->addFrom('hello_world_persona', 'p')->setCondition(Condition::GT('p', "edad", 25));
     $pm = PersistentManager::getInstance();
     $result = $pm->findByQuery($q);
     return $this->renderString(print_r($result, true));
 }
Example #4
0
 public function __construct(ClassMap $fromClassMap, $name)
 {
     $this->manager = PersistentManager::getInstance();
     $this->fromClassMap = $fromClassMap;
     $this->fromClassName = $fromClassMap->getName();
     $this->name = $name;
     $this->inverse = FALSE;
 }
Example #5
0
 public function __construct($name, $databaseName, \IPersistentManager $manager = null)
 {
     $this->name = $name;
     $p = strrpos($name, '\\');
     $this->namespace = substr($name, 0, $p);
     $this->databaseName = $databaseName;
     $this->manager = $manager ?: PersistentManager::getInstance();
     $this->db = $this->manager->getConnection($databaseName);
     $this->platform = $this->db->getPlatform();
     $this->hasTypedAttribute = FALSE;
 }
 public function __construct($classMap = NULL)
 {
     $this->manager = PersistentManager::getInstance();
     $this->setClassMap($classMap);
     // Fill tables with tableMaps
     // Create CriteriaCondition for the WHERE part of this criteria
     $this->whereCondition = $this->getNewCondition();
     //$this->whereCondition->setCriteria($this);
     // Create condition for the HAVING part of this criteria
     $this->havingCondition = $this->getNewCondition();
     //$this->havingCondition->setCriteria($this);
 }
 public function test1()
 {
     PersistentManager::getInstance()->generateAll();
     echo YuppConventions::tableName('Pagina') . "<br/>";
     /**
      * Resultado>
      * 
      * CREATE TABLE test_a004_pagina (id INT(11) DEFAULT 1 PRIMARY KEY, titulo VARCHAR(255) NULL, contenido MEDIUMTEXT NULL, class TEXT NOT NULL, deleted BOOL NOT NULL, owner_id INT(11) NULL);
      * 
      * CREATE TABLE test_a004_pagina_subpages_test_a004_pagina (id INT(11) DEFAULT 1 PRIMARY KEY, owner_id INT(11) NOT NULL, ref_id INT(11) NOT NULL, type INT(11) NOT NULL, deleted BOOL NOT NULL, class TEXT NOT NULL, ord INT(11) NULL);
      * 
      * ALTER TABLE test_a004_pagina_subpages_test_a004_pagina ADD FOREIGN KEY (owner_id) REFERENCES test_a004_pagina(id);
      * 
      * ALTER TABLE test_a004_pagina_subpages_test_a004_pagina ADD FOREIGN KEY (ref_id) REFERENCES test_a004_pagina(id);
      * 
      * ALTER TABLE test_a004_pagina ADD FOREIGN KEY (owner_id) REFERENCES test_a004_pagina(id);
      * 
      */
     // TODO: verificar si la tabla para Nariz y Cara fue creada.
     //$dal = DAL::getInstance();
     $dal = new DAL('tests');
     $this->assert($dal->tableExists(YuppConventions::tableName('Pagina')), 'TestCaseA004: Test generar tabla');
 }
 public static function find($select = '*', $where = '', $orderBy = '')
 {
     $className = get_called_class();
     $classMap = PersistentManager::getInstance()->getClassMap($className);
     $criteria = new RetrieveCriteria($classMap);
     $criteria->select($select)->where($where)->orderBy($orderBy);
     return $criteria;
 }
Example #9
0
 private function test1()
 {
     PersistentManager::getInstance()->generateAll();
     echo YuppConventions::tableName('Contenido1') . "<br/>";
     echo YuppConventions::tableName('Recipiente1') . "<br/>";
     echo YuppConventions::tableName('Vaso1') . "<br/>";
     /**
      * Resultado>
      * 
      * CREATE TABLE test_i006_contenido1 (id INT(11) DEFAULT 1 PRIMARY KEY, elemento VARCHAR(30) NULL, volumen FLOAT NULL, class TEXT NOT NULL, deleted BOOL NOT NULL);
      * 
      * CREATE TABLE test_i005_contenido (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   elemento VARCHAR(30) NULL,
      *   volumen FLOAT NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL
      * );
      * 
      * CREATE TABLE test_i006_vaso1 (id INT(11) DEFAULT 1 PRIMARY KEY, marca TEXT NULL, class TEXT NOT NULL, deleted BOOL NOT NULL, contenido_id INT(11) NULL, super_id_recipiente1 INT(11) NOT NULL);
      * 
      * CREATE TABLE test_i005_vaso (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   marca TEXT NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL,
      *   contenido_id INT(11) NULL,
      *   super_id_recipiente INT(11) NOT NULL
      * );
      * 
      * CREATE TABLE test_i006_recipiente1 (id INT(11) DEFAULT 1 PRIMARY KEY, material VARCHAR(30) NULL, capacidad FLOAT NULL, tieneTapa BOOL NULL, class TEXT NOT NULL, deleted BOOL NOT NULL);
      * 
      * CREATE TABLE test_i005_recipiente (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   material VARCHAR(30) NULL,
      *   capacidad FLOAT NULL,
      *   tieneTapa BOOL NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL
      * );
      * 
      * ALTER TABLE test_i006_vaso1 ADD FOREIGN KEY (super_id_recipiente1) REFERENCES test_i006_recipiente1(id);
      * 
      * ALTER TABLE test_i005_vaso
      *   ADD FOREIGN KEY (super_id_recipiente)
      *   REFERENCES test_i005_recipiente(id);
      * 
      * ALTER TABLE test_i006_vaso1 ADD FOREIGN KEY (contenido_id) REFERENCES test_i005_contenido(id);
      * 
      * ALTER TABLE test_i005_vaso
      *   ADD FOREIGN KEY (contenido_id)
      *   REFERENCES test_i005_contenido(id);
      */
     // TODO: verificar si la tabla para Nariz y Cara fue creada.
     //$dal = DAL::getInstance();
     $dal = new DAL('tests');
     if ($dal->tableExists(YuppConventions::tableName('Contenido1'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
     if ($dal->tableExists(YuppConventions::tableName('Recipiente1'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
     if ($dal->tableExists(YuppConventions::tableName('Vaso1'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
 }
Example #10
0
 public static function getTableName($className)
 {
     $manager = PersistentManager::getInstance();
     $classMap = $manager->getClassMap($className);
     return $classMap->getTableName();
 }
Example #11
0
 public function __construct()
 {
     $this->conn = PersistentManager::getInstance()->get_connection();
 }
 /**
  * Elimina un elemento de la base de datos, eliminacion fisica por defecto.
  * @param boolean $logical indica si la eliminacion es logica (true) o fisica (false).
  * @todo: hacer delete por clase/id, esta es solo por instancia.
  */
 public function delete($logical = false)
 {
     Logger::getInstance()->po_log("delete {$logical}");
     // FIXME: devolver algo que indique si se pudo o no eliminar.
     // FIXME: si no esta salvado (no tiene id), no se puede hacer delete.
     PersistentManager::getInstance()->delete($this, $this->getId(), $logical);
     // FIXME: no necesita pasarle el id, el objeto ya lo tiene...
     // http://code.google.com/p/yupp/issues/detail?id=127
     if ($logical) {
         $this->setDeleted(true);
     }
 }
 /**
  * Se utiliza para obtener una estructura de mapeo de clases de herencia sobre diferentes tablas.
  * Como se utiliza como auxiliar de generateAll la pongo aca, talvez pueda ir en ModelUtils, pero
  * en realidad solo se usa para generar el esquema y para salvar.
  * 
  * @param $inheritanceClasses lista de clases de una estructura de herencia (clase de la instancia
  *        del objeto que se esta manejando y todas sus superclases) (no se asume ningun orden).
  */
 public static function getMultipleTableInheritance($inheritanceClasses)
 {
     Logger::getInstance()->dal_log("MTI::getMultipleTableInheritance");
     // Ahora depende de una aplicacion.
     // La estructura de MTI no pueden establecerse entre clases del modelo de distintas aplicaciones.
     $ctx = YuppContext::getInstance();
     $appName = $ctx->getApp();
     // 1. clases y sus subclases
     $e = array();
     // array por clave la clase y valor lista de subclases directas de dicha clase
     foreach ($inheritanceClasses as $class) {
         // Quiero poner solo las clases que esten en $inheritanceClasses, que pueden
         // no ser todas las de la estructura de herencia, esto sirve para
         // implementar getPartialInstancesToSave.
         // TODO: en que caso una clase no es de la estructura de herencia si lo
         //       que le paso como parametro es solo la estructura de herencia???
         //       Ver lo que le pasan todas las operaciones que invoque a esta getMultipleTableInheritance.
         $sclss = ModelUtils::getSubclassesOf($class, $appName);
         $e[$class] = array_intersect($inheritanceClasses, $sclss);
     }
     // 2. Arma array de clases y lista de subclases que se mapean en la misma tabla.
     $e1 = array();
     foreach ($e as $class => $subclasses) {
         $c_ins = new $class();
         if (!array_key_exists($class, $e1) || $e1[$class] === NULL) {
             $e1[$class] = array();
         }
         // armo otro array con las subclases que no tienen withTable.
         foreach ($subclasses as $subclass) {
             //$sc_ins = new $subclass();
             //echo $subclass . " " . $sc_ins->getWithTable() . "<br />";
             //if ( $sc_ins->getWithTable() === $c_ins->getWithTable() ) $e1[$class][] = $subclass; // solo si los withTable son iguales (o sea, que no lo redefine en la subclase)
             if (PersistentManager::isMappedOnSameTable($class, $subclass)) {
                 $e1[$class][] = $subclass;
                 //Logger::getInstance()->dal_log("isMapperOnSameTable: $class , $subclass " . __FILE__ . " " . __LINE__ );
             }
         }
     }
     //Logger::getInstance()->dal_log("clases y subclases en la misma tabla " . __FILE__ . " " . __LINE__ );
     //Logger::struct( $e1 );
     // 3. Todas las keys estan en $inheritanceClasses
     foreach ($e1 as $class => $sameTableFirstLevelSubclasses) {
         //echo "CLASS: $class<br />";
         if ($sameTableFirstLevelSubclasses !== NULL) {
             if (count($sameTableFirstLevelSubclasses) > 0) {
                 $merge = array_merge($sameTableFirstLevelSubclasses, array());
                 // copia los valores ???
                 foreach ($sameTableFirstLevelSubclasses as $subclass) {
                     $classesToMerge = $e1[$subclass];
                     if ($classesToMerge !== NULL) {
                         $merge = array_merge($merge, $classesToMerge);
                         $e1[$subclass] = NULL;
                     }
                 }
                 $e1[$class] = $merge;
             }
         }
     }
     /* Esta mal! D, E y B deberian ser NULL tambien.
     Array
     (
         [B] => 
         [C] => Array
             (
                 [0] => E
             )
     
         [D] => Array
             (
             )
     
         [E] => Array
             (
             )
     
         [F] => Array
             (
             )
     
         [G] => Array
             (
             )
     
         [A] => Array
             (
                 [0] => B
                 [1] => D
             )
     )
            */
     //$sol = array_filter( $e1, 'filter_not_null' );
     // no me deja hacer el filter ... lo hago a mano...
     $sol = array();
     foreach ($e1 as $class => $subclasses) {
         if ($subclasses !== NULL) {
             $sol[$class] = $subclasses;
         }
     }
     return $sol;
 }
Example #14
0
 /**
  * Static criteria
  * @return <criteria>
  */
 public static function staticListAll()
 {
     $criteria = \PersistentManager::getCriteria('exemplos\\models\\Usuario');
     $criteria->select('*');
     return $criteria;
 }
 /**
  * Get Criteria
  *
  */
 public static function getCriteria($className = '')
 {
     $criteria = NULL;
     if ($className != '') {
         $manager = PersistentManager::getInstance();
         $classMap = $manager->getClassMap($className);
         $criteria = new RetrieveCriteria($classMap);
     }
     return $criteria;
 }
 private function __construct()
 {
     PersistentManager::$connection = mysqli_connect($this->hostBD, $this->userBD, $this->psswdBD, $this->nameBD) or die("Could not connect to db: " . mysqli_error());
     mysqli_query(PersistentManager::$connection, "SET NAMES 'utf8'");
 }
Example #17
0
 private function test1()
 {
     PersistentManager::getInstance()->generateAll();
     echo YuppConventions::tableName('M010_Persona') . "<br/>";
     /**
      * Resultado>
      * 
      * CREATE TABLE test_m010_persona (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   nombre TEXT NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL
      * );
      * 
      * CREATE TABLE test_m010_persona_hijos_test_m010_persona (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   owner_id INT(11) NOT NULL,
      *   ref_id INT(11) NOT NULL,
      *   type INT(11) NOT NULL,
      *   deleted BOOL NOT NULL,
      *   class TEXT NOT NULL,
      *   ord INT(11) NULL
      * );
      * 
      */
     // TODO: verificar si la tabla para Nariz y Cara fue creada.
     //$dal = DAL::getInstance();
     $dal = new DAL('tests');
     if ($dal->tableExists(YuppConventions::tableName('M010_Persona'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
 }
Example #18
0
 private function test1()
 {
     PersistentManager::getInstance()->generateAll();
     echo YuppConventions::tableName('Dedo') . "<br/>";
     echo YuppConventions::tableName('Mano') . "<br/>";
     /**
      * Resultado>
      * 
      * CREATE TABLE test_m003_dedo (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   uniaLarga BOOL NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL
      * );
      * 
      * CREATE TABLE test_m003_mano (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   tamanio TEXT NULL,
      *   class TEXT NOT NULL,
      *   deleted BOOL NOT NULL
      * );
      * 
      * CREATE TABLE test_m003_mano_dedos_test_m003_dedo (
      *   id INT(11) DEFAULT 1 PRIMARY KEY,
      *   owner_id INT(11) NOT NULL,
      *   ref_id INT(11) NOT NULL,
      *   type INT(11) NOT NULL,
      *   deleted BOOL NOT NULL,
      *   class TEXT NOT NULL,
      *   ord INT(11) NULL
      * );
      * 
      * ALTER TABLE test_m003_mano_dedos_test_m003_dedo
      *   ADD FOREIGN KEY (owner_id)
      *   REFERENCES test_m003_mano(id);
      * 
      * ALTER TABLE test_m003_mano_dedos_test_m003_dedo
      *   ADD FOREIGN KEY (ref_id)
      *   REFERENCES test_m003_dedo(id);
      * 
      */
     // TODO: verificar si la tabla para Nariz y Cara fue creada.
     //$dal = DAL::getInstance();
     $dal = new DAL('tests');
     if ($dal->tableExists(YuppConventions::tableName('Dedo'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
     if ($dal->tableExists(YuppConventions::tableName('Mano'))) {
         echo "Test 1 correcto";
     } else {
         echo "Test 1 Incorrecto";
     }
 }