use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class H2InMemoryDatabaseProxy 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) {
throw new RuntimeException(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 FileUploadController method parseFile.
/**
* Parse the Import Files
* @param input
* @param model
* @param translations
*/
protected void parseFile(InputStream input, Map<String, Object> model, Translations translations, HttpServletRequest request) {
// Get the filename
String filename = (String) model.get("filename");
SpreadsheetEmporter emporter;
if (filename == null)
return;
else {
if (filename.toLowerCase().endsWith(".xls"))
emporter = new SpreadsheetEmporter(FileType.XLS);
else if (filename.toLowerCase().endsWith(".xlsx"))
emporter = new SpreadsheetEmporter(FileType.XLSX);
else
return;
}
// Switch on the type
String dataType = (String) model.get("dataType");
if (dataType != null) {
if (dataType.equals("pointValue")) {
// List the sheets and create sheet emporters for each
for (Sheet sheet : emporter.listSheets(input)) emporter.doImport(input, new PointValueEmporter(sheet.getSheetName()));
} else
throw new ShouldNeverHappenException("Unsupported data.");
}
model.put("hasImportErrors", emporter.hasErrors());
// Get the messages
if (emporter.hasErrors()) {
List<String> errorMessages = new ArrayList<String>();
for (TranslatableMessage msg : emporter.getErrorMessages()) {
errorMessages.add(msg.translate(translations));
}
model.put("errorMessages", errorMessages);
}
model.put("rowsImported", emporter.getRowsAdded());
model.put("rowsDeleted", emporter.getRowsDeleted());
model.put("rowsWithErrors", emporter.getRowErrors());
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class AbstractPointWrapper method getCalendar.
private GregorianCalendar getCalendar() {
long time = getTime();
if (time == -1)
throw new ShouldNeverHappenException("No timestamp for point value.");
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(time);
return gc;
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class BigIntegerColumnQueryAppender method appendSQL.
/* (non-Javadoc)
* @see com.infiniteautomation.mango.db.query.SQLColumnQueryAppender#appendSQL(com.infiniteautomation.mango.db.query.SQLQueryColumn, java.lang.StringBuilder, java.lang.StringBuilder, java.util.List, java.util.List)
*/
@Override
public void appendSQL(SQLQueryColumn column, StringBuilder selectSql, StringBuilder countSql, List<Object> selectArgs, List<Object> columnArgs, ComparisonEnum comparison) {
// Catchall for null comparisons
if ((columnArgs.size() == 1) && (columnArgs.get(0) == null)) {
if (comparison == ComparisonEnum.IS)
super.appendSQL(column.getName(), IS_SQL, selectSql, countSql);
else if (comparison == ComparisonEnum.IS_NOT)
super.appendSQL(column.getName(), IS_NOT_SQL, selectSql, countSql);
else
super.appendSQL(column.getName(), IS_SQL, selectSql, countSql);
selectArgs.add(null);
return;
}
if (columnArgs.size() == 1) {
// Are we a Date String?
if (columnArgs.get(0) instanceof String) {
SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT);
try {
Date d = sdf.parse((String) columnArgs.get(0));
columnArgs.set(0, Long.toString(d.getTime()));
} catch (ParseException e) {
throw new ShouldNeverHappenException(e);
}
}
}
super.appendSQL(column, selectSql, countSql, selectArgs, columnArgs, comparison);
}
use of com.serotonin.ShouldNeverHappenException in project ma-core-public by infiniteautomation.
the class ExpandTimePeriodAdjuster method adjustInto.
/* (non-Javadoc)
* @see java.time.temporal.TemporalAdjuster#adjustInto(java.time.temporal.Temporal)
*/
@Override
public Temporal adjustInto(Temporal temporal) {
ZonedDateTime zdt = startTime;
ZonedDateTime adjustTime = (ZonedDateTime) temporal;
while (zdt.isBefore(adjustTime)) {
// adjusted in that manner if appropriate, and none of the time advances should alter a lesser field harmfully.
switch(periodType) {
case TimePeriods.MILLISECONDS:
zdt = zdt.plus(periods, ChronoUnit.MILLIS);
break;
case TimePeriods.SECONDS:
zdt = zdt.plus(periods, ChronoUnit.SECONDS);
break;
case TimePeriods.MINUTES:
zdt = zdt.plus(periods, ChronoUnit.MINUTES);
break;
case TimePeriods.HOURS:
zdt = zdt.plus(periods, ChronoUnit.HOURS);
break;
case TimePeriods.DAYS:
zdt = zdt.plus(periods, ChronoUnit.DAYS);
break;
case TimePeriods.WEEKS:
// Don't set the DoW since this may be governed by last year, and shouldn't change by adding weeks
zdt = zdt.plus(periods, ChronoUnit.WEEKS);
break;
case TimePeriods.MONTHS:
zdt = zdt.plus(periods, ChronoUnit.MONTHS);
break;
case TimePeriods.YEARS:
zdt = zdt.plus(periods, ChronoUnit.YEARS);
break;
default:
throw new ShouldNeverHappenException("Unsupported time period: " + periodType);
}
}
return zdt;
}
Aggregations