Search in sources :

Example 11 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class EventDao method returnEventsToNormal.

public void returnEventsToNormal(List<Integer> eventIds, long timestamp, long cause) {
    if (eventIds.size() == 0)
        throw new ShouldNeverHappenException("Not enough Ids!");
    StringBuilder inClause = new StringBuilder();
    inClause.append("(");
    final String comma = ",";
    Iterator<Integer> it = eventIds.iterator();
    while (it.hasNext()) {
        inClause.append(it.next());
        if (it.hasNext())
            inClause.append(comma);
    }
    inClause.append(")");
    ejt.update(EVENT_BULK_RTN + inClause.toString(), new Object[] { timestamp, cause });
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 12 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class AbstractBasicDao method getQueryColumn.

/**
 * @param argument
 * @return
 */
public SQLQueryColumn getQueryColumn(String prop) {
    boolean mapped = false;
    Set<String> properties = this.propertyTypeMap.keySet();
    String dbCol = prop;
    Integer sqlType;
    if (propertiesMap.containsKey(prop)) {
        IntStringPair pair = propertiesMap.get(prop);
        dbCol = pair.getValue();
        sqlType = pair.getKey();
        mapped = true;
    } else {
        sqlType = this.propertyTypeMap.get(dbCol);
    }
    if (mapped || properties.contains(dbCol)) {
        if (mapped)
            return new SQLQueryColumn(dbCol, sqlType);
        else
            return new SQLQueryColumn(this.tablePrefix + dbCol, sqlType);
    }
    // No Column matches...
    throw new ShouldNeverHappenException("No column found for: " + prop);
}
Also used : SQLQueryColumn(com.infiniteautomation.mango.db.query.SQLQueryColumn) IntStringPair(com.serotonin.db.pair.IntStringPair) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 13 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class AbstractDatabaseProxy method doInConnection.

/* (non-Javadoc)
     * @see com.serotonin.m2m2.db.DatabaseProxy#doInConnection(com.serotonin.db.spring.ConnectionCallbackVoid)
     */
@Override
public void doInConnection(ConnectionCallbackVoid callback) {
    DataSource dataSource = getDataSource();
    Connection conn = null;
    try {
        conn = DataSourceUtils.getConnection(dataSource);
        conn.setAutoCommit(false);
        callback.doInConnection(conn);
        conn.commit();
    } catch (Exception e) {
        try {
            if (conn != null)
                conn.rollback();
        } catch (SQLException e1) {
            log.warn("Exception during rollback", e1);
        }
        // Wrap and rethrow
        throw new ShouldNeverHappenException(e);
    } finally {
        if (conn != null)
            DataSourceUtils.releaseConnection(conn, dataSource);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) SQLException(java.sql.SQLException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) MissingResourceException(java.util.MissingResourceException) FileNotFoundException(java.io.FileNotFoundException) DataSource(javax.sql.DataSource)

Example 14 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class H2Proxy method runScript.

@Override
public void runScript(InputStream input, final OutputStream out) {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(input));
        List<String> lines = new ArrayList<>();
        String line;
        while ((line = in.readLine()) != null) lines.add(line);
        String[] script = new String[lines.size()];
        lines.toArray(script);
        runScript(script, out);
    } catch (IOException ioe) {
        throw new ShouldNeverHappenException(ioe);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException ioe) {
            LOG.warn("", ioe);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException)

Example 15 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.

the class EventInstanceDao method createEventType.

static EventType createEventType(ResultSet rs, int offset) throws SQLException {
    String typeName = rs.getString(offset);
    String subtypeName = rs.getString(offset + 1);
    EventType type;
    if (typeName.equals(EventType.EventTypeNames.DATA_POINT))
        type = new DataPointEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.DATA_SOURCE))
        type = new DataSourceEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.SYSTEM))
        type = new SystemEventType(subtypeName, rs.getInt(offset + 2));
    else if (typeName.equals(EventType.EventTypeNames.PUBLISHER))
        type = new PublisherEventType(rs.getInt(offset + 2), rs.getInt(offset + 3));
    else if (typeName.equals(EventType.EventTypeNames.AUDIT))
        throw new ShouldNeverHappenException("AUDIT events should not exist here. Consider running the SQL: DELETE FROM events WHERE typeName='AUDIT';");
    else {
        EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(typeName);
        if (def == null) {
            // Create Missing Event Type
            type = new MissingEventType(typeName, null, rs.getInt(offset + 2), rs.getInt(offset + 3));
        } else {
            type = def.createEventType(subtypeName, rs.getInt(offset + 2), rs.getInt(offset + 3));
            if (type == null) {
                // Create Missing Event type
                type = new MissingEventType(typeName, subtypeName, rs.getInt(offset + 2), rs.getInt(offset + 3));
            }
        }
    }
    return type;
}
Also used : DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) MissingEventType(com.serotonin.m2m2.rt.event.type.MissingEventType) DataSourceEventType(com.serotonin.m2m2.rt.event.type.DataSourceEventType) EventType(com.serotonin.m2m2.rt.event.type.EventType) SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) MissingEventType(com.serotonin.m2m2.rt.event.type.MissingEventType) PublisherEventType(com.serotonin.m2m2.rt.event.type.PublisherEventType) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) DataPointEventType(com.serotonin.m2m2.rt.event.type.DataPointEventType) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4