Page 1 of 1

DAO Generator Design

Posted: Thu Nov 30, 2006 6:00 pm
by rockboy
hey all

i'm about to embark on creating a DAO generator, which not only generates the php code for the class for each table, but also generates all the sql stored procedures thus enabling the php classes to access only stored procedures rather then sending long sql strings to the database, i have had a look arround at some DAO generators, or extenable classes already and whilst there are some good basic ones i'm just not happy with the crap they send to the database.

Now my class structure will look like this :
- > BaseClass (All the functions for database and functions for differant datatypes, eg date functions etc)
- > DAO (using base class to access DB via stored procs, this is what will be generated)
->Business Logic for each generated class (Will extend the DAO, but will not change when database is rebuilt, and dao regenerated)
- > Php script (using smarty template or include html files with php variables included, like a light light smarty templte)
- > smarty template / html file

So i have a few questions regarding this design

Is it too code heavy, and will that affect it speed in a big way, as in having to load so many files and classes for one page execution?
How good is php accelerator for solving this?
Is there a DAO generator that already uses Stored procedures?
What other pro's - con's can you see?

Many thanks in advance

glen

Posted: Fri Dec 01, 2006 1:02 am
by Christopher
Two thoughts: first, I don't think you should be too concerned with performance at this point. Most code generators do a pretty good job within their range -- it is flexibility that is always harder to achieve. And second, why are you going all the way to HTML? It seems like the generator coded should stay focused on creating solid Model classes. You could always build specific scaffolding for CRUD, etc. later, but that stuff is usually pretty specific/custom.

Posted: Thu Dec 07, 2006 11:29 am
by obiron
Before you go re-inventing the wheel, have a look at http://www.tonymarston.net who has an excellent tutorial on abstract ADO classes.

He has basically created a vanilla class with four methods:-


addData()
fetchData()
changeData()
deleteData()

and then extends this for each table in his database so all ADO classes use the same methods.

He also has a set of tools for building a data dictionary from the class files which you can edit to add additional parameters like required, primary key, candidate key, length validation etc. which makes building forms and validating data easier. I am sure that you could use some of the concepts in auto building stored procedures.

Posted: Thu Dec 14, 2006 11:33 am
by BDKR
Well, I'm game to see what you come up with. My DAO stuff has been relatively light weight to date, but I'm rethinking some of my outlook in this area. That means I'm opening up to new ideas.

Keep us posted.

Posted: Mon Dec 18, 2006 9:34 am
by raghavan20
I do not think having stored procedures makes your life easier in this case.
when you are especially using OO, you might have to apply more logics for basic CRUD and implementing them in stored procedures is bit complex and unmaintainable.

let us say, if you want to create a new user( user has a table and also a class ). Then nomatter you have a stored procedure or not, you are going to pass data from PHP to DB and use queries to create a record( so the queries are there immaterial of whether you write in PHP or in DB stored procedure )

if you want to load an user object, anyway stored procedure or your PHP query has to get data from DB so data is transferred at all times.

Stored procedures are supposed to be used only when there is a lot of associated actions with an action and that does not really require any data outside of DB. But it is still possible to write everything in stored procedure and make an application work but you may not be able to use OO principles effecively.