We are developing an application where we will generate forms at run time. Now we need to perform CRUD operations on the data of the dynamic form.
we want to save the record into the table by writing
Map<String, String> map = new TreeMap<>();
map.put("name","User Name");
map.put("dob", "30-3-1995");
map.put("address", "Address Line");
map.put("city", "Jaipur");
/* insert into user table */
db.insert("user",map); // SAME AS JPA
Does java spring boot provides query builder like php CodeIgniter query builder
I am trying to use JOOQ to achieve the same.
@Override
public void testingJooq(){
Field<String> username = field("username", String.class, "harigyan2");
// How bindings bind the value to the Field?
Field<String> password = field("password", String.class, "abcd");
Field<String> email = field("email", String.class, "hg2@server.com");
Field<Boolean> enabled = field("enabled", Boolean.TYPE, true);
// list of columns to insert
List<? extends Field<? extends Serializable>> columns = Arrays.asList(username, password, email, enabled);
// list of corresponding values as columns
List<? extends Field<? extends Serializable>> values = Arrays.asList(field("harigyan2", String.class), field("pwdhere", String.class), field("harigyan@server.com", String.class), field("1", Boolean.TYPE));
this.create.insertInto(table("user"), columns)
.values(values).getSQL();
}
The problems with the above code is that :
- the two lists columns and values should be in the same sequence and
- data types in the values should be matched with the table column data type in the code
Note : We can't use JOOQ with code generation because all the forms will be dynamic and will not have any corresponding Java Class (Entity class).
Map<String, Object> map = new TreeMap<>();
map.put("name","User Name");
map.put("dob", "30-3-1995");
map.put("address", "Address Line");
map.put("city", "Jaipur");
/* insert into user table */
this.create.insertInto(table('user')).values(map).execute();
It will be useful if above JOOQ insert statement find the fields names (map key name as column name) and values from the map<key, value> and create a insert sql statement.
We used php CodeIgniter in a project to build sql queries Php CodeIgniter Query Builder so we are trying to find something similar in java also.