1 / 12

ORM framework for AR Java API

ORM framework for AR Java API. Avishay Balderman 17-Jan-2009. Introduction[1]. About a year ago I had to work against AR application using AR Java API. I found that I write lots of code that is dealing with mapping.

elroy
Download Presentation

ORM framework for AR Java API

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ORM framework for AR Java API Avishay Balderman 17-Jan-2009

  2. Introduction[1] • About a year ago I had to work against AR application using AR Java API. I found that I write lots of code that is dealing with mapping. • I wrote code which map the AR Entry (Entry represents a record in AR) to the java beans I have in my application. • I also wrote code that is mapping the java bean into AR Entry.

  3. Introduction[2] • I understood that all Java developers who works with AR API do the same and I thought there must be a better way to do it. • Based on the fact that each field in AR form has unique ID I have implemented ORM framework that totally hide the AR Entry as well as the AR API from the developer.

  4. JPA • JPA stands for Java Persistence API. JPA is the standard API in today’s java. • The framework I have implemented is based on JPA, so when a java developer needs to work against AR - the learning curve hardly exists. (Assuming he did some JPA in the past)

  5. Bean generation[1] • The framework also offer a tool which can generate the bean code for the developer. • The developer needs to tell which forms and which fields he is interested in, and this tool will generate the java code for him. Since this tool is implemented as ANT task it can be used as part of the build lifecycle.

  6. Bean generation[2] • The developer does not have to use the code generation tool. The code can be written manually as well. • The bean code is just a regular Java bean code. • The “magic” is implemented by using Java annotations. Using those annotations the framework knows to map the bean to AR form and to map a bean attribute to a field in a form.

  7. The Person Form

  8. The ANT Task

  9. Bean example[1] @ARForm("Avishay:Person") public class Person extends Object implements java.io.Serializable { public String getRequestID() { return requestID; } public void setRequestID(String requestID) { this.requestID = requestID; } public String getPersonName() { return personName; } public void setPersonName(String personName) { this.personName = personName; } public FavoriteColor getFavoriteColor() { return favoriteColor; } public void setFavoriteColor(FavoriteColor favoriteColor) { this.favoriteColor = favoriteColor; }

  10. Bean example[2] public String getDemo() { return demo; } public void setDemo(String demo) { this.demo = demo; } @ARField(value = 1, originalFieldName = "Request ID") private String requestID; @ARField(value = 536870914, originalFieldName = "Person Name") private String personName; @ARField(value = 536870916, originalFieldName = "FavoriteColor") private FavoriteColor favoriteColor; @ARField(value = 536870917, originalFieldName = "Demo") private String demo; // The framework support Java Enum. public enum FavoriteColor { // implementation was removed because I had no space in the slide. } }

  11. Client code Example // Instantiate EntityManager EntityManager entityManager = new AREntityManager("tlv-esx-swim","Demo",0); // Instantiate a Java bean (The code for the 'Person' was auto generated by the ANT task) Person person = new Person(); // populate with some values person.setPersonName("ORM4AR"); person.setJoinField(112334); person.setDemo("Here is a demo.."); person.setFavoriteColor(Person.FavoriteColor.Red); // Save to AR entityManager.persist(person); System.out.println(person.getRequestID()); // Fetch a Person with the same primary key as the original person Person samePerson = entityManager.find(Person.class, person.getRequestID()); System.out.println(samePerson.getPersonName()); // query AR - look for all persons with a specific name and specific favorite color final String queryStr = "'FavoriteColor' = \"Red\" AND 'Person Name' = \"ORM4AR\""; Query query = entityManager.createNativeQuery(queryStr,Person.class); List<Person> resultList = (List<Person>)query.getResultList(); // loop over the results System.out.println("Start to loop over results:"); for (Person personIter : resultList) { System.out.println(personIter.getPersonName()); } // remove the person from AR entityManager.remove(samePerson); }

  12. Discussion • As we can see in the previous slide the ORM framework enables basic CRUD operations on top of AR Java API without direct use of the AR API and without doing the mapping from AR Entry to Java bean and the other way around. • The framework can save lots of development and maintenance time. • I think we should make this framework part of AR Java API and let developers inside and outside BMC use it and cut down the development time dramatically.

More Related