changeset 1268:725e52076f03

remove broken pooling
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 12 Nov 2018 03:54:04 -0700
parents 9fa8b8389578
children bcb39089e899
files src/luan/modules/sql/Database.java src/luan/modules/sql/Sql.luan
diffstat 2 files changed, 7 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
diff -r 9fa8b8389578 -r 725e52076f03 src/luan/modules/sql/Database.java
--- a/src/luan/modules/sql/Database.java	Mon Nov 12 02:10:41 2018 -0700
+++ b/src/luan/modules/sql/Database.java	Mon Nov 12 03:54:04 2018 -0700
@@ -1,6 +1,5 @@
 package luan.modules.sql;
 
-import java.io.Closeable;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.Statement;
@@ -17,28 +16,9 @@
 import luan.LuanException;
 
 
-public final class Database implements Closeable {
+public final class Database {
 	private static final Logger logger = LoggerFactory.getLogger(Database.class);
 
-	private static Map<Map,Database> pool = new HashMap<Map,Database>();
-
-	public static Database get(Connection con) {
-		return new Database(con);
-	}
-
-	public static synchronized Database get(LuanTable specTbl)
-		throws LuanException, ClassNotFoundException, SQLException
-	{
-		Map<Object,Object> spec = specTbl.asMap();
-		Database db = pool.get(spec);
-		if( db==null ) {
-			db = new Database(spec);
-			pool.put(spec,db);
-		}
-		return db;
-	}
-
-	public int uses = 0;
 	public final Connection con;
 	private final Map<String,PreparedStatement> pstmts = new HashMap<String,PreparedStatement>();
 
@@ -46,10 +26,10 @@
 		this.con = con;
 	}
 
-	private Database(Map<Object,Object> spec)
+	public Database(LuanTable specTbl)
 		throws LuanException, ClassNotFoundException, SQLException
 	{
-		spec = new HashMap<Object,Object>(spec);
+		Map<Object,Object> spec = specTbl.asMap();
 		String cls = getString(spec,"class");
 		Class.forName(cls);
 		String url = getString(spec,"url");
@@ -101,20 +81,4 @@
 		}
 	}
 
-	public void close() {
-		try {
-			con.close();
-		} catch(SQLException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	protected void finalize() throws Throwable {
-		if( !con.isClosed() ) {
-			logger.error("not closed");
-			close();
-		}
-		super.finalize();
-	}
-
 }
diff -r 9fa8b8389578 -r 725e52076f03 src/luan/modules/sql/Sql.luan
--- a/src/luan/modules/sql/Sql.luan	Mon Nov 12 02:10:41 2018 -0700
+++ b/src/luan/modules/sql/Sql.luan	Mon Nov 12 03:54:04 2018 -0700
@@ -13,7 +13,7 @@
 local mt = {}
 
 function mt.__gc(database)
-	if not database.is_closed then
+	if not database.is_closed() then
 		logger.error(database.created)
 		database.close()
 	end
@@ -22,24 +22,13 @@
 function Sql.database(spec)
 	local database = {}
 	set_metatable(database,mt)
-	local java_database = Database.get(spec)
-	java_database.uses = java_database.uses + 1
-	database.is_closed = false
+	local java_database = Database.new(spec)
 	database.java = java_database
 	database.created = new_error "not closed, created:"
+	database.close = java_database.con.close
+	database.is_closed = java_database.con.isClosed
 	database.update = java_database.update
 
-	function database.close()
-		if not database.is_closed then
-			database.is_closed = true
-			java_database.uses > 0 or error "java_database.uses <= 0"
-			java_database.uses = java_database.uses - 1
-			if java_database.uses == 0 then
-				java_database.close()
-			end
-		end
-	end
-
 	function database.query(sql,...)
 		local rs = java_database.query(sql,...)
 		local mt = {}