Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Initial commit of persistence extensions #1872

Merged
merged 23 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
12c7c31
Initial commit of persistence extensions
cdjackson Jul 17, 2016
b532fa5
Updated API
cdjackson Jul 21, 2016
dfbbf7a
Updated following review and added REST resource updates
cdjackson Jul 22, 2016
bcaa729
Add H2SQL persistence bundle
cdjackson Jul 22, 2016
6779175
Update manifests to remove unused OH2 references
cdjackson Jul 24, 2016
81fe974
Add store(item, time, state) method and general tidy
cdjackson Jul 24, 2016
c192e76
Fixed handler of H2 page syntax
cdjackson Jul 24, 2016
5b1238c
Allow a PUT with the same time to UPDATE the existing record
cdjackson Jul 25, 2016
4632f69
Fix test. Add persistence service class to service bean
cdjackson Jul 25, 2016
406327b
Fix conversion of DateTimeType in H2SQL
cdjackson Jul 26, 2016
acdf26a
Update doc
cdjackson Jul 27, 2016
c11d8c1
Add 'boundary' option for GET interface
cdjackson Jul 27, 2016
ad90d05
Add H2SQL tests and optimise storage. Add readme.
cdjackson Jul 30, 2016
4a22703
Remove H2
cdjackson Jul 30, 2016
1d36e4b
Updates following review
cdjackson Aug 1, 2016
2bcb6af
Updates following testing with H2SQL
cdjackson Aug 1, 2016
04e65e9
Merge branch 'master' into persistence-extensions
cdjackson Aug 1, 2016
1c0c9fd
Update license headers
cdjackson Aug 1, 2016
1c3aa20
Updated to add PersistenceExtensions.getDefaultService()
cdjackson Aug 1, 2016
829fd5d
Update after testing with H2SQL
cdjackson Aug 1, 2016
d093a17
Modify REST endpoints
cdjackson Aug 1, 2016
6610b71
Updated following comments.
cdjackson Aug 2, 2016
cbcd900
Update tests
cdjackson Aug 2, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public interface HistoricItem {

/**
* returns the timestamp of the persisted item
*
*
* @return the timestamp of the item
*/
Date getTimestamp();

/**
* returns the current state of the item
*
*
* @return the current state
*/
public State getState();
State getState();

/**
* returns the name of the item
*
*
* @return the name of the item
*/
public String getName();
String getName();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you re-run "mvn license:format" to update the headers to the latest version?

* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.core.persistence;

import java.util.Date;

import org.eclipse.smarthome.core.items.Item;

/**
* This class provides an interface to the a {@link PersistenceService} to allow data to be stored
* at a specific time. This allows bindings that interface to devices that store data internally,
* and then periodically provide it to the server to be accommodated.
*
* @author Chris Jackson - Initial implementation and API
*
*/
public interface ModifiablePersistenceService extends QueryablePersistenceService {
/**
* <p>
* Stores the historic item value. This allows the item, time and value to be specified.
* </p>
* <p>
* Implementors should keep in mind that all registered {@link PersistenceService}s are called synchronously. Hence
* long running operations should be processed asynchronously. E.g. <code>store</code> adds things to a queue which
* is processed by some asynchronous workers (Quartz Job, Thread, etc.).
* </p>
*
* @param item the data to be stored
* @param date the date of the record
*/
void store(Item item, Date date);

/**
* Removes data associated with an item from a persistence service.
* If all data is removed for the specified item, the persistence service should free any resources associated with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the javadoc - the filtercriteria might not filter for a specific item at all, so this method is applicable for many items at the same time as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. I assumed that there must be an item name provided - it's not possible to add a filter with multiple item names, and I think it would be dangerous to add a filter with no item name. As discussed elsewhere, in the REST interface at least, it is required. Technically it would be possible to implement a filter that removed data from multiple items, but is it a good idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you look at FilterCriteria, it reads:
"...properties are constraints on the query result. These properties include the item name, begin and end date and the item state" and "filter result to only contain entries for the given item".

So in general, it allows that the itemName is null and hence the filter is applicable for ANY item. As your method accepts a filter criteria as a parameter, you have to deal with that fact. If you do not want to allow itemName to be null, you should document this in the JavaDoc and declare an exception that you will throw in that case.

* the item (eg. remove any tables or delete files from the storage).
*
* @param filter the filter to apply to the data removal
* @return true if the query executed successfully
*/
boolean remove(FilterCriteria filter);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.core.persistence;

/**
* This class provides information about an item that is stored in a persistence service.
* It is used to return information about the item to the system
*
* @author Chris Jackson - Initial contribution
*
*/
public interface PersistenceItemInfo {
/**
* Returns the item name.
* It should be noted that the item name is as stored in the persistence service and as such may not be linked to an
* item. This may be the case if the item was removed from the system, but data still exists in the persistence
* service.
*
* @return Item name
*/
String getName();

/**
* Returns the number of rows of data associated with the item
* Note that this should be used as a guide to the amount of data and may note be 100% accurate. If accurate
* information is required, the {@link QueryablePersistenceService#query} method should be used.
*
* @return count of the number of rows of data.
*/
Integer getRows();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@
*/
package org.eclipse.smarthome.core.persistence;

import java.util.Set;

import org.eclipse.smarthome.core.items.Item;

/**
* A queryable persistence service which can be used to store and retrieve
* data from openHAB. This is most likely some kind of database system.
*
* @author Kai Kreuzer - Initial contribution and API
* @author Chris Jackson - Added getItems method
*/
public interface QueryablePersistenceService extends PersistenceService {

/**
* Queries the {@link PersistenceService} for data with a given filter criteria
*
*
* @param filter the filter to apply to the query
* @return a time series of items
*/
Iterable<HistoricItem> query(FilterCriteria filter);

/**
* Returns a list of items that are stored in the persistence service
*
* This is returned as a string to allow the persistence service to return items that are no long available as an
* ESH {@link Item}.
*
* @return list of strings of item names contained in the store
*/
Set<PersistenceItemInfo> getItems();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better rename the method to getItemInfos().

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Import-Package: com.google.common.base,
org.eclipse.smarthome.io.rest,
org.eclipse.smarthome.io.rest.core.item,
org.eclipse.smarthome.io.rest.core.thing,
org.openhab.core.items,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESH should not rely on an OH package

org.osgi.framework,
org.osgi.service.cm,
org.osgi.service.component,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.io.rest.core.persistence;

/**
* This is a java bean that is used to serialize information about items in a persistence service to JSON.
*
* @author Chris Jackson - Initial Contribution
*
*/
public class PersistenceItemInfoBean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we by now always call such beans DTOs and where ever they might be relevant for serialization anywhere else than the REST API as well (e.g. for the payload of events), we put those DTOs in the core bundle in a sub-package "dto" (here it would be org.eclipse.smarthome.core.persistence.dto).

Could you possibly refactor the existing "Beans" in this package to follow this convention?
Regarding the PersistenceItemInfoBean: Do we need this at all? It is very similar to the PersistenceItemInfo class - maybe you could add a simply GSON annotation to the Date fields to specify the string format in which they should be serialized?

PersistenceItemInfoBean() {
}

/**
* The name of the item in the persistence service
*/
public String name;

/**
* The number of rows of data in the persistence store for the item
*/
public Integer rows;
}
Loading