public class RecordTemplateImpl<K,T extends net.java.ao.RawEntity<K>> extends Object implements RecordTemplate<T>
Modifier and Type | Field and Description |
---|---|
private T |
fieldsToOverrideProxy |
private T |
fieldsToWriteIfNullProxy |
private Function<String,Method> |
getterMethodsCache
The 'getter provider' for the type 'type', as returned by
DAOReflectionUtils.getGetterMethodsCached(java.lang.Class<T>) |
private static org.apache.log4j.Logger |
log |
private DAOCache<K,T> |
parentDAOCache
Not exactly necessary, but keeping a reference to the cache allows for the convenience methods
such as .create(), .createOrUpdate().
|
protected T |
primaryFieldsProxy |
protected Class<T> |
type |
protected Map<String,AssignableValue> |
values |
Constructor and Description |
---|
RecordTemplateImpl(Class<T> type) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the record template, so it can be reused for another record.
|
T |
create()
Convenience method to call
DAOCache.create(com.playsql.utils.activeobjects.cache.RecordTemplate<T>)
But realistically, if you are using the DAOCache , you rather want to call RecordTemplate.createOrUpdate() . |
private T |
createDynamicProxy(Map<String,AssignableValue> values,
boolean usedForQueries,
boolean usedForWrites,
boolean usedForWritesIfTargetIsNull) |
T |
createOrUpdate()
Convenience method to call
DAOCache.createOrUpdate(com.playsql.utils.activeobjects.cache.RecordTemplate<T>) |
T |
fieldsToOverride()
Use this method to set the fields which must be written in all cases when calling create() or update().
|
T |
fieldsToWriteIfNull()
Use this method to set the fields (other than primary key) that must be written in the DB if
the previous value is null.
|
Predicate<T> |
getRecordMatcher()
Returns a predicate that can tell whether any record perfectly matches this template.
|
Map<String,Object> |
getTableFields()
Return the list of field names (the column names in Active Objects) and values, in preparation for an AO Query.
|
private Object |
getValueForField(T target,
String setterName) |
(package private) T |
primaryFields() |
T |
searchFirst()
Convenience method to call
DAOCache.searchFirst(com.playsql.utils.activeobjects.cache.RecordTemplate<T>) |
boolean |
setAll(T target,
boolean checkValuesBeforeSetting)
Set all values of 'this' into 'target'
|
private boolean |
setAll(T target,
Map<String,AssignableValue> values,
boolean checkValuesBeforeSetting)
Set all the provided values into 'target'
|
void |
setFieldsIfNull(Consumer<T> callback)
Use this method to set the "write" fields, i.e.
|
void |
setFieldsOverwrite(Consumer<T> callback)
Use this method to set the "write" fields, i.e.
|
void |
setGetterMethodsCache(Function<String,Method> getterMethodsCache) |
void |
setParentDAOCache(DAOCache<K,T> parentDAOCache) |
void |
setPrimaryKey(Consumer<T> callback)
Use this method to set the primary key of the record - Those fields will be used in the queries for example.
|
String |
toString() |
private static final org.apache.log4j.Logger log
protected final Map<String,AssignableValue> values
private Function<String,Method> getterMethodsCache
DAOReflectionUtils.getGetterMethodsCached(java.lang.Class<T>)
private DAOCache<K,T extends net.java.ao.RawEntity<K>> parentDAOCache
public void clear()
RecordTemplate
clear
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
T primaryFields()
public T fieldsToOverride()
RecordTemplate
fieldsToOverride
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public T fieldsToWriteIfNull()
RecordTemplate
fieldsToWriteIfNull
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public void setPrimaryKey(Consumer<T> callback)
RecordTemplate
setPrimaryKey
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public void setFieldsIfNull(Consumer<T> callback)
RecordTemplate
RecordTemplate.create()
.
Note that booleans cannot be set using this method, because they are always considered to be 'false'
if null.
Don't forget to call RecordTemplate.createOrUpdate()
or RecordTemplate.create()
afterwards ;)setFieldsIfNull
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public void setFieldsOverwrite(Consumer<T> callback)
RecordTemplate
RecordTemplate.createOrUpdate()
or RecordTemplate.create()
afterwards ;)setFieldsOverwrite
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public boolean setAll(T target, boolean checkValuesBeforeSetting)
setAll
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
checkValuesBeforeSetting
- if true, we'll call the getters before setting the values, to check whether
the value is already equal. If false, we don't call the getters by default.private boolean setAll(T target, Map<String,AssignableValue> values, boolean checkValuesBeforeSetting)
checkValuesBeforeSetting
- if true, we'll call the getters before setting the values, to check whether
the value is already equal. If false, we don't call the getters by default.public Predicate<T> getRecordMatcher()
RecordTemplate
getRecordMatcher
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public Map<String,Object> getTableFields()
RecordTemplate
getTableFields
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public T create()
RecordTemplate
DAOCache.create(com.playsql.utils.activeobjects.cache.RecordTemplate<T>)
But realistically, if you are using the DAOCache
, you rather want to call RecordTemplate.createOrUpdate()
.create
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public T createOrUpdate()
RecordTemplate
DAOCache.createOrUpdate(com.playsql.utils.activeobjects.cache.RecordTemplate<T>)
createOrUpdate
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
public T searchFirst()
RecordTemplate
DAOCache.searchFirst(com.playsql.utils.activeobjects.cache.RecordTemplate<T>)
searchFirst
in interface RecordTemplate<T extends net.java.ao.RawEntity<K>>
private T createDynamicProxy(Map<String,AssignableValue> values, boolean usedForQueries, boolean usedForWrites, boolean usedForWritesIfTargetIsNull)
Copyright © 2022 Requirement Yogi. All rights reserved.