comparison src/luan/modules/sql/Database.java @ 1420:225808b90cee

options handling
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 26 Oct 2019 22:21:09 -0600
parents 27efb1fcbcb5
children
comparison
equal deleted inserted replaced
1419:59fd2e8b1b9d 1420:225808b90cee
26 26
27 public Database(Connection con) { 27 public Database(Connection con) {
28 this.con = con; 28 this.con = con;
29 } 29 }
30 30
31 public Database(LuanTable specTbl) 31 public Database(LuanTable spec)
32 throws LuanException, ClassNotFoundException, SQLException 32 throws LuanException, ClassNotFoundException, SQLException
33 { 33 {
34 Map<Object,Object> spec = specTbl.asMap(); 34 spec = new LuanTable(spec);
35 String cls = Utils.removeRequiredString(spec,"class"); 35 String cls = Utils.removeRequiredString(spec,"class");
36 Class.forName(cls); 36 Class.forName(cls);
37 String url = Utils.removeRequiredString(spec,"url"); 37 String url = Utils.removeRequiredString(spec,"url");
38 Properties props = new Properties(); 38 Properties props = new Properties();
39 props.putAll(spec); 39 props.putAll(spec.asMap());
40 this.con = DriverManager.getConnection(url,props); 40 this.con = DriverManager.getConnection(url,props);
41 spec.remove("user"); 41 spec.remove("user");
42 spec.remove("password"); 42 spec.remove("password");
43 set(spec); 43 set2(spec);
44 } 44 }
45 45
46 public void set(LuanTable options) throws LuanException, SQLException { 46 public void set(LuanTable options) throws LuanException, SQLException {
47 set(options.asMap()); 47 set2(new LuanTable(options));
48 } 48 }
49 49
50 private void set(Map<Object,Object> options) throws LuanException, SQLException { 50 private void set2(LuanTable options) throws LuanException, SQLException {
51 Boolean autoCommit = Utils.removeBoolean(options,"auto_commit"); 51 Boolean autoCommit = Utils.removeBoolean(options,"auto_commit");
52 if( autoCommit != null ) 52 if( autoCommit != null )
53 con.setAutoCommit(autoCommit); 53 con.setAutoCommit(autoCommit);
54 Integer n = Utils.removeInteger(options,"fetch_size"); 54 Integer n = Utils.removeInteger(options,"fetch_size");
55 if( n != null ) 55 if( n != null )