org.ujorm.extensions
Class Property<UJO extends Ujo,VALUE>

java.lang.Object
  extended by org.ujorm.extensions.Property<UJO,VALUE>
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable<UjoProperty>, CriterionProvider<UJO,VALUE>, UjoProperty<UJO,VALUE>
Direct Known Subclasses:
BeanProperty, FactoryProperty, FieldProperty, ListProperty, RelationToMany, RelationToOne

public class Property<UJO extends Ujo,VALUE>
extends java.lang.Object
implements UjoProperty<UJO,VALUE>

The main implementation of the interface UjoProperty.

Author:
Pavel Ponec
See Also:
AbstractUjo

Constructor Summary
protected Property()
          Protected constructor
protected Property(java.lang.String name, java.lang.Class<VALUE> type, int index)
          Constructor with an property order
protected Property(java.lang.String name, VALUE value, int index)
          Constructor with an property order
 
Method Summary
protected static int _nextSequence()
          Returns a next property index by a synchronized method.
<VALUE_PAR>
CompositeProperty<UJO,VALUE_PAR>
add(UjoProperty<? extends VALUE,VALUE_PAR> property)
          Create new composite (indirect) instance.
 int compareTo(UjoProperty p)
          Compare to another UjoProperty object by the index and name of the property.
 void copy(UJO from, UJO to)
          Copy a value from the first UJO object to second one.
 UjoProperty<UJO,VALUE> descending()
          Create a new instance of the indirect property with a descending direction of order.
 UjoProperty<UJO,VALUE> descending(boolean descending)
          Create a new instance of the indirect property with a descending direction of order.
 boolean equals(UJO ujo, VALUE value)
          Returns true, if the property value equals to a parameter value.
 boolean equalsName(java.lang.CharSequence name)
          Returns true, if the property name equals to the parameter value.
 Criterion<UJO> forAll()
          Create a new Criterion for this property where all results will be true (the result is independed on the value).
 Criterion<UJO> forNone()
          Create a new Criterion for this property where all results will be false (the result is independed on the value).
 Criterion<UJO> forSql(java.lang.String sqlCondition)
          Create a new Criterion for a Native Criterion in SQL statement format.
 VALUE getDefault()
          Returns a Default property value.
 int getIndex()
          Index of Property
 java.lang.String getName()
          Name of Property
 java.lang.Class<VALUE> getType()
          Type of Property
 VALUE getValue(UJO ujo)
          It is a basic method for getting an appropriate type safe value from an MapUjo object.
 char charAt(int index)
          A char from Name
protected  void checkAttribs()
          Check properties
protected  Property<UJO,VALUE> init(java.lang.String name, java.lang.Class<VALUE> type, VALUE defaultValue, int index, java.lang.Boolean lock)
          Property initialization.
 boolean isAscending()
          A flag for a direction of sorting.
 boolean isDefault(UJO ujo)
          Indicates whether a parameter value of the ujo "equal to" this default value.
 boolean isDirect()
          Returns a true value, if the property contains more properties.
 boolean isTypeOf(java.lang.Class type)
          Returns true if the property type is a type or subtype of the parameter class.
 int length()
          Length of the Name
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type, int index)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type, VALUE value, int index, boolean lock)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, VALUE value)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, VALUE value, int index)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
UjoProperty<UJO,VALUE>
newInstance(UjoProperty p)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(UjoProperty p, int index)
          A Property Factory where a property type is related from from default value.
 VALUE of(UJO ujo)
          A shortcut for the method getValue(Ujo).
 void setValue(UJO ujo, VALUE value)
          It is a basic method for setting an appropriate type safe value to an MapUjo object.
 void setValueFromDefault(UJO ujo)
          Assing a value from the default value.
 java.lang.CharSequence subSequence(int start, int end)
          Sub sequence from the Name
 java.lang.String toString()
          Returns a name of Property
 Criterion<UJO> where(Operator operator, UjoProperty<?,VALUE> value)
          Create a new Criterion where this property is related to the value along the parameter Operator.
 Criterion<UJO> where(Operator operator, VALUE value)
          Create a new Criterion where this property is related to the value along the parameter Operator.
 Criterion<UJO> whereEq(UjoProperty<UJO,VALUE> value)
          Create a new Criterion where this property equals the property
 Criterion<UJO> whereEq(VALUE value)
          Create a new Criterion where this property equals the value
 Criterion<UJO> whereGe(VALUE value)
          Create a new Criterion where this property is great or equals the value
 Criterion<UJO> whereGt(VALUE value)
          Create a new Criterion where this property is great then the value
 Criterion<UJO> whereIn(java.util.Collection<VALUE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
 Criterion<UJO> whereIn(VALUE... list)
          Create new Criterion for operator IN to compare value to a list of constants
 Criterion<UJO> whereLe(VALUE value)
          Create a new Criterion where this property is less or equals than the value
 Criterion<UJO> whereLt(VALUE value)
          Create a new Criterion where this property is less then the value
 Criterion<UJO> whereNeq(VALUE value)
          Create a new Criterion where this property not equals the value
 Criterion<UJO> whereNotIn(java.util.Collection<VALUE> list)
          Create new Criterion for operator IN to compare value to a list of constants.
 Criterion<UJO> whereNotIn(VALUE... list)
          Create new Criterion for operator IN to compare value to a list of constants.
 Criterion<UJO> whereNotNull()
          Create a new Criterion where this property is not null.
 Criterion<UJO> whereNull()
          Create a new Criterion where this property is null.
<PROPERTY extends Property>
PROPERTY
writeDefault(VALUE value)
          Assign a Default value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Property

protected Property(java.lang.String name,
                   java.lang.Class<VALUE> type,
                   int index)
Constructor with an property order

Parameters:
name -
type -
index - On order of the property.

Property

protected Property(java.lang.String name,
                   VALUE value,
                   int index)
Constructor with an property order

Parameters:
name -
index - On order of the property.

Property

protected Property()
Protected constructor

Method Detail

_nextSequence

protected static int _nextSequence()
Returns a next property index by a synchronized method. The UJO property indexed by this method may not be in continuous series however numbers have the upward direction always.


init

protected final Property<UJO,VALUE> init(java.lang.String name,
                                         java.lang.Class<VALUE> type,
                                         VALUE defaultValue,
                                         int index,
                                         java.lang.Boolean lock)
Property initialization.

Parameters:
name - Replace the Name of property if the one is NULL.
index - Replace index always, the value -1 invoke a next number from the internal sequencer.
type - Replace the Type of property if the one is NULL.
defaultValue - Replace the Optional default value if the one is NULL.
lock - Lock the property.

checkAttribs

protected void checkAttribs()
Check properties


getName

public final java.lang.String getName()
Name of Property

Specified by:
getName in interface UjoProperty<UJO extends Ujo,VALUE>

getType

public final java.lang.Class<VALUE> getType()
Type of Property

Specified by:
getType in interface UjoProperty<UJO extends Ujo,VALUE>

getIndex

public final int getIndex()
Index of Property

Specified by:
getIndex in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
ArrayUjo, UjoManager.readProperties(Class)

setValue

public final void setValue(UJO ujo,
                           VALUE value)
It is a basic method for setting an appropriate type safe value to an MapUjo object.
For the setting value is used internally a method Ujo.writeValue(org.ujorm.UjoProperty, java.lang.Object)

Specified by:
setValue in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
Ujo.writeValue(org.ujorm.UjoProperty, java.lang.Object)

getValue

public final VALUE getValue(UJO ujo)
It is a basic method for getting an appropriate type safe value from an MapUjo object.
For the getting value is used internally a method Ujo.readValue(org.ujorm.UjoProperty) .
Note: this method replaces the value of null for default

Specified by:
getValue in interface UjoProperty<UJO extends Ujo,VALUE>
Parameters:
ujo - If a NULL parameter is used then an exception NullPointerException is throwed.
Returns:
Returns a type safe value from the ujo object.
See Also:
Ujo.readValue(UjoProperty)

of

public final VALUE of(UJO ujo)
A shortcut for the method getValue(Ujo).

Specified by:
of in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
getValue(Ujo)

getDefault

public VALUE getDefault()
Returns a Default property value. The value replace the null value in the method Ujo.readValue(...). If the default value is not modified, returns the null.

Specified by:
getDefault in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
Ujo.readValue(UjoProperty)

writeDefault

public <PROPERTY extends Property> PROPERTY writeDefault(VALUE value)
Assign a Default value. The default value may be modified after locking - at your own risk.
WARNING: the change of the default value modifies all values in all instances with the null value of the current property!


setValueFromDefault

public void setValueFromDefault(UJO ujo)
Assing a value from the default value.


isDefault

public boolean isDefault(UJO ujo)
Indicates whether a parameter value of the ujo "equal to" this default value.

Specified by:
isDefault in interface UjoProperty<UJO extends Ujo,VALUE>

isDirect

public final boolean isDirect()
Returns a true value, if the property contains more properties. The composite property is excluded from from function Ujo.readProperties() by default.

Specified by:
isDirect in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
CompositeProperty

isAscending

public boolean isAscending()
A flag for a direction of sorting. This method returns true always.

Specified by:
isAscending in interface UjoProperty<UJO extends Ujo,VALUE>
Since:
0.85
See Also:
UjoComparator

descending

public UjoProperty<UJO,VALUE> descending()
Create a new instance of the indirect property with a descending direction of order.

Specified by:
descending in interface UjoProperty<UJO extends Ujo,VALUE>
Returns:
returns a new instance of the indirect UjoProperty
Since:
0.85
See Also:
isAscending(), UjoComparator

descending

public UjoProperty<UJO,VALUE> descending(boolean descending)
Create a new instance of the indirect property with a descending direction of order.

Specified by:
descending in interface UjoProperty<UJO extends Ujo,VALUE>
Returns:
returns a new instance of the indirect UjoProperty
Since:
1.21
See Also:
isAscending(), UjoComparator

add

public <VALUE_PAR> CompositeProperty<UJO,VALUE_PAR> add(UjoProperty<? extends VALUE,VALUE_PAR> property)
Create new composite (indirect) instance.

Specified by:
add in interface UjoProperty<UJO extends Ujo,VALUE>
Since:
0.92

copy

public void copy(UJO from,
                 UJO to)
Copy a value from the first UJO object to second one. A null value is not replaced by the default.

Specified by:
copy in interface UjoProperty<UJO extends Ujo,VALUE>

isTypeOf

public boolean isTypeOf(java.lang.Class type)
Returns true if the property type is a type or subtype of the parameter class.

Specified by:
isTypeOf in interface UjoProperty<UJO extends Ujo,VALUE>

equals

public boolean equals(UJO ujo,
                      VALUE value)
Returns true, if the property value equals to a parameter value. The property value can be null.

Specified by:
equals in interface UjoProperty<UJO extends Ujo,VALUE>
Parameters:
ujo - A basic Ujo.
value - Null value is supported.
Returns:
Accordance

equalsName

public boolean equalsName(java.lang.CharSequence name)
Returns true, if the property name equals to the parameter value.

Specified by:
equalsName in interface UjoProperty<UJO extends Ujo,VALUE>
Parameters:
name - The name of a property

compareTo

public int compareTo(UjoProperty p)
Compare to another UjoProperty object by the index and name of the property.

Specified by:
compareTo in interface java.lang.Comparable<UjoProperty>
Specified by:
compareTo in interface UjoProperty<UJO extends Ujo,VALUE>
Since:
1.20

charAt

public char charAt(int index)
A char from Name

Specified by:
charAt in interface java.lang.CharSequence

length

public int length()
Length of the Name

Specified by:
length in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Sub sequence from the Name

Specified by:
subSequence in interface java.lang.CharSequence

toString

public final java.lang.String toString()
Returns a name of Property

Specified by:
toString in interface java.lang.CharSequence
Specified by:
toString in interface UjoProperty<UJO extends Ujo,VALUE>
Overrides:
toString in class java.lang.Object

newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type,
                                                                      VALUE value,
                                                                      int index,
                                                                      boolean lock)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type,
                                                                      int index)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      VALUE value,
                                                                      int index)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      VALUE value)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(UjoProperty p,
                                                                      int index)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> UjoProperty<UJO,VALUE> newInstance(UjoProperty p)
A Property Factory where a property type is related from from default value.
Warning: Method does not lock the property so you must call AbstractUjo.init(..) method after initialization!


where

public Criterion<UJO> where(Operator operator,
                            VALUE value)
Create a new Criterion where this property is related to the value along the parameter Operator.

Specified by:
where in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

where

public Criterion<UJO> where(Operator operator,
                            UjoProperty<?,VALUE> value)
Create a new Criterion where this property is related to the value along the parameter Operator.

Specified by:
where in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
operator - Operator
  • VALUE - the parameter value
  • UjoProperty - reference to a related entity
  • List<TYPE> - list of values (TODO - this type is planned in the future)
Returns:
A new criterion

whereEq

public Criterion<UJO> whereEq(VALUE value)
Create a new Criterion where this property equals the value

Specified by:
whereEq in interface CriterionProvider<UJO extends Ujo,VALUE>
Returns:
A the new immutable Criterion

whereIn

public Criterion<UJO> whereIn(java.util.Collection<VALUE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Specified by:
whereIn in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion.

whereNotIn

public Criterion<UJO> whereNotIn(java.util.Collection<VALUE> list)
Create new Criterion for operator IN to compare value to a list of constants.

Specified by:
whereNotIn in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

whereIn

public Criterion<UJO> whereIn(VALUE... list)
Create new Criterion for operator IN to compare value to a list of constants

Specified by:
whereIn in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be FALSE in this case.
Returns:
A the new immutable Criterion

whereNotIn

public Criterion<UJO> whereNotIn(VALUE... list)
Create new Criterion for operator IN to compare value to a list of constants.

Specified by:
whereNotIn in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
list - A collection of the values. The collection argument can be the EMPTY, the Criterion result will be TRUE in this case.
Returns:
A the new immutable Criterion.

whereEq

public Criterion<UJO> whereEq(UjoProperty<UJO,VALUE> value)
Create a new Criterion where this property equals the property

Specified by:
whereEq in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
value - UjoProperty can be type a direct of indirect (for a relation) property
Returns:
A the new immutable Criterion

whereNull

public Criterion<UJO> whereNull()
Create a new Criterion where this property is null. The method is a shortcut to the next full expression:
 Criterin.where(Order.NOTE_PROPERTY, Operator.EQ, (String) null) 
for the String property type in this case.

Specified by:
whereNull in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
#whereNotNull(org.ujorm.UjoProperty), Operator.EQ

whereNotNull

public Criterion<UJO> whereNotNull()
Create a new Criterion where this property is not null. The method is a shortcut to the next full expression:
 Criterin.where(Order.NOTE_PROPERTY, Operator.EQ, (String) null) 
for the String property type in this case.

Specified by:
whereNotNull in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
#whereNull(org.ujorm.UjoProperty), Operator.NOT_EQ

whereNeq

public Criterion<UJO> whereNeq(VALUE value)
Create a new Criterion where this property not equals the value

Specified by:
whereNeq in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
Operator.NOT_EQ

whereGt

public Criterion<UJO> whereGt(VALUE value)
Create a new Criterion where this property is great then the value

Specified by:
whereGt in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
Operator.GT

whereGe

public Criterion<UJO> whereGe(VALUE value)
Create a new Criterion where this property is great or equals the value

Specified by:
whereGe in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
Operator.GE

whereLt

public Criterion<UJO> whereLt(VALUE value)
Create a new Criterion where this property is less then the value

Specified by:
whereLt in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
Operator.LT

whereLe

public Criterion<UJO> whereLe(VALUE value)
Create a new Criterion where this property is less or equals than the value

Specified by:
whereLe in interface CriterionProvider<UJO extends Ujo,VALUE>
See Also:
Operator.LE

forSql

public Criterion<UJO> forSql(java.lang.String sqlCondition)
Create a new Criterion for a Native Criterion in SQL statement format. Special features:
  • parameters of the SQL_condition are not supported by the Ujorm
  • your own implementation of SQL the parameters can increase a risk of the SQL injection attacks
  • method #evaluate(org.ujorm.Ujo) is not supported and throws UnsupportedOperationException in the run-time
  • native Criterion dependents on a selected database so application developers should to create support for each supported database of target application to ensure database compatibility

Specified by:
forSql in interface CriterionProvider<UJO extends Ujo,VALUE>
Parameters:
sqlCondition - a SQL condition in the String format, the NULL value or empty string is not accepted
See Also:
Operator.XSQL

forAll

public Criterion<UJO> forAll()
Create a new Criterion for this property where all results will be true (the result is independed on the value). The method evaluate(ujo) returns TRUE always.

Specified by:
forAll in interface CriterionProvider<UJO extends Ujo,VALUE>

forNone

public Criterion<UJO> forNone()
Create a new Criterion for this property where all results will be false (the result is independed on the value). The method evaluate(method) returns FALSE always.

Specified by:
forNone in interface CriterionProvider<UJO extends Ujo,VALUE>


Copyright © 2007-2012 PPonec