use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class JdbcBaseDAO method doGetHistItemFilterQuery.
public List<HistoricItem> doGetHistItemFilterQuery(Item item, FilterCriteria filter, int numberDecimalcount, String table, String name) {
String sql = histItemFilterQueryProvider(filter, numberDecimalcount, table, name);
logger.debug("JDBC::doGetHistItemFilterQuery sql={}", sql);
List<Object[]> m = Yank.queryObjectArrays(sql, null);
List<HistoricItem> items = new ArrayList<HistoricItem>();
for (int i = 0; i < m.size(); i++) {
items.add(new JdbcItem(item.getName(), getState(item, m.get(i)[1]), objectAsDate(m.get(i)[0])));
}
return items;
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class DynamoDBPersistenceService method query.
/**
* {@inheritDoc}
*/
@Override
public Iterable<HistoricItem> query(FilterCriteria filter) {
logger.debug("got a query");
if (!isProperlyConfigured) {
logger.warn("Configuration for dynamodb not yet loaded or broken. Not storing item.");
return Collections.emptyList();
}
if (!maybeConnectAndCheckConnection()) {
logger.warn("DynamoDB not connected. Not storing item.");
return Collections.emptyList();
}
String itemName = filter.getItemName();
Item item = getItemFromRegistry(itemName);
if (item == null) {
logger.warn("Could not get item {} from registry!", itemName);
return Collections.emptyList();
}
Class<DynamoDBItem<?>> dtoClass = AbstractDynamoDBItem.getDynamoItemClass(item.getClass());
String tableName = tableNameResolver.fromClass(dtoClass);
DynamoDBMapper mapper = getDBMapper(tableName);
logger.debug("item {} (class {}) will be tried to query using dto class {} from table {}", itemName, item.getClass(), dtoClass, tableName);
List<HistoricItem> historicItems = new ArrayList<HistoricItem>();
DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = createQueryExpression(dtoClass, filter);
@SuppressWarnings("rawtypes") final PaginatedQueryList<? extends DynamoDBItem> paginatedList;
try {
paginatedList = mapper.query(dtoClass, queryExpression);
} catch (AmazonServiceException e) {
logger.error("DynamoDB query raised unexpected exception: {}. Returning empty collection. " + "Status code 400 (resource not found) might occur if table was just created.", e.getMessage());
return Collections.emptyList();
}
for (int itemIndexOnPage = 0; itemIndexOnPage < filter.getPageSize(); itemIndexOnPage++) {
int itemIndex = filter.getPageNumber() * filter.getPageSize() + itemIndexOnPage;
DynamoDBItem<?> dynamoItem;
try {
dynamoItem = paginatedList.get(itemIndex);
} catch (IndexOutOfBoundsException e) {
logger.debug("Index {} is out-of-bounds", itemIndex);
break;
}
if (dynamoItem != null) {
HistoricItem historicItem = dynamoItem.asHistoricItem(item);
logger.trace("Dynamo item {} converted to historic item: {}", item, historicItem);
historicItems.add(historicItem);
}
}
return historicItems;
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndStartAndEndWithGTOperator.
@Test
public void testQueryUsingNameAndStartAndEndWithGTOperator() {
// Skip for subclasses which have null "state between"
Assume.assumeTrue(getQueryItemStateBetween() != null);
FilterCriteria criteria = new FilterCriteria();
criteria.setOperator(Operator.GT);
criteria.setState(getQueryItemStateBetween());
criteria.setItemName(getItemName());
criteria.setBeginDate(beforeStore);
criteria.setEndDate(afterStore2);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
Iterator<HistoricItem> iterator = iterable.iterator();
HistoricItem actual1 = iterator.next();
assertFalse(iterator.hasNext());
assertStateEquals(getSecondItemState(), actual1.getState());
assertTrue(actual1.getTimestamp().before(afterStore2));
assertTrue(actual1.getTimestamp().after(afterStore1));
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingNameAndStartAndEnd.
@Test
public void testQueryUsingNameAndStartAndEnd() {
FilterCriteria criteria = new FilterCriteria();
criteria.setOrdering(Ordering.ASCENDING);
criteria.setItemName(getItemName());
criteria.setBeginDate(beforeStore);
criteria.setEndDate(afterStore2);
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
assertIterableContainsItems(iterable, true);
}
use of org.openhab.core.persistence.HistoricItem in project openhab1-addons by openhab.
the class AbstractTwoItemIntegrationTest method testQueryUsingName.
@Test
public void testQueryUsingName() {
FilterCriteria criteria = new FilterCriteria();
criteria.setOrdering(Ordering.ASCENDING);
criteria.setItemName(getItemName());
Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
assertIterableContainsItems(iterable, true);
}
Aggregations