Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1446:f2082e9aeaa9 | 1447:851b9a48cc44 |
---|---|
15 import luan.LuanTable; | 15 import luan.LuanTable; |
16 import luan.LuanFunction; | 16 import luan.LuanFunction; |
17 import luan.LuanException; | 17 import luan.LuanException; |
18 import luan.modules.Utils; | 18 import luan.modules.Utils; |
19 import luan.modules.parsers.LuanToString; | 19 import luan.modules.parsers.LuanToString; |
20 import luan.modules.parsers.LuanParser; | |
21 import goodjava.parser.ParseException; | |
20 import goodjava.logging.Logger; | 22 import goodjava.logging.Logger; |
21 import goodjava.logging.LoggerFactory; | 23 import goodjava.logging.LoggerFactory; |
22 | 24 |
23 | 25 |
24 final class PostgresBackup { | 26 final class PostgresBackup { |
154 throw new LuanException("rollback failed trans="+trans); | 156 throw new LuanException("rollback failed trans="+trans); |
155 con.rollback(); | 157 con.rollback(); |
156 con.setAutoCommit(true); | 158 con.setAutoCommit(true); |
157 } | 159 } |
158 | 160 |
159 private static LuanTable newEnv() { | |
160 LuanTable env = new LuanTable(new Luan()); | |
161 LuanToString.addNumberTypes(env); | |
162 return env; | |
163 } | |
164 | |
165 private static Object eval(String s,LuanTable env) throws LuanException { | |
166 LuanFunction fn = env.luan().load( "return "+s, "PostgresBackup", false, env ); | |
167 return fn.call(); | |
168 } | |
169 | |
170 void restoreLucene(LuceneIndex li) | 161 void restoreLucene(LuceneIndex li) |
171 throws LuanException, IOException, SQLException | 162 throws LuanException, IOException, SQLException, ParseException |
172 { | 163 { |
173 LuanTable env = newEnv(); | 164 Luan luan = new Luan(); |
174 Statement stmt = con.createStatement(); | 165 Statement stmt = con.createStatement(); |
175 ResultSet rs = stmt.executeQuery("select data from lucene"); | 166 ResultSet rs = stmt.executeQuery("select data from lucene"); |
176 while( rs.next() ) { | 167 while( rs.next() ) { |
177 String data = rs.getString("data"); | 168 String data = rs.getString("data"); |
178 LuanTable doc = (LuanTable)eval(data,env); | 169 LuanTable doc = (LuanTable)LuanParser.parse(luan,data); |
179 li.restore(doc); | 170 li.restore(doc); |
180 } | 171 } |
181 stmt.close(); | 172 stmt.close(); |
182 } | 173 } |
183 | 174 |
193 } | 184 } |
194 | 185 |
195 final class Checker { | 186 final class Checker { |
196 private final Connection con; | 187 private final Connection con; |
197 private final PreparedStatement pstmt; | 188 private final PreparedStatement pstmt; |
198 private final LuanTable env = newEnv(); | 189 private final Luan luan = new Luan(); |
199 | 190 |
200 Checker() throws SQLException { | 191 Checker() throws SQLException { |
201 con = newConnection(); | 192 con = newConnection(); |
202 con.setReadOnly(true); | 193 con.setReadOnly(true); |
203 pstmt = con.prepareStatement( | 194 pstmt = con.prepareStatement( |
220 } | 211 } |
221 stmt.close(); | 212 stmt.close(); |
222 return ids; | 213 return ids; |
223 } | 214 } |
224 | 215 |
225 LuanTable getDoc(long id) throws SQLException, LuanException { | 216 LuanTable getDoc(long id) throws SQLException, ParseException { |
226 pstmt.setLong(1,id); | 217 pstmt.setLong(1,id); |
227 ResultSet rs = pstmt.executeQuery(); | 218 ResultSet rs = pstmt.executeQuery(); |
228 if( !rs.next() ) | 219 if( !rs.next() ) |
229 return null; | 220 return null; |
230 String data = rs.getString("data"); | 221 String data = rs.getString("data"); |
231 LuanTable doc = (LuanTable)eval(data,env); | 222 LuanTable doc = (LuanTable)LuanParser.parse(luan,data); |
232 return doc; | 223 return doc; |
233 } | 224 } |
234 } | 225 } |
235 | 226 |
236 Checker newChecker() throws SQLException { | 227 Checker newChecker() throws SQLException { |