[New] Added a ElementMap.getTemplate()-method

This really simplifies the working with templates in Strolch. Just know
the type of template, retrieve it, clone it and then set your values.
This commit is contained in:
Robert von Burg 2014-06-28 01:05:13 +02:00
parent a087f4a624
commit 76274b81c8
4 changed files with 33 additions and 0 deletions

View File

@ -38,6 +38,25 @@ public interface ElementMap<T extends StrolchElement> {
public long querySize(StrolchTransaction tx, String type);
/**
* Returns the element with the type "Template" and the id = type
*
* @param tx
* the open {@link StrolchTransaction}
* @param type
* The template id to return
* @return the template, or null if it does not exist
*/
public T getTemplate(StrolchTransaction tx, String type);
/**
*
*
* @param tx
* @param type
* @param id
* @return
*/
public T getBy(StrolchTransaction tx, String type, String id);
/**

View File

@ -29,6 +29,7 @@ import li.strolch.model.StrolchElement;
import li.strolch.persistence.api.StrolchDao;
import li.strolch.persistence.api.StrolchPersistenceException;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
import ch.eitchnet.utils.dbc.DBC;
/**
@ -70,6 +71,11 @@ public abstract class CachedElementMap<T extends StrolchElement> implements Elem
return getKeysBy(tx, type).size();
}
@Override
public T getTemplate(StrolchTransaction tx, String type) {
return getBy(tx, StrolchConstants.TEMPLATE, type);
}
@Override
public T getBy(StrolchTransaction tx, String type, String id) {
Map<String, T> byType = this.elementMap.get(type);

View File

@ -7,6 +7,7 @@ import li.strolch.agent.api.ElementMap;
import li.strolch.model.StrolchElement;
import li.strolch.persistence.api.StrolchDao;
import li.strolch.persistence.api.StrolchTransaction;
import li.strolch.runtime.StrolchConstants;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
@ -38,6 +39,11 @@ public abstract class TransactionalElementMap<T extends StrolchElement> implemen
return getDao(tx).querySize(type);
}
@Override
public T getTemplate(StrolchTransaction tx, String type) {
return getBy(tx, StrolchConstants.TEMPLATE, type);
}
@Override
public T getBy(StrolchTransaction tx, String type, String id) {
return getDao(tx).queryBy(type, id);

View File

@ -36,6 +36,8 @@ public class StrolchConstants {
public static final String DEFAULT_XML_VERSION = "1.0"; //$NON-NLS-1$
public static final String DEFAULT_ENCODING = "utf-8"; //$NON-NLS-1$
public static final String TEMPLATE = "Template";
/**
* This interpretation value indicates that the value of the {@link Parameter} should be understood as a reference
* to a {@link Resource}