Mercurial Hosting > luan
diff src/luan/modules/lucene/PostgresBackup.java @ 1562:b89212fd04b5
remove table.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 08 Nov 2020 16:50:59 -0700 |
parents | 26c51acf00f3 |
children | 8fbcc4747091 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/PostgresBackup.java Thu Nov 05 20:24:09 2020 -0700 +++ b/src/luan/modules/lucene/PostgresBackup.java Sun Nov 08 16:50:59 2020 -0700 @@ -34,7 +34,7 @@ private final PreparedStatement updateStmt; private final PreparedStatement deleteStmt; private int trans = 0; - private final LuanToString luanToString = new LuanToString(null,null); + private final LuanToString luanToString; PostgresBackup(Luan luan,LuanTable spec) throws ClassNotFoundException, SQLException, LuanException @@ -82,6 +82,7 @@ "delete from lucene where id=?" ); + luanToString = new LuanToString(luan,null,null); luanToString.settingsInit.strict = true; luanToString.settingsInit.numberTypes = true; } @@ -102,23 +103,23 @@ super.finalize(); } - void add(LuanTable doc) throws LuanException, SQLException { - Long id = (Long)doc.get("id"); + void add(Luan luan,LuanTable doc) throws LuanException, SQLException { + Long id = (Long)doc.get(luan,"id"); String data = luanToString.toString(doc); insertStmt.setLong(1,id); insertStmt.setString(2,data); insertStmt.executeUpdate(); } - void update(LuanTable doc) throws LuanException, SQLException { - Long id = (Long)doc.get("id"); + void update(Luan luan,LuanTable doc) throws LuanException, SQLException { + Long id = (Long)doc.get(luan,"id"); String data = luanToString.toString(doc); updateStmt.setString(1,data); updateStmt.setLong(2,id); int n = updateStmt.executeUpdate(); if( n==0 ) { logger.error("update not found for id="+id+", trying add"); - add(doc); + add(luan,doc); } else if( n!=1 ) throw new RuntimeException(); } @@ -158,12 +159,11 @@ void restoreLucene(LuceneIndex li) throws LuanException, IOException, SQLException, ParseException { - 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)LuanParser.parse(luan,data); + LuanTable doc = (LuanTable)LuanParser.parse(data); li.restore(doc); } stmt.close(); @@ -172,7 +172,6 @@ final class Checker { private final Connection con; private final PreparedStatement pstmt; - private final Luan luan = new Luan(); Checker() throws SQLException { con = newConnection(); @@ -205,7 +204,7 @@ if( !rs.next() ) return null; String data = rs.getString("data"); - LuanTable doc = (LuanTable)LuanParser.parse(luan,data); + LuanTable doc = (LuanTable)LuanParser.parse(data); return doc; } }