use of com.j256.ormlite.dao.Dao in project krypton-android by kryptco.
the class Approval method deleteExpiredApprovals.
public static synchronized void deleteExpiredApprovals(Dao<Approval, Long> db, Long temporaryApprovalSeconds) throws SQLException {
DeleteBuilder deleteExpiredPolicyAffectedApprovals = db.deleteBuilder();
deleteExpiredPolicyAffectedApprovals.where().notIn("type", ApprovalType.READ_TEAM_DATA).and().le("approved_at", new Date(System.currentTimeMillis() - temporaryApprovalSeconds * 1000));
deleteExpiredPolicyAffectedApprovals.delete();
DeleteBuilder deleteExpiredReadTeamApprovals = db.deleteBuilder();
deleteExpiredReadTeamApprovals.where().eq("type", // Always 6 hours
ApprovalType.READ_TEAM_DATA).and().le("approved_at", new Date(System.currentTimeMillis() - (Policy.READ_TEAM_TEMPORARY_APPROVAL_SECONDS) * 1000));
deleteExpiredReadTeamApprovals.delete();
}
use of com.j256.ormlite.dao.Dao in project entando-core by entando.
the class TableFactory method createTable.
private void createTable(Class tableClass, ConnectionSource connectionSource) throws Throwable {
int result = 0;
String logTableName = this.getDatabaseName() + "/" + getTableName(tableClass);
try {
result = ApsTableUtils.createTable(connectionSource, tableClass);
if (result > 0) {
_logger.info("Created table - {}", logTableName);
Object tableModel = tableClass.newInstance();
if (tableModel instanceof ExtendedColumnDefinition) {
String[] extensions = ((ExtendedColumnDefinition) tableModel).extensions(this.getType());
if (null != extensions && extensions.length > 0) {
Dao dao = DaoManager.createDao(connectionSource, tableClass);
for (int i = 0; i < extensions.length; i++) {
String query = extensions[i];
dao.executeRaw(query);
}
}
}
} else {
throw new RuntimeException("Error creating table from class " + logTableName);
}
} catch (Throwable t) {
_logger.error("Error creating table {}", logTableName, t);
if (result > 0) {
TableUtils.dropTable(connectionSource, tableClass, true);
}
throw new ApsSystemException("Error creating table " + logTableName, t);
}
}
use of com.j256.ormlite.dao.Dao in project BachelorPraktikum by lucasbuschlinger.
the class VaultDAO method initDb.
/**
* Initializes the actual database as a {@link JdbcConnectionSource}.
*
* @throws SQLException Thrown if the database can not be successfully initialized.
*/
private void initDb() throws SQLException {
// create a connection source to our database
connectionSource = new JdbcConnectionSource(DATABASE_URL, "sa", "", new HsqldbDatabaseType());
// instantiate the DAO
vaultDao = DaoManager.createDao(connectionSource, VaultEntry.class);
if (!vaultDao.isTableExists()) {
TableUtils.createTableIfNotExists(connectionSource, VaultEntry.class);
} else {
LOG.warning("Found existing DB for VaultEntries. Reusing it!!");
}
// TableUtils.createTableIfNotExists(connectionSource, SliceEntry.class);
}
use of com.j256.ormlite.dao.Dao in project ETSMobile-Android2 by ApplETS.
the class NoteManager method deleteExpiredElementsEvaluation.
/**
* Deletes marks in DB that doesn't exist on API
*
* @param
*/
public void deleteExpiredElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
HashMap<String, ElementEvaluation> elementEvaluationHashMap = new HashMap<String, ElementEvaluation>();
for (ElementEvaluation elem : listeDesElementsEvaluation.liste) {
String id = listeDesElementsEvaluation.id + elem.nom;
elementEvaluationHashMap.put(id, elem);
}
List<ElementEvaluation> elementEvaluationList = null;
try {
Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
QueryBuilder<ElementEvaluation, String> builder = elementsEvaluationDao.queryBuilder();
Where where = builder.where();
where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
elementEvaluationList = builder.query();
for (ElementEvaluation element : elementEvaluationList) {
if (!elementEvaluationHashMap.containsKey(element.id))
elementsEvaluationDao.deleteById(element.id);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
use of com.j256.ormlite.dao.Dao in project ETSMobile-Android2 by ApplETS.
the class NoteManager method getElementsEvaluation.
public List<ElementEvaluation> getElementsEvaluation(ListeDesElementsEvaluation listeDesElementsEvaluation) {
DatabaseHelper dbHelper = new DatabaseHelper(context);
List<ElementEvaluation> elementEvaluationList = null;
try {
Dao<ElementEvaluation, String> elementsEvaluationDao = dbHelper.getDao(ElementEvaluation.class);
QueryBuilder<ElementEvaluation, String> builder = elementsEvaluationDao.queryBuilder();
Where where = builder.where();
where.eq("listeDesElementsEvaluation_id", listeDesElementsEvaluation);
elementEvaluationList = builder.query();
} catch (SQLException e) {
Log.e("SQL Exception", e.getMessage());
}
return elementEvaluationList;
}
Aggregations