SitePoint Sponsor |
|
User Tag List
Results 51 to 75 of 171
-
Feb 16, 2006, 19:10 #51
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
Originally Posted by akrabat
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Feb 16, 2006, 19:18 #52
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
Originally Posted by thr
Anyway, looks like you have surpassed Changes some time ago.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Feb 17, 2006, 02:36 #53
Originally Posted by lastcraft
Originally Posted by lastcraft
Originally Posted by lastcraft
Originally Posted by jayboots
The main danger I see with pre-methods is that when they're executed you assume that the query will go thru and thus make changes to other DomainObjects / The database - but what happends if the query fail and you've already made changes in say beforeInsert(); to other DomainObjects?
-
Feb 17, 2006, 03:35 #54
How does this look for a standard mapper interface:
PHP Code:<?php
interface Mapper{
const HAS_MANY = 0x0;
const HAS_ONE = 0x1;
const BELONGS_TO = 0x2;
const CFG_TYPE = 0x1;
const CFG_TABLE = 0x2;
const CFG_ID = 0x4;
const CFG_KEYS = 0x8;
const CFG_FIELDS = 0x10;
const CFG_RELATIONS = 0x20;
const CFG_VALUEOBJECTS = 0x40;
const CFG_ALL = 0x7F;
public function getConfigurationDirective($directive = Mapper::CFG_ALL);
public function generateArrayKey(Array $result);
public function generateObjectKey(DomainObject $object);
public function findBySql($sql, Array $values = array(), $recursion = null);
public function findByStmt(PDOStatement $stmt);
public function update(DomainObject $object);
public function delete(DomainObject $object);
public function insert(DomainObject $object);
public function create();
}
?>
-
Feb 17, 2006, 05:54 #55
Ok, so I was thinking about performance and how to improve it earlier today (yes I spend alot of time on this ORM code but I enjoy it.), this idea popped into my head:
Often when you do a query that spans over multiple objects(such as select * from person where age > 20), many of those objects are already in memory and the data isn't realy required to be fetched from the db. Just executing this query and then compare the result vs. what you got inmemory and figure out what objects to build and what objects already exists is the "normal" way. I was thinking about trying to do some optimization.
Take the above query select * from person where age > 20 and turn it into select id from person where age > 20, now compare the ids you get back to the objects you already got in memory. Remove all the ids that already have object representing them and only fetch the ids without objects with a query such as: select * from person where id = 1 or id = 2 to fetch object 1 and 2. Would this improve performance? I can see that memory wise it would improve performance if you're fetching very large rows from the db. And even if it doesn't effect performance that much is it worth it anyways due to not fetching "old" data again?
-
Feb 17, 2006, 06:56 #56
Not sure its worth it.
If eventually write a OQL parser, and evaluator to run against the in-mem objects you could feasibly write
SELECT * Person WHERE age > 20 AND Id NOT IN (1, 2)
Where 1 & 2 are in-mem persons that statisfy the condition(s), but I'm guessing probably more expensive in the vast majority of cases. Edit: Plus composite pks get messy.
Back to optimistic locking, if your using a config file, why not have a section for columns that need to be compared when doing U&D operations. Would be more independant I think, MySQL allows tables with multiple timestamps, and only the first gets updated automatically, MSSQL's timestamp is non-standard and have a rowversion datatype, Sqlite doesn't have a timestamp datatype.
-
Feb 17, 2006, 07:13 #57
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by thr
-
Feb 17, 2006, 07:43 #58
Originally Posted by kyberfabrikken
Originally Posted by ren
-
Feb 17, 2006, 08:03 #59
Originally Posted by thr
SELECT Id FROM Persons WHERE Age > 20
And create Person objects directly from the result, and the rest of the Person fields get lazy loaded, guess the trick maybe to merge SELECT * FROM Persons WHERE Id = 1 into SELECT * Persons WHERE Id IN (...) when performing lazy loading, so can reduce the number of SQL calls.
-
Feb 17, 2006, 10:09 #60
Originally Posted by thr
As for Data validation, it goes in the model layer, which just happens to be the same as the orm layer for me because i'm using active record. The advantage of putting it there is that there is no way to persist data that doesn't meet the validation rules, which could happen if validation wasn't being performed in the save call.
-
Feb 17, 2006, 10:17 #61
Edit: Rephrased + added some more text.
Originally Posted by 33degrees
Originally Posted by 33degrees
-
Feb 17, 2006, 10:25 #62
Originally Posted by thr
Really, the only way to optimise sensibly is to profile your classes and identify the bottlenecks; don't bother implementing something like this unless you're absolutely sure it's worth it.
Originally Posted by thr
-
Feb 17, 2006, 10:33 #63
Originally Posted by thr
Originally Posted by thr
-
Feb 17, 2006, 10:46 #64
Originally Posted by 33degrees
Originally Posted by 33degrees
-
Feb 17, 2006, 10:49 #65
(to mention something else) Found a rather annoying thing in PHP today, namely this:
PHP Code:<?php
$names = array("fredrik","madeleine");
foreach($names as $name){
echo $name . "<br />";
if($name == 'fredrik')
$names[] = 'thr';
}
?>
Code:fredrik<br />madeleine<br />
Edit: Ok, found a workaround (rather annoying tho):
PHP Code:<?php
class ObjectList implements Iterator{
protected $objects = array();
protected $pos;
public function next(){
$this->pos++;
next($this->objects);
}
public function valid(){
return ($this->pos < count($this->objects));
}
public function key(){
return key($this->objects);
}
public function current(){
return current($this->objects);
}
public function rewind(){
$this->pos = 0;
reset($this->objects);
}
public function insert($object){
$this->objects[strval($object)] = $object;
}
public function clear(){
$this->objects = array();
}
}
$o = new ObjectList;
$o->insert("hej");
$o->insert(" ");
$o->insert("älskling");
foreach($o as $v){
var_dump($v);
if($v == " ")
$o->insert(" <3 ");
}
?>
-
Feb 17, 2006, 10:51 #66
Sigh, three posts in a row no, ah well - another thing on my mind is this:
If a transaction fail, should the ORM automaticly rollback the transaction or let the user decide what to do?
-
Feb 17, 2006, 11:15 #67
Originally Posted by thr
PHP Code:$names = new ArrayObject(array("fredrik","madeleine"));
foreach($names as $name)
{
echo $name . "<br />";
if($name == 'fredrik')
$names[] = 'thr';
}
Also there is an AppendIterator interface.
Edit scratch that, it appends another iterator rather than value.
-
Feb 17, 2006, 11:18 #68
haha, how could i miss that ;p thanks ren.
-
Feb 17, 2006, 11:27 #69
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If a transaction fail, should the ORM automaticly rollback the transaction or let the user decide what to do?
-
Feb 17, 2006, 12:29 #70
Originally Posted by thr
-
Feb 17, 2006, 12:45 #71
Originally Posted by 33degrees
If you mean that it's a valid domain object that got all required fields set(no NULLs, etc.) and doesn't already exists in the db, etc - then yes.
-
Feb 17, 2006, 18:26 #72
Originally Posted by thr
-
Feb 18, 2006, 01:49 #73
Just a quick question to all of you: Which type of inheritance mapping would you prefer?
1. Single Table Inhertiance (PoEAA p.278) (One table for all classes)
2. Class Table Inheritance (PoEAA p.285) (Different tables for all classes with only the "extra" fields that are added in a subclass in each sub-class table)
3. Concrete Table Inheritance (PoEAA p.293) (Different tables for all classes with all fields for one class in that table)
Personally Single(1) or Concrete(3) seems the easiest to implement and also the fastest ones in terms of mysql queries. Class(2) seems like the "purest" choice but also the hardest to implement. 1 Has the drawback that the table you're using easily could get cluttered with all types of fields for different subclasses. 2. Has the drawback that it requires quite an amount of queries/subqueries if you get deep inheritance, 3. Has the drawback that one change in the top class requires a table schema change in every other also.
So which one is the lesser of three evils?
Originally Posted by 33degrees
-
Feb 18, 2006, 04:43 #74
I ran into another problem with Optimistic Offlinelocking and php today, more specific this: It's not possible to use "standard" offline locking with php as the client doesn't hold the state of an object. That means that if you do the "normal" route with just one version field and you "lock()" an object, on the next page/application run that object will be fetched again and the version field will be updated to the latest version meaning that the "lock" will be valid at all times.
Now there's two workarounds for this(as far as I can see):
1. Save the object you're updating in the current session(you store the object in $_SESSION['locked'] and you can fetch your locked objects thru the LockingManager for example)
2. Use a lockingtable for Optimistic Offlinelocking also(where you store the key for the object, the type for the object, who locked it and what version he had when he locked it)
Or am I missing something crucial and just confusing myself?
-
Feb 18, 2006, 06:58 #75
Originally Posted by thr
Bookmarks