當前位置: 首頁>>代碼示例>>Java>>正文


Java PersistenceService類代碼示例

本文整理匯總了Java中org.openhab.core.persistence.PersistenceService的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceService類的具體用法?Java PersistenceService怎麽用?Java PersistenceService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PersistenceService類屬於org.openhab.core.persistence包,在下文中一共展示了PersistenceService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: historicState

import org.openhab.core.persistence.PersistenceService; //導入依賴的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.PersistenceService; //導入依賴的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: deactivate

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void deactivate() {
	for(ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService> serviceReg : delegates.values()) {
		serviceReg.unregister();
	}
	delegates.clear();
	this.context = null;
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:8,代碼來源:PersistenceServiceFactory.java

示例4: addPersistenceService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void addPersistenceService(PersistenceService service) {
	if(context!=null) {
		registerDelegateService(service);			
	} else {
		persistenceServices.add(service);
	}
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:8,代碼來源:PersistenceServiceFactory.java

示例5: registerDelegateService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
private void registerDelegateService(PersistenceService persistenceService) {
	if(!delegates.containsKey(persistenceService.getName())) {
		org.eclipse.smarthome.core.persistence.PersistenceService service = 
				(persistenceService instanceof org.openhab.core.persistence.QueryablePersistenceService) ?
				new QueryablePersistenceServiceDelegate(persistenceService, itemRegistry) 
			:	new PersistenceServiceDelegate(persistenceService);
		Dictionary<String, Object> props = new Hashtable<String, Object>();
		ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService> serviceReg = 
				context.registerService(org.eclipse.smarthome.core.persistence.PersistenceService.class, service, props);
		delegates.put(persistenceService.getName(), serviceReg);
	}
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:13,代碼來源:PersistenceServiceFactory.java

示例6: unregisterDelegateService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
private void unregisterDelegateService(PersistenceService service) {
	if(delegates.containsKey(service.getName())) {
		ServiceRegistration<org.eclipse.smarthome.core.persistence.PersistenceService> serviceReg = 
				delegates.get(service.getName());
		delegates.remove(service.getName());
		serviceReg.unregister();
	}
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:9,代碼來源:PersistenceServiceFactory.java

示例7: persist

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
/**
 * Persists the state of a given <code>item</code> through a {@link PersistenceService} identified
 * by the <code>serviceName</code>. 
 * 
 * @param item the item to store
 * @param serviceName the name of the {@link PersistenceService} to use
 */
static public void persist(Item item, String serviceName) {
	PersistenceService service = services.get(serviceName);
	if (service != null) {
		service.store(item);
	} else {
		logger.warn("There is no persistence service registered with the name '{}'", serviceName);
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:16,代碼來源:PersistenceExtensions.java

示例8: previousState

import org.openhab.core.persistence.PersistenceService; //導入依賴的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

示例9: getAllStatesSince

import org.openhab.core.persistence.PersistenceService; //導入依賴的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

示例10: execute

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void execute(JobExecutionContext context) throws JobExecutionException {
	String modelName = (String) context.getJobDetail().getJobDataMap().get(JOB_DATA_PERSISTMODEL);				
	String strategyName = (String) context.getJobDetail().getJobDataMap().get(JOB_DATA_STRATEGYNAME);
	
	PersistenceManager persistenceManager = PersistenceManager.getInstance();
	if(persistenceManager!=null) {
		ModelRepository modelRepository = persistenceManager.modelRepository;
		PersistenceService persistenceService = persistenceManager.persistenceServices.get(modelName);
		
		if(modelRepository!=null && persistenceService!=null) {
			EObject model = modelRepository.getModel(modelName + ".persist");
			if (model instanceof PersistenceModel) {
				PersistenceModel persistModel = (PersistenceModel) model;
				for(PersistenceConfiguration config : persistModel.getConfigs()) {
					if(hasStrategy(persistModel, config, strategyName)) {
						for(Item item : persistenceManager.getAllItems(config)) {
							long startTime = System.currentTimeMillis();
							persistenceService.store(item, config.getAlias());
							logger.trace("Storing item '{}' with persistence service '{}' took {}ms",
									new Object[] { item.getName(), modelName, System.currentTimeMillis() - startTime});
						}
					}
				}
			} else {
				logger.debug("Persistence file '{}' does not exist", modelName);
			}
		}
	} else {
		logger.warn("Persistence manager is not available!");
	}
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:32,代碼來源:PersistItemsJob.java

示例11: initialize

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
/**
 * Handles the "restoreOnStartup" strategy for the item.
 * If the item state is still undefined when entering this method, all persistence configurations are checked,
 * if they have the "restoreOnStartup" strategy configured for the item. If so, the item state will be set
 * to its last persisted value.
 * 
 * @param item the item to restore the state for
 */
protected void initialize(Item item) {
	// get the last persisted state from the persistence service if no state is yet set
	if(item.getState().equals(UnDefType.NULL) && item instanceof GenericItem) {
		for(Entry<String, List<PersistenceConfiguration>> entry : persistenceConfigurations.entrySet()) {
			String serviceName = entry.getKey();
			for(PersistenceConfiguration config : entry.getValue()) {
				if(hasStrategy(serviceName, config, GlobalStrategies.RESTORE)) {
					if(appliesToItem(config, item)) {
						PersistenceService service = persistenceServices.get(serviceName);
						if(service instanceof QueryablePersistenceService) {
							QueryablePersistenceService queryService = (QueryablePersistenceService) service;
							FilterCriteria filter = new FilterCriteria().setItemName(item.getName()).setPageSize(1);
							Iterable<HistoricItem> result = queryService.query(filter);
							Iterator<HistoricItem> it = result.iterator();
							if(it.hasNext()) {
								HistoricItem historicItem = it.next();
								GenericItem genericItem = (GenericItem) item;
								genericItem.removeStateChangeListener(this);
								genericItem.setState(historicItem.getState());
								genericItem.addStateChangeListener(this);
								logger.debug("Restored item state from '{}' for item '{}' -> '{}'", 
										new Object[] { DateFormat.getDateTimeInstance().format(historicItem.getTimestamp()), 
										item.getName(), historicItem.getState().toString() } );
								return;
							}
						} else if(service!=null) {
							logger.warn("Failed to restore item states as persistence service '{}' can not be queried.", serviceName);
						}
					}
				}
			}
		}	
	}		
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:43,代碼來源:PersistenceManager.java

示例12: activate

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void activate(BundleContext context) {
	this.context = context;
	for(PersistenceService service : persistenceServices) {
		registerDelegateService(service);
	}
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:7,代碼來源:PersistenceServiceFactory.java

示例13: removePersistenceService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void removePersistenceService(PersistenceService service) {
	if(context!=null) {
		unregisterDelegateService(service);
	}
}
 
開發者ID:Neulinet,項目名稱:Zoo,代碼行數:6,代碼來源:PersistenceServiceFactory.java

示例14: addPersistenceService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void addPersistenceService(PersistenceService service) {
	if (service instanceof QueryablePersistenceService)
		persistenceServices.put(service.getName(), (QueryablePersistenceService) service);
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:5,代碼來源:DefaultChartProvider.java

示例15: removePersistenceService

import org.openhab.core.persistence.PersistenceService; //導入依賴的package包/類
public void removePersistenceService(PersistenceService service) {
	persistenceServices.remove(service.getName());
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:4,代碼來源:DefaultChartProvider.java


注:本文中的org.openhab.core.persistence.PersistenceService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。