JavaFX
KISS + Swing = RAD
How to rapidly develop enterprise class Swing applications by keeping things simple
Mar. 20, 2006 01:00 PM
Digg This!
Page 2 of 4
« previous page
next page »
/// This is a sample embeddable class representing an address.
Class base.Address Extends %SerialObject [ ClassType = serial, ProcedureBlock ]
{
Projection JavaClient As %Projection.Java;
/// Specify the proper Java Package
Parameter JAVAPACKAGE = "com.egrok.db.base";
/// The street address.
Property Street As %String(MAXLEN = 80);
/// The city name.
Property City As %String(MAXLEN = 80);
/// The 2-letter state abbreviation.
Property State As %String(MAXLEN = 2);
/// The 5-digit U.S. Zone Improvement Plan (ZIP) code.
Property Zip As %String(MAXLEN = 5);
}
The Person Class
Note that the Person class is being projected as a Java class in the package "com.egrok.db.base" and that the Person class has two properties that are derived from the serial address class: HomeAddress and WorkAddress. When you access these properties from the Java class, you'll use standard dot notation as follows:
Class base.Person Extends %Persistent [ ClassType = persistent, ProcedureBlock ]
{
Projection JavaClient As %Projection.Java;
/// Specify the proper Java Package
Parameter JAVAPACKAGE = "com.egrok.db.base";
Property Name As %String [ Required ];
Property LastName As %String;
Property HomeAddress As base.Address;
Property WorkAddress As base.Address;
Property Notes As %String(MAXLEN = 1000);
Property DateCreated As %TimeStamp;
/// Person is registered with the mailing list
Property IsRegistered As %Boolean;
}
person.getHomeAddress().getStreet();
The Employee Class
Class base.Employee Extends base.Person [ ClassType = persistent, ProcedureBlock ]
{
Projection JavaClient As %Projection.Java;
/// Specify the proper Java Package
Parameter JAVAPACKAGE = "com.egrok.db.base";
/// Specify the required property username
Property UserName As %String [ Required ];
/// Specify the username property must be unique
Index UserNameIndex On UserName [ Unique ];
Property Password As %String [ Required ];
/// The employee's current work status. Used when assigning jobs dynamically
Property WorkStatus As %String(VALUELIST = ",Available,Sick,Vacation,UnAvailable");
/// Defines a one to many relationship between the Department Object and Employee Objects
Relationship Department As base.Department [ Cardinality = one, Inverse = Employees ];
/// Defines an index on the Department property
Index DepartmentIndex On Department;
/// Specify the Employee's Manager - Example of Aggregation
Property Manager As base.Employee;
}
Here you can see that the Employee class extends the Person class and thus inherits all the properties and methods associated with the Person class. New properties specific to the Employee class are also added including a one-to-many relationship with the Department class and a reference to another employee, the Manager (an example of aggregation). We won't go into the details of parent/child and one-to-many relationships here since it's beyond the scope of this article.
Once again a Java Projection is defined. When you compile your class definitions, Java classes that provide access to the objects in the database will be created in the specified package. Simply by defining your database, you get access to pure Java objects that can be instantiated and persisted without any other code or mapping frameworks.
Tip: As with any Java class, you can extend the Java classes created by Caché (Java Projections) and add custom methods to them. Your application should then access these extended classes. This will insulate your application from most changes made to the class definition and preserve your custom methods, which would be overwritten the next time you compiled the database definition if you modify the Caché projection classes directly.
Example: Instantiating a Persistent Object
Listing 1 shows how to instantiate and access the Employee Java object from your Java code as well as some examples of how to access the data just as you would any other Java object.
That's it - straightforward Java objects. Just like any other persistence mechanism, you must connect to the database. However, once you've done that, you can access the object using standard dot notation. As you can see, you can also access linked objects (department and manager, for example) in the same manner without the need for creating multi-table SQL Joins. And remember - you've eliminated the need to define and maintain complex XML mappings for a JDO persistence layer!
Caché Tip: Use Caché's SQL projection when you are doing complex selection queries and updates to multiple objects at the same time. Use Caché's Object projection when dealing with a single object or linked objects.
Why Too Many Technologies Make Development and Maintenance Difficult
At this point, you've seen how to dramatically simplify and accelerate development on the server side, but you still need to get the data to the client and present it to the end user. Look under the hood of many Web -based applications today and you'll see a vast array of technologies and frameworks in use. A typical Struts application will require knowledge of HTML, JSP, XML, Java, and perhaps JSF and JavaScript. In addition, you have to learn Struts and possibly Tiles and some sort of Validation framework. (We'll forget about SQL and JDO for now, since we've solved that by using an object database.)
Page 2 of 4
« previous page
next page »
About Richard ConwayRichard Conway is a software developer and technology consultant with more than 15 years of technology, project management, and information services experience. He has extensive experience developing Java/Struts-based web applications. He started focusing more on Swing based developments at the beginning of 2005 and has just finished a Swing-based client/server asset management project. He lives in Miami with his wife Patricia, is currently working on an EMR application, and plays sand volleyball in his spare time.