use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-modules-public by infiniteautomation.
the class SqlController method handleRequest.
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, final Map<String, Object> model) throws Exception {
Permissions.ensureAdmin(Common.getHttpUser());
model.put("updateResult", -1);
try {
final String serializedDataMsg = ControllerUtils.translate(request, "sql.serializedData");
final String sqlString = request.getParameter("sqlString");
model.put("sqlString", sqlString);
model.put("updateResult", -1);
if (WebUtils.hasSubmitParameter(request, "query"))
query(sqlString, serializedDataMsg, model);
else if (WebUtils.hasSubmitParameter(request, "update")) {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(Common.databaseProxy.getDataSource());
int result = ejt.update(sqlString);
model.put("updateResult", result);
} else if (WebUtils.hasSubmitParameter(request, "tables"))
query(Common.databaseProxy.getTableListQuery(), serializedDataMsg, model);
} catch (RuntimeException e) {
model.put("error", e.getMessage());
LOG.warn("", e);
}
return null;
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-modules-public by infiniteautomation.
the class ScheduledEventDao method deleteScheduledEvent.
public void deleteScheduledEvent(final int scheduledEventId) {
ScheduledEventVO se = getScheduledEvent(scheduledEventId);
final ExtendedJdbcTemplate ejt2 = ejt;
if (se != null) {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
ejt2.update("delete from eventHandlersMapping where eventTypeName=? and eventTypeRef1=?", new Object[] { ScheduledEventType.TYPE_NAME, scheduledEventId });
ejt2.update("delete from scheduledEvents where id=?", new Object[] { scheduledEventId });
}
});
AuditEventType.raiseDeletedEvent(AuditEvent.TYPE_NAME, se);
this.countMonitor.decrement();
}
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-modules-public by infiniteautomation.
the class MaintenanceEventDao method deleteMaintenanceEvent.
public void deleteMaintenanceEvent(final int maintenanceEventId) {
MaintenanceEventVO me = getMaintenanceEvent(maintenanceEventId);
final ExtendedJdbcTemplate ejt2 = ejt;
if (me != null) {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
ejt2.update("delete from eventHandlersMapping where eventTypeName=? and eventTypeRef1=?", new Object[] { MaintenanceEventType.TYPE_NAME, maintenanceEventId });
ejt2.update("delete from maintenanceEvents where id=?", new Object[] { maintenanceEventId });
}
});
AuditEventType.raiseDeletedEvent(AuditEvent.TYPE_NAME, me);
}
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class H2InMemoryDatabaseProxy method initialize.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.DatabaseProxy#initialize(java.lang.ClassLoader)
*/
@Override
public void initialize(ClassLoader classLoader) {
JdbcDataSource jds = new JdbcDataSource();
String url = "jdbc:h2:mem:" + databaseName + ";DB_CLOSE_DELAY=-1";
jds.setUrl(url);
dataSource = JdbcConnectionPool.create(jds);
transactionManager = new DataSourceTransactionManager(dataSource);
if (initWebConsole) {
String[] webArgs = new String[4];
webArgs[0] = "-webPort";
webArgs[1] = webPort.toString();
webArgs[2] = "-ifExists";
webArgs[3] = "-webAllowOthers";
try {
this.web = Server.createWebServer(webArgs);
this.web.start();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(getDataSource());
// Create the empty database
if (!tableExists(ejt, SchemaDefinition.USERS_TABLE)) {
// The users table wasn't found, so assume that this is a new instance.
// Create the tables
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()));
SystemSettingsDao.instance.setValue(SystemSettingsDao.BACKUP_ENABLED, "false");
SystemSettingsDao.instance.setValue(SystemSettingsDao.DATABASE_BACKUP_ENABLED, "false");
// 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);
Providers.get(IMangoLifecycle.class).addStartupTask(new Runnable() {
@Override
public void run() {
// New database. Create a default user.
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);
DefaultDataPointPropertiesTemplateFactory factory = new DefaultDataPointPropertiesTemplateFactory();
factory.saveDefaultTemplates();
}
});
}
// Check if we are using NoSQL
if (NoSQLProxyFactory.instance.getProxy() != null) {
noSQLProxy = NoSQLProxyFactory.instance.getProxy();
noSQLProxy.initialize();
}
initialized = true;
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class CompoundEventDetectorDao method deleteCompoundEventDetector.
public void deleteCompoundEventDetector(final int compoundEventDetectorId) {
final ExtendedJdbcTemplate ejt2 = ejt;
CompoundEventDetectorVO ced = getCompoundEventDetector(compoundEventDetectorId);
if (ced != null) {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
ejt2.update("delete from eventHandlers where eventTypeId=" + EventType.EventTypeNames.COMPOUND + " and eventTypeRef1=?", new Object[] { compoundEventDetectorId });
ejt2.update("delete from compoundEventDetectors where id=?", new Object[] { compoundEventDetectorId });
}
});
AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_COMPOUND_EVENT_DETECTOR, ced);
}
}
Aggregations