public boolean tableExists() throws DaoException { DSLContext context = getJooq(); try { return JooqUtils.tableExists(context, Tables.META_INFO); } 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); } }
freeJooq(context);
freeJooq(context);
@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); } }
freeJooq(context);
@Override public void clear(Class component, Language lang) throws DaoException { if (!tableExists()) { return; } DSLContext context = getJooq(); try { context.delete(Tables.META_INFO) .where(Tables.META_INFO.COMPONENT.eq(component.getSimpleName())) .and(Tables.META_INFO.LANG_ID.eq(lang.getId())) .execute(); JooqUtils.commit(context); } catch (RuntimeException e) { JooqUtils.rollbackQuietly(context); throw e; } catch (DaoException e) { JooqUtils.rollbackQuietly(context); throw e; } finally { freeJooq(context); } }
@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); } }
throw e; } finally { freeJooq(context);