use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class H2InMemoryDatabaseProxy method clean.
/**
* @throws Exception
*/
public void clean() throws Exception {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(getDataSource());
runScript(new String[] { "DROP ALL OBJECTS;" }, null);
runScript(this.getClass().getResourceAsStream("/createTables-" + getType().name() + ".sql"), null);
for (DatabaseSchemaDefinition def : ModuleRegistry.getDefinitions(DatabaseSchemaDefinition.class)) def.newInstallationCheck(ejt);
SystemSettingsDao.instance.setValue(SystemSettingsDao.DATABASE_SCHEMA_VERSION, Integer.toString(Common.getDatabaseSchemaVersion()));
// Add the settings flag that this is a new instance. This flag is removed when an administrator
// logs in.
SystemSettingsDao.instance.setBooleanValue(SystemSettingsDao.NEW_INSTANCE, true);
User user = new User();
user.setId(Common.NEW_ID);
user.setName("Administrator");
user.setUsername("admin");
user.setPassword(Common.encrypt("admin"));
user.setEmail("admin@yourMangoDomain.com");
user.setPhone("");
user.setPermissions(SuperadminPermissionDefinition.GROUP_NAME);
user.setDisabled(false);
UserDao.instance.saveUser(user);
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class H2InMemoryDatabaseProxy method runScript.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.DatabaseProxy#runScript(java.lang.String[], java.io.OutputStream)
*/
@Override
public void runScript(String[] script, OutputStream out) throws Exception {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(getDataSource());
StringBuilder statement = new StringBuilder();
for (String line : script) {
// Trim whitespace
line = line.trim();
// Skip comments
if (line.startsWith("--"))
continue;
// Replace macros in the line
// line = com.serotonin.util.StringUtils.replaceMacro(line, "blob", replacement("blob"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "char", replacement("char"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "clob", replacement("clob"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "double", replacement("double"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "identity", replacement("identity"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "int", replacement("int"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "varchar", replacement("varchar"));
//
// line = com.serotonin.util.StringUtils.replaceMacro(line, "ALTER COLUMN", replacement("ALTER COLUMN"));
// line = com.serotonin.util.StringUtils.replaceMacro(line, "DROP FOREIGN KEY",
// replacement("DROP FOREIGN KEY"));
statement.append(line);
statement.append(" ");
if (line.endsWith(";")) {
// Execute the statement
ejt.execute(statement.toString());
statement.delete(0, statement.length() - 1);
}
}
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class EventDao method purgeEventsBefore.
public int purgeEventsBefore(final long time) {
// Find a list of event ids with no remaining acknowledgments pending.
final ExtendedJdbcTemplate ejt2 = ejt;
int count = getTransactionTemplate().execute(new TransactionCallback<Integer>() {
@Override
public Integer doInTransaction(TransactionStatus status) {
int count = ejt2.update("delete from events where activeTs<?", new Object[] { time });
// Delete orphaned user comments.
ejt2.update("delete from userComments where commentType=" + UserCommentVO.TYPE_EVENT + " and typeKey not in (select id from events)");
return count;
}
});
return count;
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class EventDao method purgeEventsBefore.
/**
* Purge Events Before a given time with a given alarmLevel
* @param time
* @param typeName
* @return
*/
public int purgeEventsBefore(final long time, final int alarmLevel) {
// Find a list of event ids with no remaining acknowledgments pending.
final ExtendedJdbcTemplate ejt2 = ejt;
int count = getTransactionTemplate().execute(new TransactionCallback<Integer>() {
@Override
public Integer doInTransaction(TransactionStatus status) {
int count = ejt2.update("delete from events where activeTs<? and alarmLevel=?", new Object[] { time, alarmLevel });
// Delete orphaned user comments.
ejt2.update("delete from userComments where commentType=" + UserCommentVO.TYPE_EVENT + " and typeKey not in (select id from events)");
return count;
}
});
return count;
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class EventDao method purgeEventsBefore.
/**
* Purge Events Before a given time with a given typeName
* @param time
* @param typeName
* @return
*/
public int purgeEventsBefore(final long time, final String typeName) {
// Find a list of event ids with no remaining acknowledgments pending.
final ExtendedJdbcTemplate ejt2 = ejt;
int count = getTransactionTemplate().execute(new TransactionCallback<Integer>() {
@Override
public Integer doInTransaction(TransactionStatus status) {
int count = ejt2.update("delete from events where activeTs<? and typeName=?", new Object[] { time, typeName });
// Delete orphaned user comments.
ejt2.update("delete from userComments where commentType=" + UserCommentVO.TYPE_EVENT + " and typeKey not in (select id from events)");
return count;
}
});
return count;
}
Aggregations