public function multipleJoinResultTest()
 {
     $rs = new MockResultSet(array(array(JoinProcessor::FIRST . '_job_id' => '11', JoinProcessor::FIRST . '_title' => 'clean toilette', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(array('PersonJob')) . '_person_id' => '11', JoinProcessor::pathToKey(array('PersonJob')) . '_name' => 'Schultz', JoinProcessor::pathToKey(array('PersonJob')) . '_job_id' => '21', JoinProcessor::pathToKey(array('PersonJob')) . '_department_id' => '31'), array(JoinProcessor::FIRST . '_job_id' => '11', JoinProcessor::FIRST . '_title' => 'clean toilette', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(array('PersonJob')) . '_person_id' => '12', JoinProcessor::pathToKey(array('PersonJob')) . '_name' => 'Müller', JoinProcessor::pathToKey(array('PersonJob')) . '_job_id' => '11', JoinProcessor::pathToKey(array('PersonJob')) . '_department_id' => '31'), array(JoinProcessor::FIRST . '_job_id' => '12', JoinProcessor::FIRST . '_title' => 'second job', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(array('PersonJob')) . '_person_id' => '11', JoinProcessor::pathToKey(array('PersonJob')) . '_name' => 'Schultz', JoinProcessor::pathToKey(array('PersonJob')) . '_job_id' => '21', JoinProcessor::pathToKey(array('PersonJob')) . '_department_id' => '31'), array(JoinProcessor::FIRST . '_job_id' => '13', JoinProcessor::FIRST . '_title' => 'third job', JoinProcessor::FIRST . '_valid_from' => new \util\Date(), JoinProcessor::FIRST . '_expire_at' => '', JoinProcessor::pathToKey(array('PersonJob')) . '_person_id' => null, JoinProcessor::pathToKey(array('PersonJob')) . '_name' => null, JoinProcessor::pathToKey(array('PersonJob')) . '_job_id' => null, JoinProcessor::pathToKey(array('PersonJob')) . '_department_id' => null)));
     $jp = new JoinProcessor(Job::getPeer());
     $jp->setFetchModes(array('PersonJob' => 'join'));
     $ji = new JoinIterator($jp, $rs);
     $this->assertTrue($ji->hasNext());
     $this->assertClass($job = $ji->next(), 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertArray($job->getPersonJobList());
     $this->assertClass($pji = $job->getPersonJobIterator(), 'util.HashmapIterator');
     $this->assertTrue($pji->hasNext());
     $this->assertClass($pji->next(), 'net.xp_framework.unittest.rdbms.dataset.Person');
     $this->assertTrue($pji->hasNext());
     $this->assertClass($pji->next(), 'net.xp_framework.unittest.rdbms.dataset.Person');
     $this->assertFalse($pji->hasNext());
     $this->assertTrue($ji->hasNext());
     $this->assertClass($job = $ji->next(), 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertArray($job->getPersonJobList());
     $this->assertClass($pji = $job->getPersonJobIterator(), 'util.HashmapIterator');
     $this->assertTrue($pji->hasNext());
     $this->assertClass($pji->next(), 'net.xp_framework.unittest.rdbms.dataset.Person');
     $this->assertFalse($pji->hasNext());
     $this->assertTrue($ji->hasNext());
     $this->assertClass($job = $ji->next(), 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertArray($job->getPersonJobList());
     $this->assertClass($pji = $job->getPersonJobIterator(), 'util.HashmapIterator');
     $this->assertFalse($pji->hasNext());
     $this->assertFalse($ji->hasNext());
 }
 public function extractTest()
 {
     $toJob = new JoinPart('j', Job::getPeer());
     $toPerson = new JoinPart('p', Person::getPeer());
     $toDepartment = new JoinPart('d', Department::getPeer());
     $toChief = new JoinPart('c', Person::getPeer());
     $toJob->addRelative($toPerson, 'JobPerson');
     $toPerson->addRelative($toDepartment, 'Department');
     $toDepartment->addRelative($toChief, 'DepartmentChief');
     $job = Job::getPeer()->objectFor(array('job_id' => '21', 'title' => 'clean the toilette', 'valid_from' => new \util\Date(), 'expire_at' => ''));
     $toPerson->extract($job, array('p_person_id' => '11', 'p_name' => 'Schultz', 'p_job_id' => '21', 'p_department_id' => '31', 'd_department_id' => '31', 'd_name' => 'iDev', 'd_chief_id' => '12', 'c_person_id' => '12', 'c_name' => 'Friebe', 'c_job_id' => '22', 'c_department_id' => '31'), 'JobPerson');
     $this->assertClass($job->getCachedObj('JobPerson', '#11'), 'net.xp_framework.unittest.rdbms.dataset.Person');
     $this->assertClass($job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31'), 'net.xp_framework.unittest.rdbms.dataset.Department');
     $this->assertClass($job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31')->getCachedObj('DepartmentChief', '#12'), 'net.xp_framework.unittest.rdbms.dataset.Person');
 }
 function restrictionTest()
 {
     $this->assertSQL('where job_id = ceil(asin(sin(0.125)))', 'where job_id = ceiling(asin(sin(0.125)))', 'where job_id = ceil(asin(sin(0.125)))', 'where job_id = php(\'ceil\', php(\'asin\', php(\'sin\', 0.125)))', create(new \rdbms\Criteria())->add(Restrictions::equal('job_id', SQLFunctions::ceil(SQLFunctions::asin(SQLFunctions::sin(0.125))))));
     $this->assertSQL('where job_id = ceil(asin(sin(0.125)))', 'where job_id = ceiling(asin(sin(0.125)))', 'where job_id = ceil(asin(sin(0.125)))', 'where job_id = php(\'ceil\', php(\'asin\', php(\'sin\', 0.125)))', create(new \rdbms\Criteria())->add(Restrictions::equal(Job::column('job_id'), SQLFunctions::ceil(SQLFunctions::asin(SQLFunctions::sin(0.125))))));
 }
 public function testJoinWithProjection()
 {
     $jp = new \rdbms\join\JoinProcessor(Job::getPeer());
     $jp->setFetchModes(array('PersonJob->Department' => 'join'));
     $jp->enterJoinContext();
     $this->assertEquals('select  PersonJob.job_id, PersonJob_Department.department_id from JOBS.job as start, JOBS.Person as PersonJob, JOBS.Department as PersonJob_Department where start.job_id *= PersonJob.job_id and PersonJob.department_id *= PersonJob_Department.department_id and  1 = 1', create(new Criteria())->setFetchmode(\rdbms\join\Fetchmode::join('PersonJob'))->setProjection(\rdbms\criterion\Projections::ProjectionList()->add(Job::column('PersonJob->job_id'))->add(Job::column('PersonJob->Department->department_id')))->getSelectQueryString($this->conn, $this->peer, $jp));
     $jp->leaveJoinContext();
 }
 public function testDoSelectMax()
 {
     for ($i = 0; $i < 4; $i++) {
         $this->setResults(new MockResultSet(array(0 => array('job_id' => 654, 'title' => 'Java Unit tester', 'valid_from' => Date::now(), 'expire_at' => null), 1 => array('job_id' => 655, 'title' => 'Java Unit tester 1', 'valid_from' => Date::now(), 'expire_at' => null), 2 => array('job_id' => 656, 'title' => 'Java Unit tester 2', 'valid_from' => Date::now(), 'expire_at' => null), 3 => array('job_id' => 657, 'title' => 'Java Unit tester 3', 'valid_from' => Date::now(), 'expire_at' => null))));
         $this->assertEquals($i ? $i : 4, count(Job::getPeer()->doSelect(new \rdbms\Criteria(), $i)));
     }
 }
 /**
  * Setup method
  */
 public function setUp()
 {
     $this->conn = DriverManager::getConnection('mock://mock/JOBS?autoconnect=1');
     $this->peer = Job::getPeer();
     $this->peer->setConnection(DriverManager::getConnection('mock://mock/JOBS?autoconnect=1'));
 }
 public function ambiguous()
 {
     Job::getPeer()->getConnection()->setResultSet(new \net\xp_framework\unittest\rdbms\mock\MockResultSet(array(array('job_id' => 1549, 'title' => 'Developer'), array('job_id' => 1549, 'title' => 'Doppelgänger'))));
     $in = $this->newReader("job_id;title\n1549;10248")->withProcessors(array(new GetDataSet(create(new JobFinder())->method('byPrimary')), null));
     $in->getHeaders();
     try {
         $in->read();
         $this->fail('Lookup succeeded', null, 'lang.FormatException');
     } catch (\lang\FormatException $expected) {
     }
 }
Пример #8
0
 /**
  * Returns the Peer object for this finder
  *
  * @return  rdbms.Peer
  */
 public function getPeer()
 {
     return Job::getPeer();
 }
 function withProjectionTest()
 {
     $crit = new \rdbms\Criteria();
     $this->assertClass($crit->withProjection(Projections::property(Job::column('job_id'))), 'rdbms.Criteria');
     $this->assertFalse($crit->isProjection());
     $this->assertTrue($crit->withProjection(Projections::property(Job::column('job_id')))->isProjection());
 }
Пример #10
0
 public function genericFinderGetAll()
 {
     $this->getConnection()->setResultSet(new MockResultSet(array(0 => array('job_id' => 1, 'title' => $this->getName(), 'valid_from' => \util\Date::now(), 'expire_at' => null), 1 => array('job_id' => 2, 'title' => $this->getName() . ' #2', 'valid_from' => \util\Date::now(), 'expire_at' => null))));
     $all = create(new GenericFinder(Job::getPeer()))->getAll(new \rdbms\Criteria());
     $this->assertEquals(2, sizeof($all));
     $this->assertClass($all[0], 'net.xp_framework.unittest.rdbms.dataset.Job');
     $this->assertClass($all[1], 'net.xp_framework.unittest.rdbms.dataset.Job');
 }
Пример #11
0
 public function executeWithRestriction()
 {
     $this->assertClass(create(new SelectQuery())->withRestriction(Job::column('job_id')->equal(5)), 'rdbms.query.SelectQuery');
 }
 public function noSuchRoleTest()
 {
     $jp = new JoinProcessor(Job::getPeer());
     $jp->setFetchModes(array('UnknownRole' => 'join'));
 }