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 2 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
@@ -0,0 +1,52 @@
/**
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 date the date of the record
* @param item the data to be stored
*/
public void store(Date date, Item item);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't care, I would prefer to use Item as first argument and Date as second one.
Why? Because there is already the method void store(Item item);.
https://github.com/eclipse/smarthome/blob/e0985e9/bundles/core/org.eclipse.smarthome.core.persistence/src/main/java/org/eclipse/smarthome/core/persistence/PersistenceService.java#L40
And if this one has an additional argument I prefer to add it at the endt.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove "public" modifiers on interface functions (its default).

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 know - the reason I added them was to maintain the same style as other interfaces in this package. I’m happy to remove it though.


/**
* Removes a data from a persistence store.
*
* @param filter the filter to apply to the data removal
* @return true if the query executed successfully
*/
public boolean remove(FilterCriteria filter);

/**
* Removes an item and all data associated with the item
*
* @return true if the item was deleted
*/
public boolean removeItemData(String itemName);
Copy link
Contributor

Choose a reason for hiding this comment

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

to make it very clear, I would call it removeAllItemData.

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 am considering to remove this method and instead just have the remove method. If all data is removed using the remove method, then the item should also be deleted from the database. I think this is a more fail safe method - it means you need to actively configure a filter with a start/stop time that includes all data.

What do you think?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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;

public interface PersistenceItem {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer some other name to better express the purpose/content.
How about something like PersistedItemInfo or so?

String getName();

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.

Why "rows"? Shouldn't we use "count" or "size"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could - I don’t mind. rows is common database terminology which is why I used it.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, that rows is used by SQL databases. IIRC it differs using NOSQL databases.
The interface is about persistence, not about SQL databases.
If rows or files or map entries are used is implementation dependent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So? It needs to be called something - it wasn't planned to be SQL dependant - other databases use this term as well.
As I said - I don't care, but I don't see anything wrong with rows...

}
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
*/
public Set<PersistenceItem> getItems();
}