diff src/luan/modules/lucene/PostgresBackup.java @ 1447:851b9a48cc44

Luan.parse
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 18 Feb 2020 14:54:35 -0700
parents 56fb5cd8228d
children 928be2a4d565
line wrap: on
line diff
--- a/src/luan/modules/lucene/PostgresBackup.java	Tue Feb 11 13:38:55 2020 -0700
+++ b/src/luan/modules/lucene/PostgresBackup.java	Tue Feb 18 14:54:35 2020 -0700
@@ -17,6 +17,8 @@
 import luan.LuanException;
 import luan.modules.Utils;
 import luan.modules.parsers.LuanToString;
+import luan.modules.parsers.LuanParser;
+import goodjava.parser.ParseException;
 import goodjava.logging.Logger;
 import goodjava.logging.LoggerFactory;
 
@@ -156,26 +158,15 @@
 		con.setAutoCommit(true);
 	}
 
-	private static LuanTable newEnv() {
-		LuanTable env = new LuanTable(new Luan());
-		LuanToString.addNumberTypes(env);
-		return env;
-	}
-
-	private static Object eval(String s,LuanTable env) throws LuanException {
-		LuanFunction fn = env.luan().load( "return "+s, "PostgresBackup", false, env );
-		return fn.call();
-	}
-
 	void restoreLucene(LuceneIndex li)
-		throws LuanException, IOException, SQLException
+		throws LuanException, IOException, SQLException, ParseException
 	{
-		LuanTable env = newEnv();
+		Luan luan = new Luan();
 		Statement stmt = con.createStatement();
 		ResultSet rs = stmt.executeQuery("select data from lucene");
 		while( rs.next() ) {
 			String data = rs.getString("data");
-			LuanTable doc = (LuanTable)eval(data,env);
+			LuanTable doc = (LuanTable)LuanParser.parse(luan,data);
 			li.restore(doc);
 		}
 		stmt.close();
@@ -195,7 +186,7 @@
 	final class Checker {
 		private final Connection con;
 		private final PreparedStatement pstmt;
-		private final LuanTable env = newEnv();
+		private final Luan luan = new Luan();
 
 		Checker() throws SQLException {
 			con = newConnection();
@@ -222,13 +213,13 @@
 			return ids;
 		}
 
-		LuanTable getDoc(long id) throws SQLException, LuanException {
+		LuanTable getDoc(long id) throws SQLException, ParseException {
 			pstmt.setLong(1,id);
 			ResultSet rs = pstmt.executeQuery();
 			if( !rs.next() )
 				return null;
 			String data = rs.getString("data");
-			LuanTable doc = (LuanTable)eval(data,env);
+			LuanTable doc = (LuanTable)LuanParser.parse(luan,data);
 			return doc;
 		}
 	}