
Originally Posted by
Selkirk
I think a good place to start would be an example domain model expressed in UML. This would provide a common vocabulary for examples. The model should contain some of the problems that an ORM layer must solve. ...
This is a really good idea. Ive got a prototype attached for people to check out. The domain model I was testing on is really crappy and has basically become obsolete compared to the ORM.
I think one of the goals should be to stay as decoupled from the WACT inner workings as possible. Id want people to be able to pick up the code and use it in Mojavi or their own framework. I think this would benefit the PHP community the most.
This could be used with wact now if we passed in a wact dbObject and stopped using prepared statements in the orm. I couldnt find the Datasource interface that you want persistent objects to implement.
Quick overview of the attached :
This xml file is the Object Relational Map for our example:
PHP Code:
<persist>
<class name="League" table="LEAGUE">
<field name="id" column="LEAGUE_ID" columnType="int" key="primary" />
<field name="name" column="LEAGUE_NAME" columnType="string" />
</class>
<class name="Team" table="TEAM">
<field name="id" column="TEAM_ID" columnType="int" key="primary" />
<field name="name" column="TEAM_NAME" columnType="string" />
<field name="league" column="TEAM_LEAGUE_ID" columnType="int">
<association class="League" field="id" />
</field>
</class>
</persist>
No domain model code is generated. Your model objects must have a set*/get*/add* interface however.
Queries we can do so far:
PHP Code:
$o_r_map = './location/of/o_r_map_xml_file.xml';
$datasource = DataSource::create('mysql', 'localhost', 'root', 'pass', 'db');
$uow = new UnitOfWork($o_r_map, $datasource);
// SELECT * FROM TEAM
$query = $uow->createQuery('Team');
$teams = $query->execute();
// SELECT * FROM TEAM WHERE TEAM_ID = 1
$query = $uow->createUniqueQuery('Team', 'id == ?');
$team = $query->execute(1);
// INSERT INTO TEAM (TEAM_NAME, TEAM_LEAGUE_ID)
// VALUES ('Vancouver Canucks', 1)
$team =& $this->uow->createObject('Team');
$team->setName('Vancouver Canucks');
$team->setLeague(1);
// Insert is not done until commit
$uow->commit();
// UPDATE TEAM SET TEAM_NAME = 'Utah Jazz' WHERE TEAM_ID = 1
$query = $uow->createUniqueQuery('Team', 'id == ?');
$team =& $query->execute(1);
$team->setName('Utah Jazz');
// Update is not done until commit
$uow->commit();
/*
SELECT *
FROM LEAGUE
LEFT JOIN TEAM
ON (LEAGUE.LEAGUE_ID = TEAM.TEAM_LEAGUE_ID)
WHERE
LEAGUE_ID = 1;
*/
// This returns a League object with all related teams
$query = $uow->createUniqueQuery('League', 'id == ?', 'Team');
$league = $query->execute(1);
echo $league->getName();
foreach($league->getTeams() as $team) {
echo $team->getName();
}
There are problems with the code but I wanted to post something for people to really sink their teeth into.
Beyond coming up with a good domain model I think we need to discuss the OQL and XMLMap languages before much more code is written.
Id appreciate comments on how the testing is done, the interface, any problem areas people see with the code or expect.
There is a TODO file in the attachment that covers some of the stuff covered in this thread.
Bookmarks