use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class PublisherDao method deletePublisher.
public void deletePublisher(final int publisherId) {
PublisherVO<?> vo = getPublisher(publisherId);
final ExtendedJdbcTemplate ejt2 = ejt;
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
ejt2.update("delete from eventHandlersMapping where eventTypeName=? and eventTypeRef1=?", new Object[] { EventType.EventTypeNames.PUBLISHER, publisherId });
ejt2.update("delete from publishers where id=?", new Object[] { publisherId });
AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_PUBLISHER, vo);
countMonitor.decrement();
}
});
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class SystemSettingsDao method setValue.
public void setValue(final String key, final String value) {
// Update the cache
String oldValue;
if (value == null) {
oldValue = cache.remove(key);
} else {
oldValue = cache.put(key, value);
}
// Update the database
final ExtendedJdbcTemplate ejt2 = ejt;
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// Delete any existing value.
removeValue(key);
// Insert the new value if it's not null.
if (value != null)
ejt2.update("insert into systemSettings values (?,?)", new Object[] { key, value });
}
});
// Fire an event for this here as if the pools are full we may not be able to spawn a thread for the change
if (this.threadPoolListener.getKeys().contains(key))
this.threadPoolListener.SystemSettingsSaved(key, oldValue, value);
SystemSettingsEventDispatcher.fireSystemSettingSaved(key, oldValue, value);
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class BasePooledProxy method runScript.
@Override
public void runScript(String[] script, OutputStream out) {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(dataSource);
StringBuilder statement = new StringBuilder();
for (String line : script) {
// Trim whitespace
line = line.trim();
// Skip comments
if (line.startsWith("--"))
continue;
statement.append(line);
statement.append(" ");
if (line.endsWith(";")) {
// Execute the statement
ejt.execute(statement.toString());
if (out != null) {
try {
out.write((statement.toString() + "\n").getBytes(Common.UTF8_CS));
} catch (IOException e) {
// Don't really care
}
}
statement.delete(0, statement.length() - 1);
}
}
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class H2Proxy method getDatabaseSizeInBytes.
@Override
public Long getDatabaseSizeInBytes() {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(this.getDataSource());
String dataDir = ejt.queryForObject("call DATABASE_PATH()", new Object[] {}, String.class, null);
if (dataDir == null) {
return null;
}
// Good until we change to MVStore
File dbData = new File(dataDir + ".h2.db");
if (dbData.exists()) {
DirectoryInfo dbInfo = DirectoryUtils.getSize(dbData);
return dbInfo.getSize();
} else
return null;
}
use of com.serotonin.db.spring.ExtendedJdbcTemplate in project ma-core-public by infiniteautomation.
the class H2Proxy method getDataDirectory.
@Override
public File getDataDirectory() {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(this.getDataSource());
String dataDir = ejt.queryForObject("call DATABASE_PATH()", new Object[] {}, String.class, null);
if (dataDir == null)
return null;
return new File(dataDir);
}
Aggregations