System.out.println("... from " + enabledCount + " channels");
System.out.println("... using cache at " + config.cacheDbHandle);
}
-
+ if (clearCache) {
+ ProgrammeCache cache = new ProgrammeCache(config);
+ cache.clear();
+ cache.close();
+ }
Map<Integer,EPGSource> guides = new HashMap<Integer,EPGSource>();
EPGSourceFactory factory = EPGSourceFactory.newInstance();
//EPGSource gids = new TvGids(config);
if (!config.quiet) System.out.print(".");
if(!guides.containsKey(c.source)) {
guides.put(c.source, factory.createEPGSource(c.source, config));
- if (clearCache) guides.get(c.source).clearCache();
}
List<Programme> programmes = guides.get(c.source).getProgrammes(c, day);
for (Programme p: programmes) p.serialize(writer);
private PreparedStatement putStatement;
private PreparedStatement removeStatement;
private PreparedStatement clearStatement;
+ private PreparedStatement clearSourceStatement;
private final static Integer SCHEMA_VERSION=1;
private final static String SCHEMA_KEY="TV_GRAB_NL_JAVA_SCHEMA_VERSION";
putStatement = db.prepareStatement("INSERT INTO cache VALUES (?,?,?,?)");
removeStatement = db.prepareStatement("DELETE FROM cache WHERE source=? AND id=?");
clearStatement = db.prepareStatement("DELETE FROM cache");
+ clearSourceStatement = db.prepareStatement("DELETE FROM cache WHERE source=?");
} catch (SQLException e) {
if (!config.quiet) {
System.out.println("Unable to prepare statements, proceeding without cache");
}
}
+ public void clear(int source) {
+ if (db==null) return;
+ try {
+ clearSourceStatement.setInt(1, source);
+ int count = clearSourceStatement.executeUpdate();
+ if (!config.quiet && count>0) {
+ System.out.println("Cleared " + count + " entries from cache for source " + source);
+ }
+ } catch (SQLException e) {
+ if (config.logLevel>=Config.LOG_DEBUG) e.printStackTrace();
+ }
+ }
+
public void close() {
cleanup();
if (db != null) {
putStatement.close();
removeStatement.close();
clearStatement.close();
+ clearSourceStatement.close();
db.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
}
}
}
+
}