Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider support object mapping friendly CURD Methods #39

Open
gencube opened this issue Sep 3, 2015 · 2 comments
Open

Please consider support object mapping friendly CURD Methods #39

gencube opened this issue Sep 3, 2015 · 2 comments

Comments

@gencube
Copy link

gencube commented Sep 3, 2015

Since there is already support for this:
https://github.com/davidmoten/rxjava-jdbc#auto-mappings

int keyId = 
    db.update("insert into Person (pid, age, dob, sex, name) values (null, ?, ?, ?, ?) ")
      .parameters(person.getAge(), person.getDob(), person.isMale(), person.getName())
      .returnGeneratedKeys()
      .getAs(Integer.class)
      .toBlocking().single();

Please consider support for a concrete class:

int keyId = 
    db.insert(person)  // << Object AutoMapped Person for insert.
      .returnGeneratedKeys()
      .getAs(Integer.class)
      .toBlocking().single();

Such support will reduce the amount of manual refactoring done for remodeling of Person object which rename or adding fields.

@gencube
Copy link
Author

gencube commented Sep 3, 2015

Also for update:

int count = db
    .update("update person set name=?, email=?, sex=?, age=?, dob=? where pid=?")
    .parameters(person.getName(), person.getEmail(), person.isMale(), person.getAge(), person.getDob(), person.getPid())
     .count().toBlocking().single();

Instead of the above, Please consider automapping support for a concrete class:

   int count = db.update(person)
                .count().toBlocking().single();

The main reason for this feature is that many existing legacy coding logic in ORM classes(like HibernateTemplate, Session):

http://www.tutorialspoint.com/hibernate/hibernate_examples.htm

Code example that many developers are ALREADY with:

/* Method to UPDATE salary for an employee */
   public void updateEmployee(Integer EmployeeID, int salary ){
      Session session = factory.openSession();
      Transaction tx = null;
      try{
         tx = session.beginTransaction();
         Employee employee = 
                    (Employee)session.get(Employee.class, EmployeeID); 
         employee.setSalary( salary );
         session.update(employee); 
         tx.commit();
      }catch (HibernateException e) {
         if (tx!=null) tx.rollback();
         e.printStackTrace(); 
      }finally {
         session.close(); 
      }
   }

@gencube
Copy link
Author

gencube commented Sep 3, 2015

I am actually tasked to write a simple STUB in classes(HibernateTemplate and Session class) TO REPLACE a few EXISTING Hibernate code in Production deployed Projects.

The main purpose for that is to speed up the query speed of business function without or MINIMUM code changes(import replacement only).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants