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 });
}
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);
}
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);
}
}
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);
}
}
}
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;
}
Aggregations