db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael D. Cassidy" <mi...@logartsol.com>
Subject OJB template enhacement?
Date Mon, 15 Dec 2003 20:06:56 GMT
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


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message