public function testHardifier() { $switcher = new Switcher(); $switcher->hardify($this->targetSubjectClass, array('topclass' => new core_kernel_classes_Class('http://www.tao.lu/Ontologies/generis.rdf#User'), 'recursive' => true, 'createForeigns' => false, 'rmSources' => true)); unset($switcher); $this->assertIsA(ClassProxy::singleton()->getImpToDelegateTo($this->targetSubjectClass), 'oat\\generisHard\\models\\hardsql\\Clazz'); $this->assertIsA(ClassProxy::singleton()->getImpToDelegateTo($this->targetSubjectSubClass), 'oat\\generisHard\\models\\hardsql\\Clazz'); }
public function testInject() { $generisClass = new core_kernel_classes_Class(CLASS_GENERIS_RESOURCE); $testClass = $generisClass->createSubClass(); $switcher = new Switcher(); $switcher->hardify($testClass); try { $testInstance = $testClass->createInstanceWithProperties(array(RDFS_LABEL => '"hi"')); $testInstance->setPropertiesValues(array(RDFS_COMMENT => '"hi"')); $this->assertEquals($testInstance->getUniquePropertyValue(new core_kernel_classes_Property(RDFS_LABEL)), "\"hi\""); } catch (Exception $e) { $this->fail('SQL Error: ' . $e->getMessage()); } $testInstance->delete(); $switcher->unhardify($testClass); $testClass->delete(); }
public function testCreateInstanceHardified() { $rr = ResourceReferencer::singleton(); $this->assertFalse($rr->isClassReferenced($this->class)); $softinstance = core_kernel_classes_ResourceFactory::create($this->class); $this->assertFalse($rr->isResourceReferenced($softinstance)); $switcher = new Switcher(); $switcher->hardify($this->class, array('topclass' => $this->class)); unset($switcher); $this->assertTrue($rr->isClassReferenced($this->class)); common_Logger::i('creating hardified'); $hardinstance = core_kernel_classes_ResourceFactory::create($this->class); $this->assertTrue($rr->isResourceReferenced($hardinstance), 'Instance created from harmode class was added in softmode'); $softinstance->delete(); $hardinstance->delete(); $switcher = new Switcher(); $switcher->unhardify($this->class); unset($switcher); }
/** * (non-PHPdoc) * @see core_kernel_persistence_ClassInterface::createSubClass() */ public function createSubClass(\core_kernel_classes_Class $resource, $label = '', $comment = '', $uri = '') { // Meta-model is still in smooth mode... $newClass = \core_kernel_persistence_smoothsql_Class::singleton()->createSubClass($resource, $label, $comment, $uri); if (empty($newClass)) { $classUri = $resource->getUri(); $msg = "An error occured while creating a sub-class of '{$classUri}'."; throw new HardapiException($msg); } // Simply hardify the class to keep consistency in the class hierarchy. // We want to avoid class hierarchies with multiple persistence implementations. $switcher = new Switcher(); if (!$switcher->hardify($newClass)) { $classUri = $resource->getUri(); $msg = "An error occured while hardifying class '{$classUri}'."; throw new HardapiException($msg); } return $newClass; }
/** * Convenience method to compile a class. The optimization options are retrieved from * data returned by getOptimizableClasses(). * * This method returns an associative structure containing the following informations: * * array( * "success" => true/false, * "count" => integer // the class instances that were optimized * "relatedClasses" => array("class1", "class2", ...) // the classes that were impacted by the optimization * // depending on the optimization options * ) * * @param \core_kernel_classes_Class A class to compile. * @see Optimization::getOptimizableClasses() * @return array */ public static function compileClass(\core_kernel_classes_Class $class) { $result = array('success' => false); $optimizableClasses = self::getOptimizableClasses(); if (isset($optimizableClasses[$class->getUri()]) && isset($optimizableClasses[$class->getUri()]['compile'])) { //build the option array and launch the compilation: $options = array_merge($optimizableClasses[$class->getUri()]['compile']); $switcher = new Switcher(); $switcher->hardify($class, $options); //prepare return value $hardenedClasses = $switcher->getHardenedClasses(); $count = isset($hardenedClasses[$class->getUri()]) ? $hardenedClasses[$class->getUri()] : 0; $relatedClasses = array(); foreach ($hardenedClasses as $relatedClassUri => $nb) { if ($relatedClassUri != $class->getUri()) { $relatedClass = new \core_kernel_classes_Class($relatedClassUri); $relatedClasses[$relatedClass->getLabel()] = $nb; } } $result = array('success' => true, 'count' => $count, 'relatedClasses' => $relatedClasses); unset($switcher); } return $result; }
public function testHardGetInstances() { $this->hardify(); // Get the hardified instance from the hard sql imlpementation $this->assertEquals(count($this->targetSubjectClass->getInstances()), 1); $this->assertEquals(count($this->targetSubjectSubClass->getInstances()), 1); $this->assertEquals(count($this->targetSubjectClass->getInstances(true)), 2); $this->assertEquals(count($this->targetWorkClass->getInstances(true)), 0); $this->assertEquals(count($this->targetMovieClass->getInstances()), 0); $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER); $users = $userClass->getInstances(); $this->assertEquals(count($users), 1); $user = $userClass->createInstance('toto', 'toto'); $switcher = new Switcher(); $switcher->hardify($userClass, array('recursive' => false)); $users = $userClass->getInstances(); $this->assertEquals(count($users), 2); $switcher->unhardify($userClass, array('recursive' => false)); $this->assertTrue($user->delete()); }
public function testSearchInstancesMultipleImpl() { $clazz = new core_kernel_classes_Class(RDFS_CLASS); $sub1Clazz = $clazz->createSubClass(); $sub1ClazzInstance = $sub1Clazz->createInstance('test case instance'); $sub2Clazz = $sub1Clazz->createSubClass(); $sub2ClazzInstance = $sub2Clazz->createInstance('test case instance'); $sub3Clazz = $sub2Clazz->createSubClass(); $sub3ClazzInstance = $sub3Clazz->createInstance('test case instance'); $options = array('recursive' => true, 'append' => true, 'createForeigns' => true, 'referencesAllTypes' => true, 'rmSources' => true); //Test the search instances on the smooth impl $propertyFilter = array(RDFS_LABEL => 'test case instance'); $instances = $clazz->searchInstances($propertyFilter, array('recursive' => true)); $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances)); common_Logger::d('starting hardify'); //Test the search instances on the hard impl $switcher = new Switcher(); $switcher->hardify($sub1Clazz, $options); unset($switcher); //Required to update cache data common_Logger::d('done hardify'); $propertyFilter = array(RDFS_LABEL => 'test case instance'); $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true)); $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances)); $switcher = new Switcher(); $switcher->unhardify($sub1Clazz, $options); unset($switcher); //Required to update cache data //Test the search instances on a shared model (smooth + hard) //Disable recursivity on hardify, and hardify the sub2Clazz $switcher = new Switcher(); $options['recursive'] = false; $switcher->hardify($sub2Clazz, $options); unset($switcher); //Required to update cache data $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true)); $this->assertTrue(array_key_exists($sub1ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub2ClazzInstance->getUri(), $instances)); $this->assertTrue(array_key_exists($sub3ClazzInstance->getUri(), $instances)); try { $instances = $sub1Clazz->searchInstances($propertyFilter, array('recursive' => true, 'offset' => 1)); $this->assertTrue(false); } catch (common_Exception $e) { $this->assertTrue(true); } $switcher = new Switcher(); $switcher->unhardify($sub2Clazz, $options); unset($switcher); //Required to update cache data //clean data test foreach ($sub1Clazz->getInstances(true) as $instance) { $instance->delete(); } $sub1Clazz->delete(true); $sub2Clazz->delete(true); $sub3Clazz->delete(true); }