guidance on java class design -


i in process of building data tool allows users build etl code. before getting meat , bones of this, need build 'agent' deal database related work tool need perform. specifically, involve -

  • selecting, inserting, updating, , deleting
  • multiple records
  • from/to/in different tables different layouts

my thought build class following 4 methods -

arraylist[][] selectfromrepository  (string dbtable, string[] columnnames) arraylist[][] selectfromrepository  (string dbtable, string[] columnnames, map<string, object> predicate)  void          inserttorepository    (string dbtable, map<string, object>[] payload) void          updateinrepository    (string dbtable, map<string, object>[] payload, map<string,object>[] predicate) void          deletefromrepository  (string dbtable, map<string, object>[] payload) 

selectfromrepository respond 2d arraylist of heterogenous elements based on types of elements in "columnnames" retrieved argument "dbtable". overloaded version allows specifying clause predicate through "predicate" map. thinking inspect type of map object element passed method , build clause correctly (for e.g.

"where " + key + " = '" + predicate.get(k) + "'" if predicate.get(k) instanceof string  

and on ..

other methods work update methods predicate working similar of overloaded select.

i looking guidance on best practices, disadvantages of idea (and therefore advantages of doing way :) ). also, make sense build generic type called db element accepts known db data types expect work type input, , use instead of "object" type in map/arraylist arguments?

thanks in advance!

well quite question.

first of not implement myself. there number of free libraries out there (spring, hibernate) you, , better in form of orm (http://en.wikipedia.org/wiki/object-relational_mapping).

if want how this:

i follow ado , create class each table have. example make class employee employee table.

then create query builder such this:

querybuilder     .selectfrom(employee.class)     .equalto(propery, value)     .graterthenorequalto(property, value); 

my properties so:

interface property<from, to>{     get(from from); } 

so example:

class employeetoid<employee, integer>{     public integer get(employee emp){         return emp.id;     } } 

so in previos example:

querybuilder     .selectfrom(employee.class)     .equalto(new employeetoid(), 15)     .build().fetch(); // returns optional<collection<employee>>; 

my query builder have number methods such as:

class querybuilder{    public <entity> selectbuilder<entity> selectfrom(class<entity> clazz); } 

this jist of it. can make complex like. make good, take alot of time, ask hibernate or jooq.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -