当前位置: 首页>>代码示例>>Java>>正文


Java Ordering类代码示例

本文整理汇总了Java中org.openhab.core.persistence.FilterCriteria.Ordering的典型用法代码示例。如果您正苦于以下问题:Java Ordering类的具体用法?Java Ordering怎么用?Java Ordering使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Ordering类属于org.openhab.core.persistence.FilterCriteria包,在下文中一共展示了Ordering类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: historicState

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
/**
 * Retrieves the state of a given <code>item</code> to a certain point in time through  a {@link PersistenceService} identified
 * by the <code>serviceName</code>. 
 * 
 * @param item the item to retrieve the state for
 * @param the point in time for which the state should be retrieved 
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return the item state at the given point in time
 */
static public HistoricItem historicState(Item item, AbstractInstant timestamp, String serviceName) {
	PersistenceService service = services.get(serviceName);
	if (service instanceof QueryablePersistenceService) {
		QueryablePersistenceService qService = (QueryablePersistenceService) service;
		FilterCriteria filter = new FilterCriteria();
		filter.setEndDate(timestamp.toDate());
		filter.setItemName(item.getName());
		filter.setPageSize(1);
		filter.setOrdering(Ordering.DESCENDING);
		Iterable<HistoricItem> result = qService.query(filter);
		if(result.iterator().hasNext()) {
			return result.iterator().next();
		} else {
			return null;
		}
	} else {
		logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
		return null;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:30,代码来源:PersistenceExtensions.java

示例2: lastUpdate

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
/**
 * Query for the last update timestamp of a given <code>item</code>.
 *
 * @param item the item to check for state updates
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return point in time of the last update or null if none available
 */
static public Date lastUpdate(Item item, String serviceName) {
	PersistenceService service = services.get(serviceName);
	if (service instanceof QueryablePersistenceService) {
		QueryablePersistenceService qService = (QueryablePersistenceService) service;
		FilterCriteria filter = new FilterCriteria();
		filter.setItemName(item.getName());
		filter.setOrdering(Ordering.DESCENDING);
		filter.setPageSize(1);
		Iterable<HistoricItem> result = qService.query(filter);
		if (result.iterator().hasNext()) {
			return result.iterator().next().getTimestamp();
		} else {
			return null;
		}
	} else {
		logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
		return null;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:27,代码来源:PersistenceExtensions.java

示例3: testQueryUsingNameAndStartAndEndFirst

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@Test
public void testQueryUsingNameAndStartAndEndFirst() {
    FilterCriteria criteria = new FilterCriteria();
    criteria.setOrdering(Ordering.ASCENDING);
    criteria.setItemName(getItemName());
    criteria.setBeginDate(beforeStore);
    criteria.setEndDate(afterStore1);
    Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);

    Iterator<HistoricItem> iterator = iterable.iterator();
    HistoricItem actual1 = iterator.next();
    assertFalse(iterator.hasNext());
    assertStateEquals(getFirstItemState(), actual1.getState());
    assertTrue(actual1.getTimestamp().before(afterStore1));
    assertTrue(actual1.getTimestamp().after(beforeStore));
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:17,代码来源:AbstractTwoItemIntegrationTest.java

示例4: previousState

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
/**
 * Returns the previous state of a given <code>item</code>. 
 * The {@link PersistenceService} identified by the <code>serviceName</code> is used. 
 * 
 * @param item the item to get the previous state value for
 * @param skipEqual if true, skips equal state values and searches the first state not equal the current state
 * @param serviceName the name of the {@link PersistenceService} to use
 * @return the previous state
 */
static public HistoricItem previousState(Item item, boolean skipEqual, String serviceName) {
	PersistenceService service = services.get(serviceName);
	if (service instanceof QueryablePersistenceService) {
		QueryablePersistenceService qService = (QueryablePersistenceService) service;
		FilterCriteria filter = new FilterCriteria();
		filter.setItemName(item.getName());
		filter.setOrdering(Ordering.DESCENDING);

		filter.setPageSize(skipEqual ? 1000 : 1);
		int startPage = 0;
		filter.setPageNumber(startPage);

		Iterable<HistoricItem> items = qService.query(filter);
		while (items != null) {
			Iterator<HistoricItem> itemIterator = items.iterator();
			int itemCount = 0;
			while (itemIterator.hasNext()) {
				HistoricItem historicItem = itemIterator.next(); 
				itemCount++;
				if (!skipEqual || (skipEqual && !historicItem.getState().equals(item.getState()))) {
					return historicItem;
				}
			}
			if (itemCount == filter.getPageSize()) {
				filter.setPageNumber(++startPage);
				items = qService.query(filter);
			}
			else {
				items = null;
			}
		}
		return null;

	} else {
		logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
		return null;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:48,代码来源:PersistenceExtensions.java

示例5: getAllStatesSince

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
static private Iterable<HistoricItem> getAllStatesSince(Item item, AbstractInstant timestamp, String serviceName) {
	PersistenceService service = services.get(serviceName);
	if (service instanceof QueryablePersistenceService) {
		QueryablePersistenceService qService = (QueryablePersistenceService) service;
		FilterCriteria filter = new FilterCriteria();
		filter.setBeginDate(timestamp.toDate());
		filter.setItemName(item.getName());
		filter.setOrdering(Ordering.ASCENDING);
		return qService.query(filter);
	} else {
		logger.warn("There is no queryable persistence service registered with the name '{}'", serviceName);
		return Collections.emptySet();
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:15,代码来源:PersistenceExtensions.java

示例6: query

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public Iterable<HistoricItem> query(FilterCriteria filter) {		
	int startValue = 1950;
	int endValue = 2012;
	
	if(filter.getBeginDate()!=null) startValue = filter.getBeginDate().getYear() + 1900;
	if(filter.getEndDate()!=null) endValue = filter.getEndDate().getYear() + 1900;
	
	if(endValue<=startValue || startValue<1950) return Collections.emptyList();
	
	ArrayList<HistoricItem> results = new ArrayList<HistoricItem>(endValue - startValue);
	for(int i = startValue; i <= endValue; i++) {
		final int year = i;
		results.add(new HistoricItem() {
			public Date getTimestamp() {
				return new Date(year-1900, 0, 1);
			}
			
			@Override
			public State getState() {
				return new DecimalType(year);
			}
			
			@Override
			public String getName() {
				return "Test";
			}
		});
	}
	if(filter.getOrdering()==Ordering.DESCENDING) {
		Collections.reverse(results);
	}
	return results;
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:36,代码来源:TestPersistenceService.java

示例7: getPersistenceSeries

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
public Object getPersistenceSeries(
		QueryablePersistenceService persistenceService, Item item,
		Date timeBegin, Date timeEnd, long resolution) {
	Map<Long, ArrayList<String>> data = new TreeMap<Long, ArrayList<String>>();

	// Define the data filter
	FilterCriteria filter = new FilterCriteria();
	filter.setBeginDate(timeBegin);
	filter.setEndDate(timeEnd);
	filter.setItemName(item.getName());
	filter.setOrdering(Ordering.ASCENDING);

	// Get the data from the persistence store
	Iterable<HistoricItem> result = persistenceService.query(filter);
	Iterator<HistoricItem> it = result.iterator();

	// Iterate through the data
	int dataCounter = 0;
	while (it.hasNext()) {
		dataCounter++;
		HistoricItem historicItem = it.next();
		State state = historicItem.getState();
		if (state instanceof DecimalType) {
			ArrayList<String> vals = new ArrayList<String>();
			vals.add(formatDouble(((DecimalType) state).doubleValue(),
					"null", true));
			data.put(historicItem.getTimestamp().getTime(), vals);
		}
	}
	logger.debug(
			"'{}' querying item '{}' from '{}' to '{}' => '{}' results",
			persistenceService.getName(), filter.getItemName(),
			filter.getBeginDate(), filter.getEndDate(), dataCounter);
	return convertToRrd(data);
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:36,代码来源:RrdResource.java

示例8: createQueryExpression

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
/**
 * Construct dynamodb query from filter
 *
 * @param filter
 * @return DynamoDBQueryExpression corresponding to the given FilterCriteria
 */
private DynamoDBQueryExpression<DynamoDBItem<?>> createQueryExpression(Class<? extends DynamoDBItem<?>> dtoClass,
        FilterCriteria filter) {
    DynamoDBItem<?> item = getDynamoDBHashKey(dtoClass, filter.getItemName());
    final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression = new DynamoDBQueryExpression<DynamoDBItem<?>>()
            .withHashKeyValues(item).withScanIndexForward(filter.getOrdering() == Ordering.ASCENDING)
            .withLimit(filter.getPageSize());
    Condition timeFilter = maybeAddTimeFilter(queryExpression, filter);
    maybeAddStateFilter(filter, queryExpression);
    logger.debug("Querying: {} with {}", filter.getItemName(), timeFilter);
    return queryExpression;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:DynamoDBPersistenceService.java

示例9: histItemFilterQueryProvider

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
private String histItemFilterQueryProvider(FilterCriteria filter, int numberDecimalcount, String table,
        String simpleName) {
    logger.debug(
            "JDBC::getHistItemFilterQueryProvider filter = {}, numberDecimalcount = {}, table = {}, simpleName = {}",
            filter.toString(), numberDecimalcount, table, simpleName);

    String filterString = "";
    if (filter.getBeginDate() != null) {
        filterString += filterString.isEmpty() ? " WHERE" : " AND";
        filterString += " TIME>'" + jdbcDateFormat.print(new DateTime(filter.getBeginDate().getTime())) + "'";
    }
    if (filter.getEndDate() != null) {
        filterString += filterString.isEmpty() ? " WHERE" : " AND";
        filterString += " TIME<'" + jdbcDateFormat.print(new DateTime(filter.getEndDate().getTime())) + "'";
    }
    filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC ";
    if (filter.getPageSize() != 0x7fffffff) {
        filterString += " LIMIT " + filter.getPageNumber() * filter.getPageSize() + "," + filter.getPageSize();
    }
    // SELECT time, ROUND(value,3) FROM number_item_0114 ORDER BY time DESC LIMIT 0,1
    // rounding HALF UP
    String queryString = "NUMBERITEM".equalsIgnoreCase(simpleName) && numberDecimalcount > -1
            ? "SELECT time, ROUND(value," + numberDecimalcount + ") FROM " + table
            : "SELECT time, value FROM " + table;
    if (!filterString.isEmpty()) {
        queryString += filterString;
    }
    logger.debug("JDBC::query queryString = {}", queryString);
    return queryString;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:31,代码来源:JdbcBaseDAO.java

示例10: histItemFilterQueryProvider

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
/**
 * @param filter
 * @param numberDecimalcount
 * @param table
 * @return
 */
private String histItemFilterQueryProvider(FilterCriteria filter, int numberDecimalcount, String table,
        String simpleName) {
    logger.debug(
            "JDBC::getHistItemFilterQueryProvider filter = {}, numberDecimalcount = {}, table = {}, simpleName = {}",
            filter.toString(), numberDecimalcount, table, simpleName);

    String filterString = "";
    if (filter.getBeginDate() != null) {
        filterString += filterString.isEmpty() ? " WHERE" : " AND";
        filterString += " TIME>'" + jdbcDateFormat.print(new DateTime(filter.getBeginDate().getTime())) + "'";
    }
    if (filter.getEndDate() != null) {
        filterString += filterString.isEmpty() ? " WHERE" : " AND";
        filterString += " TIME<'" + jdbcDateFormat.print(new DateTime(filter.getEndDate().getTime())) + "'";
    }
    filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC";
    if (filter.getPageSize() != 0x7fffffff) {
        // see:
        // http://www.jooq.org/doc/3.5/manual/sql-building/sql-statements/select-statement/limit-clause/
        filterString += " OFFSET " + filter.getPageNumber() * filter.getPageSize() + " LIMIT "
                + filter.getPageSize();
    }
    String queryString = "NUMBERITEM".equalsIgnoreCase(simpleName) && numberDecimalcount > -1
            ? "SELECT time, ROUND(CAST (value AS numeric)," + numberDecimalcount + ") FROM " + table
            : "SELECT time, value FROM " + table;
    if (!filterString.isEmpty()) {
        queryString += filterString;
    }
    logger.debug("JDBC::query queryString = {}", queryString);
    return queryString;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:38,代码来源:JdbcPostgresqlDAO.java

示例11: testQueryUsingName

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@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);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:9,代码来源:AbstractTwoItemIntegrationTest.java

示例12: testQueryUsingNameAndStart

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@Test
public void testQueryUsingNameAndStart() {
    FilterCriteria criteria = new FilterCriteria();
    criteria.setOrdering(Ordering.ASCENDING);
    criteria.setItemName(getItemName());
    criteria.setBeginDate(beforeStore);
    Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
    assertIterableContainsItems(iterable, true);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:10,代码来源:AbstractTwoItemIntegrationTest.java

示例13: testQueryUsingNameAndEnd

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@Test
public void testQueryUsingNameAndEnd() {
    FilterCriteria criteria = new FilterCriteria();
    criteria.setOrdering(Ordering.ASCENDING);
    criteria.setItemName(getItemName());
    criteria.setEndDate(afterStore2);
    Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
    assertIterableContainsItems(iterable, true);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:10,代码来源:AbstractTwoItemIntegrationTest.java

示例14: testQueryUsingNameAndStartAndEnd

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@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);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:11,代码来源:AbstractTwoItemIntegrationTest.java

示例15: testQueryUsingNameAndStartAndEndDesc

import org.openhab.core.persistence.FilterCriteria.Ordering; //导入依赖的package包/类
@Test
public void testQueryUsingNameAndStartAndEndDesc() {
    FilterCriteria criteria = new FilterCriteria();
    criteria.setOrdering(Ordering.DESCENDING);
    criteria.setItemName(getItemName());
    criteria.setBeginDate(beforeStore);
    criteria.setEndDate(afterStore2);
    Iterable<HistoricItem> iterable = BaseIntegrationTest.service.query(criteria);
    assertIterableContainsItems(iterable, false);
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:11,代码来源:AbstractTwoItemIntegrationTest.java


注:本文中的org.openhab.core.persistence.FilterCriteria.Ordering类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。