Skip to content
This repository has been archived by the owner on Jan 9, 2018. It is now read-only.

Commit

Permalink
allow non-model based persistence configuration (eclipse-archived#2094)
Browse files Browse the repository at this point in the history
* allow non-model based persistence configuration

Signed-off-by: Markus Rathgeb <maggu2810@gmail.com>
  • Loading branch information
maggu2810 authored and chaton78 committed May 7, 2017
1 parent 9138428 commit adff1ba
Show file tree
Hide file tree
Showing 19 changed files with 1,074 additions and 580 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ Bundle-ManifestVersion: 2
Bundle-License: http://www.eclipse.org/legal/epl-v10.html
Bundle-SymbolicName: org.eclipse.smarthome.core.persistence
Import-Package: org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.items,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.persistence,
org.eclipse.smarthome.core.scheduler,
org.eclipse.smarthome.core.types,
org.slf4j
Export-Package: org.eclipse.smarthome.core.persistence,
org.eclipse.smarthome.core.persistence.dto
org.eclipse.smarthome.core.persistence.config,
org.eclipse.smarthome.core.persistence.dto,
org.eclipse.smarthome.core.persistence.strategy
Bundle-ClassPath: .
Service-Component: OSGI-INF/*.xml
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014-2016 by the respective copyright holders.
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
-->
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.smarthome.core.persistence.persistencemanager">
<implementation class="org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl"/>
<service>
<provide interface="org.eclipse.smarthome.core.persistence.PersistenceManager"/>
</service>
<reference bind="addPersistenceService" cardinality="0..n" interface="org.eclipse.smarthome.core.persistence.PersistenceService" name="PersistenceService" policy="dynamic" unbind="removePersistenceService"/>
<reference bind="setItemRegistry" cardinality="0..1" interface="org.eclipse.smarthome.core.items.ItemRegistry" name="ItemRegistry" policy="dynamic" unbind="unsetItemRegistry"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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;

/**
* A persistence manager service which could be used to start event handling or supply configuration for persistence
* services.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public interface PersistenceManager {
/**
* Add a configuration for a persistence service.
*
* @param dbId the database id used by the persistence service
* @param config the configuration of the persistence service
*/
void addConfig(String dbId, PersistenceServiceConfiguration config);

/**
* Remove a configuration for a persistence service.
*
* @param dbId the database id used by the persistence service
*/
void removeConfig(String dbId);

/**
* Start the event handling for a persistence service.
*
* @param dbId the database id used by the persistence service
*/
void startEventHandling(String dbId);

/**
* Stop the event handling for a persistence service.
*
* @param dbId the database id used by the persistence service
*/
void stopEventHandling(String dbId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.Collections;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.smarthome.core.persistence.strategy.SimpleStrategy;

/**
* This class represents the configuration for a persistence service.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class PersistenceServiceConfiguration {
private final List<SimpleItemConfiguration> configs;
private final List<SimpleStrategy> defaults;
private final List<SimpleStrategy> strategies;

public PersistenceServiceConfiguration(final List<SimpleItemConfiguration> configs,
final List<SimpleStrategy> defaults, final List<SimpleStrategy> strategies) {
this.configs = Collections.unmodifiableList(new LinkedList<>(configs));
this.defaults = Collections.unmodifiableList(new LinkedList<>(defaults));
this.strategies = Collections.unmodifiableList(new LinkedList<>(strategies));
}

/**
* Get the item configurations.
*
* @return an unmodifiable list of the item configurations
*/
public List<SimpleItemConfiguration> getConfigs() {
return configs;
}

/**
* Get the default strategies.
*
* @return an unmodifiable list of the default strategies
*/
public List<SimpleStrategy> getDefaults() {
return defaults;
}

/**
* Get all defined strategies.
*
* @return an unmodifiable list of the defined strategies
*/
public List<SimpleStrategy> getStrategies() {
return strategies;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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;

/**
*
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class SimpleFilter {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.Arrays;
import java.util.List;

import org.eclipse.smarthome.core.persistence.config.SimpleConfig;
import org.eclipse.smarthome.core.persistence.strategy.SimpleStrategy;

/**
* This class holds the configuration of a persistence strategy for specific items.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class SimpleItemConfiguration {

private final List<SimpleConfig> items;
private final String alias;
private final List<SimpleStrategy> strategies;
private final List<SimpleFilter> filters;

public SimpleItemConfiguration(final List<SimpleConfig> items, final String alias,
final List<SimpleStrategy> strategies, final List<SimpleFilter> filters) {
this.items = items;
this.alias = alias;
this.strategies = strategies;
this.filters = filters;
}

public List<SimpleConfig> getItems() {
return items;
}

public String getAlias() {
return alias;
}

public List<SimpleStrategy> getStrategies() {
return strategies;
}

public List<SimpleFilter> getFilters() {
return filters;
}

@Override
public String toString() {
return String.format("%s [items=%s, alias=%s, strategies=%s, filters=%s]", getClass().getSimpleName(),
Arrays.toString(items.toArray()), alias, Arrays.toString(strategies.toArray()),
Arrays.toString(filters.toArray()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.config;

/**
* This class represents the configuration that stand for "using all items".
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class SimpleAllConfig extends SimpleConfig {

@Override
public String toString() {
return String.format("%s []", getClass().getSimpleName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.config;

/**
* This class is a base class that needs to be used by every item configuration.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public abstract class SimpleConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.config;

/**
* This class represents the configuration that is used for group items.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class SimpleGroupConfig extends SimpleConfig {

private final String group;

public SimpleGroupConfig(final String group) {
this.group = group;
}

public String getGroup() {
return group;
}

@Override
public String toString() {
return String.format("%s [group=%s]", getClass().getSimpleName(), group);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2014-2016 by the respective copyright holders.
* 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.config;

/**
* This class represents the configuration that identify item(s) by name.
*
* @author Markus Rathgeb - Initial contribution and API
*/
public class SimpleItemConfig extends SimpleConfig {
final String item;

public SimpleItemConfig(final String item) {
this.item = item;
}

public String getItem() {
return item;
}

@Override
public String toString() {
return String.format("%s [item=%s]", getClass().getSimpleName(), item);
}
}
Loading

0 comments on commit adff1ba

Please sign in to comment.