Search in sources :

Example 6 with ExtendedJdbcTemplate

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();
        }
    });
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 7 with ExtendedJdbcTemplate

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);
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 8 with ExtendedJdbcTemplate

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);
        }
    }
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) IOException(java.io.IOException)

Example 9 with ExtendedJdbcTemplate

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;
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) DirectoryInfo(com.serotonin.util.DirectoryInfo) File(java.io.File)

Example 10 with ExtendedJdbcTemplate

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);
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) File(java.io.File)

Aggregations

ExtendedJdbcTemplate (com.serotonin.db.spring.ExtendedJdbcTemplate)22 TransactionStatus (org.springframework.transaction.TransactionStatus)12 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 DatabaseSchemaDefinition (com.serotonin.m2m2.module.DatabaseSchemaDefinition)3 User (com.serotonin.m2m2.vo.User)3 File (java.io.File)3 DefaultDataPointPropertiesTemplateFactory (com.serotonin.m2m2.vo.template.DefaultDataPointPropertiesTemplateFactory)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 DataSourceTransactionManager (org.springframework.jdbc.datasource.DataSourceTransactionManager)2 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)1 IMangoLifecycle (com.serotonin.m2m2.IMangoLifecycle)1 CompoundEventDetectorVO (com.serotonin.m2m2.vo.event.CompoundEventDetectorVO)1 PointFolder (com.serotonin.m2m2.vo.hierarchy.PointFolder)1 PointHierarchy (com.serotonin.m2m2.vo.hierarchy.PointHierarchy)1 DirectoryInfo (com.serotonin.util.DirectoryInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 MissingResourceException (java.util.MissingResourceException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1