SitePoint Sponsor

User Tag List

Page 2 of 9 FirstFirst 123456 ... LastLast
Results 26 to 50 of 205
  1. #26
    SitePoint Enthusiast hantu's Avatar
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A suggestion:

    I think we should start with the format the metadata is available in. When it comes to query parsing then, you can feed the parser with mock metadata and see if it generates the appropriate SQL.

    I used a ClassDescriptor class including FieldDescriptors and ReferenceDescriptors. And a MetadataHandler to retrieve the info like this:
    PHP Code:
    $metadataHandler->getClassDescriptor('Product')->getTable();
    ...
    $metadataHandler->getClassDescriptor('Product')->getPrimaryKey()->getColumn();
    ... 

  2. #27
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is Hibernate/OQL ? (oql = object query language ?) Any links where I can read about it?

  3. #28
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, at the start of the thread

    Also try Google, the largest search engine on the planet

  4. #29
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Milano
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Selkirk
    • Querying is separate
      I see query building as an endless source of complexity. I would like an architecture that separated the process of query building from the process of mapping and object instantiation. One advantage of this is that the query building can hand coded in SQL for complex cases and the query builder can be worked on last.
    How this separation should effectively be done? Can you post an example of code (interface)?
    Quote Originally Posted by Selkirk
    I hadn't really planned to start working on WACT persistence any time soon, but if there is interest in doing something as part of WACT, I would be willing to set things up and to work on it.
    I'd love to see this stuff running "today" under WACT and I'd like to collaborate in it.

  5. #30
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ponticelli
    How this separation should effectively be done? Can you post an example of code (interface)?
    I have no idea at this point. It was just a design goal.

  6. #31
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Selkirk
    [*]Example driven
    The preferred model of development with WACT is to create an example program representing a real use case and then only program what is necessary to support that use case, refactoring what is necessary. This is an anti-speculation technique. We don't add something until there is a proven need for it. You can relate this to the practice of user stories and acceptance testing in XP. Wact instead uses example programs as use cases, and automated web testing of those examples as acceptance tests.
    If I started a thread on methodologies of running SF projects, would you have time to contribute. I am collecting tips and tricks inthis area with the hope of publishing some kind of standard benchmark methodology. I need lots experience reports and case studies.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  7. #32
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. For example:

    One to One relationship
    One to Many relationship
    Many to Many relationship
    Inheritance releationship
    Derived business logic
    etc.

    Also, A list of potential queries on the domain model would be helpful.

    I think picking a good example domain model will be a key to collaborative success. Also, I have found in my past experiences that picking overly contrived examples can be a hinderance.

    May I suggest a link directory, a blog, or an advertising server?

    I would lean toward and advertising server because of the opportunities to express more complex business logic, different types of ads can be represented via inheritance, and keywords and categories can provide extra relationships to work with.

    Any suggestions on cases which should be supported?

    With a good example model to start with, we can then start to talk about how we might represent this model as a set of PHP objects, how we might represent this model as a database, and how we might map between the two.

    ORM and persistence is a very big topic. Without a firm grounding in some very concrete examples and use cases, discussion will end up being far flung and fragmented, especially in a collaborative effort. A concrete example domain allows us to compare apples to apples as proposals are made and discussed.

  8. #33
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think we were both posting at the same time, Marcus. Its very interesting what you chose to quote versus my last post. I will contribute what I can to such a thread.

  9. #34
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Milano
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest as a working example, to use something like a "librarian project"; this should be quite clear for everyone without too much explications. An advertising sever should be of course of great interest but I think it adds complexity in itself; I mean, it's not just modeling something known, it's something to invent first.

  10. #35
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We need a domain where we can create a semi-working application that can have test cases run against it. An application of the kind that one would actually write in PHP. Additionally, we are all web developers here, so I think it should be a common web application (say one of the hotscripts categories).

    Anyway, I don't plan to be the one to make the domain model and the thing about open source is "he who contributes decides."

  11. #36
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    Milano
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've no problem to start it here, but maybe a new thread should be better since this has been started about a porting of Hibernate?

  12. #37
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    with my kids
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is a bit of a sidetrack, but has anybody ever looked at Protege? i've been playing around and it's got a lot of interesting, and perhaps useful, ideas. it's website says "Protégé is an ontology editor and a knowledge-base editor", but it's really a tool that builds domain models. those models can then be used within protege itself, in a separate stand-alone application, accessed through an API, even stored as UML or XML or another format (from whence you can generate Java Classes or Beans, or even PHP Code?).

    Here's an introductory article on Protege:
    An AI tool for the real world

    what made me think of Protege when reading this thread is this bit on the JDBC backend.

    anyway, thought it might provide some useful ideas.

  13. #38
    SitePoint Addict
    Join Date
    Apr 2002
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mjlivelyjr
    It has already been noted that one of the harder things to tackle would be that we would need to parse the OQL. The best solution to this would probably be a lexer as Marcus aptly pointed out. Fortunately for us Marcus is quite versed in this area. So he'll be able to give alot more information on that. I'll repost when I have some knowledge worth sharing :P
    Before reinventing the wheel, you may want to take a look at Metastorage. This is a tool that generates classes for implementing persistent objects from models of the classes that each developer describe. The model description is done in a simple XML based format named CPML (Component Persistence Markup Language).

    In that model you describe your persistent object classes with their variables, validation rules, relationships between classes and a set functions that you specify that your classes need to store, retrieve and perform other types of manipulations on their objects.

    You can specify as many functions as you want to retrieve objects of each class. You can associate filter conditions to specify search criteria using Metastorage OQL. Metastorage OQL is very similar to SQL but since it is part of CPML, its syntax is also in XML. So, it can perform complex joins based on the relationships defined in your model.

    The search conditions of functions that use Metastorage OQL are compiled at code generation time to produce optimized SQL. You do not have to waste any time at runtime processing the filter condition expressions. That is much more efficient than other data object package solutions that make you call a bunch of functions at runtime just to define any type of search criteria that you need.

    Metastorage also generates report generation classes that retrieve data according to filter expressions also defined using Metastorage OQL. The report generation support is a feature that is available in the current beta version that was not yet released as the documentation is not yet finished. However, you can see an example of application of Metastorage generated persistent objects and report classes in the forums system of the PHP Classes site.
    Manuel Lemos

    Metastorage - Data object relational mapping layer generator
    PHP Classes - Free ready to use OOP components in PHP

  14. #39
    SitePoint Addict
    Join Date
    May 2003
    Location
    Calgary, Alberta, Canada
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote 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.
    Attached Files Attached Files

  15. #40
    SitePoint Enthusiast hantu's Avatar
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Brenden,

    I've read through your code and I think it looks quite promising. There's still a lot of work to do for mapping inheritance and all associations and for parsing OQL, but your code is a good starting point I think.

    Some comments on the TODO file:

    I'm not happy with PHP4 compatibility as a lot of features like interfaces, exceptions and dereferencing objects couldn't be used.

    I think a Query Object should be implemented, it's very useful in case your application needs to dynamically generate queries.

    Maybe in the first run only Single Table Inheritance should be implemented for the sake of simpleness.

    I miss the IN-Operator in the list of comparison functions.

    Just some thoughts ...

  16. #41
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm also with you on that, I like the naming of the xml tags as well though is there no standard naming for this sort of thing... maybe we should follow the Hibernate approach, or create our own naming?

    On the topic, I have a PDF on data peristence, tried to attach it to this post but the file is too big. If anyone is interested, I can email it to them instead

  17. #42
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Brenden Vickery
    Ive got a prototype attached for people to check out.
    Excellent! the best sort of post...

    Quote Originally Posted by Brenden Vickery
    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.
    I was watching Jeff hijack this with some admiration .

    Quote Originally Posted by Brenden Vickery
    This xml file is the Object Relational Map for our example:
    Cool. Very clear. The association will need a lot more information, or better yet, be split into different tags.

    Quote Originally Posted by Brenden Vickery
    No domain model code is generated. Your model objects must have a set*/get*/add* interface however.
    Usual DataMapper behaviour.

    Quote Originally Posted by Brenden Vickery
    PHP Code:
    $uow = new UnitOfWork($o_r_map$datasource); 
    UnitOfWork is still not a very defined pattern and having pattern names in code is a bit dodgy. For example, what if this class wraps a UnitOfWork when it gets more complicated. Hibernate uses "Session", although "Transaction" should be fine to.

    I would get DB transactions in early because without them a library like this is pretty useless. You also need backup and restore utilities (store the object schema with the data). You also need schema migration tools, although for schemas that map to existing DB structures you can leave it up to the DBA. These extra tools are not just minor add ons, they are in constant use throughout a project once you are working with live servers.

    I have been dropping heavy hints that this is a big job...

    Quote Originally Posted by Brenden Vickery
    Id appreciate comments on how the testing is done, the interface, any problem areas people see with the code or expect.
    You have a global test example which wil get strained as you add more tests. Don't go there . For the unit tests I would have lot's of little mini examples with their own mini schemas. Makes the tests a lot easier to maintain and also makes them more readable. Especially if the schema actually appears in the test case...
    PHP Code:
    class TestOfSimpleJoin extends UnitTestCase {
        function 
    setUp() {
            
    $this->writeSchema('<persist>...</persist>');
        }

    Also you normally want at least as much test code as real code. Probably more in this case because DB data is usually mission critical.

    BTW: How about calling it PhORM?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  18. #43
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    BTW: How about calling it PhORM?
    I bet dozens of people have thought that was a clever name for PHP based form handling scripts
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  19. #44
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Bogota
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by Brenden Vickery

    PHP Code:
     // 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(); 
    I've been working on some code that looks almost the same as yours. We are not confortable with one thing though. There´s a possibility that you load objects you don´t want to update aswell as objects you update or create... the clean, dirty, new stuff.

    We don't like the fact that using this implementations forces you to update every loaded object when you commit the transaction, even if some of them were not modified.

    We found that the only way to keep clean objects clean would requiere domain objects to notify the UoW when they are modified and become dirty. This would add a dependency from the domain model to the ORM ... sucks.

    So, do you plan to get around this? Do you think it's ok to save everything that wasnt modified during commit() ?

    Currently I'm seriously considering to implement the UoW using a singleton and notifying to it from the constructors and setters.

    PHP Code:
      Class Person{
      
          function 
    setName($name) {
              
    $this->name $name;
              
    $uow UoW::instance();
              
    $uow->registerDirty($name);
          }
      } 
    I don't think I'm being of great help here, but at least I hope this will give you food for thought.

    Regards,
    - Andres
    If I have wings, why am I walking?

  20. #45
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Bogota
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $team =& $query->execute(1); 
    Just realized this is the way you register them dirty, right?

    If I have wings, why am I walking?

  21. #46
    SitePoint Enthusiast hantu's Avatar
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We already had a long discussion on how to keep track of changes in the domain objects without having them notify the Unit of Work.

    Take a look here:
    http://www.sitepoint.com/forums/showthread.php?t=214974

    As far as I can remember we found two options:

    a) save a hash of the object's state when it's loaded, compare that to the object's state when Unit Of Work commits the changes.

    The drawback here is you won't be able to reconstruct which attributes have changed, so you will need to update the whole object in the db.

    b) save a copy of the object when it's loaded, so you can reconstruct the changes of single attributes at commit time. (Fowler says TopLink uses this approach and calls it Unit Of Work Controller)

    The drawback here might be the difficult comparison and huge memory usage

  22. #47
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    Bogota
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by hantu
    We already had a long discussion on how to keep track of changes in the domain objects without having them notify the Unit of Work.
    Ok, good you pointed this out... I still have my doubts but I will defenetively be trying some code on this.

    Cheers,
    -Andres
    If I have wings, why am I walking?

  23. #48
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by hantu
    The drawback here might be the difficult comparison and huge memory usage
    There are all sorts of reasons why a straight Hibernate port won't do because you don't want to keep things in memory longer than you have to (unless it includes a persistent memory cache). For example when iterating through a large data set, you don't want to clone or keep a reference to every item.

    One solution might be a commit method that can take an object as an optional parameter and so remove it from the IdentityMap. In a loop it might be...
    PHP Code:
    $friends $query->fetch();
    foreach (
    $friends as $friend) {
        
    $friend->send($gift);
        
    $transaction->commit($friend);

    The problem is going to be the degree of transaction isolation provided by the database engine. With a partial committing of the object graph there could be all sorts of problems with simultaneous transactions.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  24. #49
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lastcraft: How about calling it PhORM?

    sweatje: I bet dozens of people have thought that was a clever name for PHP based form handling scripts
    How about ORMpH.

    Christopher

  25. #50
    SitePoint Enthusiast hantu's Avatar
    Join Date
    Oct 2004
    Location
    Berlin
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    There are all sorts of reasons why a straight Hibernate port won't do because you don't want to keep things in memory longer than you have to
    I guess we all agree on this

    Quote Originally Posted by lastcraft
    For example when iterating through a large data set, you don't want to clone or keep a reference to every item
    I think we need more granularity for controlling the behaviour of object graphs or large lists than just one commit operation that saves all changes.

    There would be the Transaction->commit() (or Session.flush() in Hibernate) method that automatically persists all changes as the most comfortable option to a user.

    PHP Code:
    $friends $session->fetch($query);
    foreach (
    $friends as $friend) {
      
    $friend->send($gift);
    }
    /* automatically detect and commit all changes 
        using the Identity Map 
        and the information stored about loaded objects */
    $session->flush() 
    But there should also be an API to manually control transaction and persistence behaviour

    PHP Code:
    /* load the objects, but don't store information about them */
    $friends $session->fetch($queryQuery::IGNORE_CHANGE_TRACKING);
    $tx $session->beginTransaction(); 
    foreach (
    $friends as $friend) {
      
    $friend->send($gift);
      
    /* do a manual update*/
      
    $session->update($friend);
    }
    $tx->commit(); 
    BTW: Another candidate for the name game: eklemata

    Anybody remembers the old SNES Adventuregame "Terranigma"? I loved playing it, you had to revive the world step by step (ocean, nature, animals, humans). Anyway there was a place called eklemata where the souls of humanity were resting. So in technical terms humanity was persisted there and I find it a good name for a persistence layer

    Just a suggestion ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •