Sisäänkirjautuminen| Uusi tunnus
FrontPage| Projects| Forums| Search|
^ DaoGen Forums: › Why? › PHP5? › Using ToString() with PHP › Next DaoGen version almost ready! › Create (insert) and Save (update) PHP examples › Support for numeric object types almost ready! › DaoGen 2.1.0 released! › Compliments and minor suggestion › variables within a class › Foreign key constraint in create() › Security issue!!! › auto-generated columns and create method › Oracle BLOB › DAO for cross-table queries › Please help me.. › Please use this forum for DaoGen related stuff › Call-time Pass-By-Reference › DaoGen 2.4.0 has been released! › How can I show relationships? › DaoGen & PHP 5 › PHP4 vs PHP5 and other considerations. › singleQuery example in php › Why are save and delete not synchronized? › Why are save and delete not synchronized? › DTD for generated XML › DaoGen 2.2.2 has been released! › DaoGen 2.0.2 is available. › For a thesis ?? › Extremely good idea ?? how can I ???? › Usability suggestions for DaoGen › Performance of DaoGen with Mapping tools › Performance with List › Some usage statistics › DaoGen 2.2.1 has been released! › Programming Examples are back! › DaoGen 2.0.1 is available. › Version 2.0.0 generates buggy PHP code! New version soon available! » Examples of DaoGen customizations › Code Examples
Sisäänkirjautuminen
» Käyttäjätunnus:
» Salasana:
» Muista kirjautuminen:
Suosituimmat sivut: › DaoGen Forums › DaoGen 2.1.0 released! › Programming Examples › DaoGen FAQ › DaoGen Manual › Using ToString() with PHP › Projects › Search › Forums › DaoGen
FrontPage » Forums » DaoGen Forums » Examples of DaoGen customizations

Examples of DaoGen customizations

Posted by aradius 11:43:45 AM

Hello,

I used DaoGen to generate some source code, and I customized generated sources in order to make it works with a little project.
I don't have bugs to report, but I just wanted to send you my comments about my customization, if it can be useful to improve the DaoGen or add some stuff to generated code.
Sources I include here are generated from a previous version of DaoGen (before 2.0.0).

Thanks for this generator.

######################################

Here is example I used :
table : article
columns : id int, label varchar, ....

######################################

I modified source code like this :

#####################
# in Article.java : #
#####################

- implementing java.io.Serializable for bean object :
public class Article implements Serializable

- add equals(Object valueObject) method :

public boolean equals(Object valueObject) {
if ((valueObject == null) || (!( valueObject instanceof Article))){
return false;
}
else if (this == valueObject) {
return true;
}
else {
return equals((Article)valueObject);
}
}

Without equals(Object valueObject) method, I have errors when I try to compare objects in a Collection ; Collection.contains(Object) always return false.
This was before renaming of method equals() to hasEqualMapping().

- do :
private Integer id;

instead of
private int id;

because in ArticleDAO.searchMatching method, there is the test :

if (valueObject.getIdentifiant() != 0) {
if (first) {
first = false;
}
sql.append("AND identifiant = ").append(
valueObject.getIdentifiant()).append(
" ");
}
ie. if field equals 0 then its value is not added to SQL request.
But sometimes, it could be useful to test if an int column has 0 value in SQL request.

with my Article bean having only object properties, this is :
if (valueObject.getIdentifiant() != null) {
//...
}

######################
# in ArticleDao.java #
######################

- in methods load, loadAll, create, save, delete, deleteAll, countAll, searchMatching, I remove Connection parameter, and make them use a getConnection method, because in my project, these methods are called from an business object, and this business object of my project don't import java.sql packages and can't create a new Connection:

public List loadAll() throws SQLException {

//...
Connection conn = getConnection();
searchResults = listQuery(conn, conn.prepareStatement(sql));
return searchResults;
}


- Add a loadAll(int offset, int limit) method to get a sublist for pagination. (Uses same code as loadAll but concatenate request String with instruction "LIMIT "+offset+" "+limit+" ")

- Add a countMatching(Article valueObject) method to return the number of all rows from table that matches valueObject

- Convert :
public void load(...)
to :
public Article load(...)

like loadAll method, this method return an object.

- Same thing for singleQuery method.

############
# Others : #
############

- Add a utility class to get SQL connection

- Create a DAOException thrown by all DAO method instead of SQLException : because business objects of my project don't import any java.sql.* class.


Re: Examples of DaoGen customizations

Posted by anonymous 20.05.2004 19:45

I'd like to see:
A class that is used to create connection and DAO objects assume a connection can be obtained from this class. Then we can customize this new class like implementing a pool, loading initial db configuration and etc.


Re: Re: Examples of DaoGen customizations

Posted by anonymous 20.05.2004 19:48

It's a way to isolate business logics and physical DB operations.


Re: Re: Re: Examples of DaoGen customizations

Posted by Luigi 22.05.2004 10:15

> anonymous 20.05.2004 19:48
> It's a way to isolate business logics and physical DB operations.

Thanks for your feedback!

I understand the need for this type of class. I will seriously consider it. The biggest problem with that is, that it would break the current API, which assumes the Connection parameter for each method. (There exists quite a lot code that depends on the DaoGen API.)

// Luigi.