You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by "Michael D. Cassidy" <mi...@logartsol.com> on 2003/12/15 21:06:56 UTC
OJB template enhacement?
To all,
While working with OJB, and using Torque as the generator, I
needed a constant to refer to the fields of the mapped classes when
building criteria for the persistence broker query. I added a small
block of code to the /templates/ojb/model/Object.vm template to populate
public constants for use in my bl layer. The code I added as well as my
usage is listed below. I have been a developer for many years, and
lately I have been more involved in the java community (although I still
like programming in VB.Net :). I am a CVS newbie, and don't completely
understand all the implications of CVS usage, but I would like to be
involved in the Torque and OJB projects. If you don't mind I will keep
playing with things, and send ideas or comments as they arise.
Object.vm excerpt:
public class ${table.JavaName} implements Serializable
{
// ---- added here
#foreach ($col in $table.Columns)
public static final String FIELD_$col.JavaName.toUpperCase() =
"$col.UncapitalisedJavaName";
#end
// ----- end of addition
#foreach ($col in $table.Columns)
private $col.JavaPrimitive $col.UncapitalisedJavaName;
#end
AuthUtil.java (usage)
broker = PersistenceBrokerFactory.defaultPersistenceBroker();
Criteria criteria = new Criteria();
criteria.addEqualTo(UserAuth.FIELD_USERNAME,
form.getUserName());
criteria.addEqualTo(UserAuth.FIELD_PASSWORD,
form.getPassword());
Query query = new
QueryByCriteria(UserAuth.class, criteria);
// ask the broker to retrieve the user
authentitcation data
userAuth = (UserAuth)
broker.getObjectByQuery(query);
if(userAuth != null) {
user = getUserByUserAuth(userAuth);
}
Michael D. Cassidy
Logical Art Solutions
misha@logartsol.com
Michael D. Cassidy
Logical Art Solutions
misha@logartsol.com
Re: OJB template enhacement?
Posted by Martin Poeschl <mp...@marmot.at>.
hi
i am on vacation in mexico at the moment :-)
i will be back on jan. 15th ...
i will work on the ojb templates later in jan when the generator
restructuring is finnished .. stay tuned ;-)
martin
> To all,
> While working with OJB, and using Torque as the generator, I
> needed a constant to refer to the fields of the mapped classes when
> building criteria for the persistence broker query. I added a small
> block of code to the /templates/ojb/model/Object.vm template to populate
> public constants for use in my bl layer. The code I added as well as my
> usage is listed below. I have been a developer for many years, and
> lately I have been more involved in the java community (although I still
> like programming in VB.Net :). I am a CVS newbie, and don't completely
> understand all the implications of CVS usage, but I would like to be
> involved in the Torque and OJB projects. If you don't mind I will keep
> playing with things, and send ideas or comments as they arise.
>
> Object.vm excerpt:
>
> public class ${table.JavaName} implements Serializable
> {
> // ---- added here
> #foreach ($col in $table.Columns)
> public static final String FIELD_$col.JavaName.toUpperCase()
> "$col.UncapitalisedJavaName";
> #end
> // ----- end of addition
>
> #foreach ($col in $table.Columns)
> private $col.JavaPrimitive $col.UncapitalisedJavaName;
> #end
>
>
> AuthUtil.java (usage)
>
> broker = PersistenceBrokerFactory.defaultPersistenceBroker();
> Criteria criteria = new Criteria();
> criteria.addEqualTo(UserAuth.FIELD_USERNAME,
> form.getUserName());
> criteria.addEqualTo(UserAuth.FIELD_PASSWORD,
> form.getPassword());
> Query query = new
> QueryByCriteria(UserAuth.class, criteria);
> // ask the broker to retrieve the user
> authentitcation data
> userAuth = (UserAuth)
> broker.getObjectByQuery(query);
> if(userAuth != null) {
> user = getUserByUserAuth(userAuth);
> }
>
> Michael D. Cassidy
> Logical Art Solutions
> misha@logartsol.com
>
>
>
> Michael D. Cassidy
> Logical Art Solutions
> misha@logartsol.com
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org