@Override public LanguageSet getLoadedLanguages() throws DaoException { return metaDao.getLoadedLanguages(klass); }
@Override public int incrementErrors(Class component, Language lang) throws DaoException { MetaInfo info = getInfo(component, lang); int n = info.incrementNumErrors(); maybeFlush(info); return n; }
@Override public LanguageSet getLoadedLanguages(Class component) throws DaoException { sync(component); DSLContext context = getJooq(); try { if (!tableExists(context)) { return new LanguageSet(); } Set<Language> langs = new HashSet<Language>(); Result<Record1<Short>> records = context.select(Tables.META_INFO.LANG_ID) .from(Tables.META_INFO) .where(Tables.META_INFO.COMPONENT.eq(component.getSimpleName())) .and(Tables.META_INFO.LANG_ID.isNotNull()) .fetch(); for (Record1<Short> record : records) { langs.add(Language.getById(record.value1())); } return new LanguageSet(langs); } catch (Exception e) { throw new DaoException("Error when getting loaded languages, check if the database exists / has been initialized\n" + e.toString()); } finally { freeJooq(context); } }
@Override public void clear(Class component) throws DaoException { if (!tableExists()) { return; } DSLContext context = getJooq(); try { if (!context.meta().getTables().contains(Tables.META_INFO)) { return; } context.delete(Tables.META_INFO) .where(Tables.META_INFO.COMPONENT.eq(component.getSimpleName())) .execute(); } finally { freeJooq(context); } }
@Override public void sync(Class component) throws DaoException { if (counters.containsKey(component)) { for (MetaInfo mi : counters.get(component).values()) { flush(mi); } } }
@Override public int incrementErrors(Class component) throws DaoException { return incrementErrors(component, null); }
@Override public int incrementRecords(Class component) throws DaoException { return incrementRecords(component, 1); }
@Override public MetaInfoDao get(String name, Config config, Map<String, String> runtimeParams) throws ConfigurationException { if (!config.getString("type").equals("sql")) { return null; } try { return new MetaInfoSqlDao( getConfigurator().get( WpDataSource.class, config.getString("dataSource")) ); } catch (DaoException e) { throw new ConfigurationException(e); } } }
@Override public boolean isLoaded(Class component) throws DaoException { MetaInfo info = getInfo(component); return (info != null && info.getNumRecords() > 0); }
@Override public void endLoad() throws DaoException { sync(); super.endLoad(); wpDs.optimize(Tables.META_INFO); }
@Override public MetaInfo getInfo(Class component) throws DaoException { sync(component); MetaInfo accumulated = new MetaInfo(component); DSLContext context = getJooq(); try { if (!tableExists(context)) { return accumulated; } Result<Record3<Integer, Integer, Timestamp>> records = context.select(Tables.META_INFO.NUM_RECORDS, Tables.META_INFO.NUM_ERRORS, Tables.META_INFO.LAST_UPDATED) .from(Tables.META_INFO) .where(Tables.META_INFO.COMPONENT.eq(component.getSimpleName())) .fetch(); for (Record3<Integer, Integer, Timestamp> record : records) { MetaInfo info = new MetaInfo(component, null, record.value1(), record.value2(), record.value3()); accumulated.merge(info); } return accumulated; } finally { freeJooq(context); } }
@Override public Map<String, List<MetaInfo>> getAllInfo() throws DaoException { DSLContext context = getJooq(); try { Map<String, List<MetaInfo>> components = new HashMap<String, List<MetaInfo>>(); if (!tableExists(context)) { return components; freeJooq(context);
@Override public int incrementRecords(Class component, Language lang, int n) throws DaoException { MetaInfo info = getInfo(component, lang); n = info.incrementNumRecords(n); maybeFlush(info); return n; }
@Override public void sync() throws DaoException { for (Class klass : ((Map<Class, Map<Language, MetaInfo>>)counters).keySet()) { for (MetaInfo mi : counters.get(klass).values()) { flush(mi); } } }
@Override public int incrementErrorsQuietly(Class component){ try { return incrementErrors(component); } catch (DaoException e) { LOG.warn("incrementErrors failed:", e); return 0; } }
@Override public int incrementRecords(Class component, Language lang) throws DaoException { return incrementRecords(component, lang, 1); }
this.metaDao = (MetaInfoSqlDao) this; } else { this.metaDao = new MetaInfoSqlDao(wpDs);
@Override public Map<String, MetaInfo> getAllCummulativeInfo() throws DaoException { sync(); DSLContext context = getJooq(); try { Map<String, MetaInfo> components = new HashMap<String, MetaInfo>(); if (!tableExists(context)) { return components; freeJooq(context);