0% found this document useful (0 votes)
67 views

Adf Entity Object Notes: State and Entity-State

The document discusses entity objects and view objects in ADF. An entity object provides an object-oriented representation of data from a database table or view. Database rows are presented as entity objects with attributes corresponding to columns. The status of an entity object's data relative to the database is indicated by its post-state and entity-state. Post-state indicates if the data has changed in the current transaction. Entity-state indicates if the data is current in the database. View objects allow querying entity cache data and presenting query results. Related entity rows can be accessed using association accessors. The document provides examples of defaulting attribute values, refreshing entity data, and conditionally preventing entity removal.

Uploaded by

paresh.bapna
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Adf Entity Object Notes: State and Entity-State

The document discusses entity objects and view objects in ADF. An entity object provides an object-oriented representation of data from a database table or view. Database rows are presented as entity objects with attributes corresponding to columns. The status of an entity object's data relative to the database is indicated by its post-state and entity-state. Post-state indicates if the data has changed in the current transaction. Entity-state indicates if the data is current in the database. View objects allow querying entity cache data and presenting query results. Related entity rows can be accessed using association accessors. The document provides examples of defaulting attribute values, refreshing entity data, and conditionally preventing entity removal.

Uploaded by

paresh.bapna
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

ADF ENTITY OBJECT NOTES

>> An Entity Object provides an object-oriented representation of the data it caches from a database object, such as a table or
view. Database rows are presented as individual Entities, in which attributes typically correspond to columns in the corresponding
table.
>> he status of an Entity Object!s data, relative to the corresponding database data, are indicated by its current post-
state and Entity-state.
Post state indicates the state of the Entity Object!s data relative to the transaction!s data
Entity State indicates the state of the Entity Object's data relatie to the act!al database
>> "or post-state#
STAT"S#$ODIFIED % if this Entity Object has been &!eried fro' the database and has chan(ed)
STAT"S#INITIA*I+ED % if this Entity Object is ne, and the client a--lication chan(ed it's state to 'a.e this
Object te'-orary.
STAT"S#NE/ % if this Entity Object is ne, in the -ost%cycle)
STAT"S#DE*ETED % if this Entity Object has been 'ar.ed for deletion)
STAT"S#DEAD % if this Entity Object is ne,0 b!t has been deleted)
// In OrderEOImpl.java in Fusion Order Demo
protected void create(AttributeList nameValuePair)
super.create(nameValuePair)!
t"is.setOrderDate(ne# Date())!
$
Defaulting an Attribute Value from a Database Sequence
%ometimes &ou ma& #ant to ea'erl& allocate a se(uence number at entit& ro# creation time so t"at t"e user can see its value and so t"at t"is
value does not c"an'e #"en t"e data is saved. )o accomplis" t"is* use t"e %e(uenceImpl "elper class in t"e oracle.jbo.server pac+a'e in an
overridden create() met"od, e',
// In -are"ouseEOImpl.java
import oracle.jbo.server.%e(uenceImpl!
// De.ault -are"ouseId value .rom -A/E0O1%E2%E3 se(uence at entit& ro# create time
protected void create(AttributeList attributeList)
super.create(attributeList)!
%e(uenceImpl se(uence 4 ne# %e(uenceImpl(5-A/E0O1%E2%E35*'etD6)ransaction())!
set-are"ouseId(se(uence.'et%e(uence7umber())!
$
A.ter callin' super.create()* it creates a ne# instance o. t"e %e(uenceImpl object* passin' t"e se(uence name and t"e current transaction
object. )"en it calls t"e set-are"ouseId() attribute setter met"od #it" t"e return value .rom %e(uenceImpl8s 'et%e(uence7umber() met"od.
Assign Derived Values Before Saving
)o per.orm t"e assi'nment onl& durin' I7%E/)* 1PDA)E* or DELE)E* &ou can compare t"e value o. t"e operation parameter passed to t"is met"od
a'ainst t"e inte'er constants D9L2I7%E/)* D9L21PDA)E* D9L2DELE)E respectivel&..
protected void prepareForD9L(int operation* )ransactionEvent e)
super.prepareForD9L(operation* e)!
//Populate :L Date
i. (operation 44 D9L2I7%E/))
;.
i. ((operation 44 D9L2I7%E/)) << (operation 44 D9L21PDA)E))
7O)E 0E/E OPE/A)IO7 I% I7)E:E/ I.E D9L2I7%E/)* D9L21PDA)E* D9L2DELE)E A/E I7)E:E/ =O7%)A7)
CALLING SETTE !ET"#D$ #% AN ATTIB&TE' %#! AN#T"E SETTE !ET"#D ATTIB&TE
public void setAssi'ned)o(7umber value)
setAttributeInternal(A%%I:7ED)O* value)!
setAssi'nedDate('et=urrentDate-it")ime())!
$
7O)E )0A) , setAttributeInternal(A%%I:7ED)O* value)! I% =ALLED A7D )0E7 A7O)0E/ A))/I61)E %EE))E/ 9E)0OD
Undoing Pending Changes to an Entity Using the Refresh Method
>ou can use t"e re.res"(int .la') met"od on a ro# to re.res" an& pendin' c"an'es it mi'"t "ave. )"e be"avior o. t"e re.res"() met"od depends
on t"e .la' t"at &ou pass as a parameter. )"e t"ree +e& .la' values t"at control its be"avior are t"e .ollo#in' constants in
t"e /o# inter.ace,
/EF/E%02-I)02D62FO/:E)2=0A7:E% %I9ILA/ )O /OLL 6A=?
For'ets modi.ications made to t"e ro# in t"e current transaction* and t"e ro#8s data is re.res"ed .rom t"e database. )"e latest
data .rom t"e database replaces data in t"e ro# re'ardless o. #"et"er t"e ro# #as modi.ied or not.
/EF/E%02-I)02D62O7L>2IF217=0A7:ED %I9PLE /EF/E%0* IF 7O 9ODIFI=A)IO7 6EI7: 9ADE
-or+s just li+e /EF/E%02-I)02D62FO/:E)2=0A7:E%* but .or unmodi.ied ro#s. I. a ro# #as alread& modi.ied b& t"is transaction* t"e
ro# is not re.res"ed.
/EF/E%0217DO2=0A7:E% %I9PLE /EF/E%0 FO/ 179ODIFIED /O-% @ /OLL 6A=? FO/ 9ODIFIED /O-%
-or+s t"e same as /EF/E%02-I)02D62FO/:E)2=0A7:E% .or unmodi.ied ro#s. For a modi.ied ro#* t"is mode re.res"es t"e ro# #it"
attribute values at t"e be'innin' o. t"is transaction. )"e ro# remains in a modi.ied state i. it "ad been previousl& posted but
not committed in t"e current transaction prior to per.ormin' t"e re.res" operation.
Controlling Ne( o(s of E#) During a efres*
6& de.ault* an& entit& ro#s #it" 7e# status t"at &ou re.res"() are reverted bac+ to blan+ ro#s in t"e InitialiAed state. Declarative de.aults
are reset* as #ell as pro'rammatic de.aults coded in t"e initDe.aultEBpressionAttributes() met"od* but t"e entit& object8s create() met"od is
not invo+ed durin' t"is blan+in'Cout process.
>ou can c"an'e t"is de.ault be"avior b& combinin' one o. t"e .la's in %ection D.E #it" one o. t"e .ollo#in' t#o .la's (usin' t"e bit#iseC
O/ operator),
/EF/E%02/E9OVE27E-2/O-%* ne# ro#s are removed durin' re.res".
/EF/E%02FO/:E)27E-2/O-%* ne# ro#s are mar+ed Dead.
Using View Objects for Validation
-"en &our business lo'ic re(uires per.ormin' %3L (ueries* t"e natural c"oice is to use a vie# object to per.orm t"at tas+. ?eep in mind t"at
t"e %3L statements &ou eBecute .or validation #ill 5see5 pendin' c"an'es in t"e entit& cac"e onl& i. t"e& are entit&Cbased vie# objects.
/eadConl& vie# objects #ill onl& retrieve data t"at "as been posted to t"e database.
&se Vie( Accessors$VA' for Validation Against Vie( #b+ects
VAs A/E 1%ED )O AVOID )I:0) =O1PLI7: OF VO% O7 EO%. -E %0O1LD 7O) I7%)A7)IA)E A7> VO O/ :E) )0E 0A7DLE OF =1//E7) VO /A)0E/ 1%E VA )O :E) )0E
0A7DLE. )0I% I% O7E OF )0E 1%E OF VA.
// %ample entit&Clevel validation met"od
public boolean validate%omet"in'1sin'Vie#Accessor()
/o#%et rs 4 'et9&ValidationVO()!
rs.set7amed6indParameter(57ameF5* valueF)!
rs.set7amed6indParameter(57ameG5* valueG)!
rs.eBecute3uer&()!
i. ( /H some condition H/)
/H
H code "ere returns true i. t"e validation succeeds
H/
$
return .alse!
$
BETTER IS TO CREATE NEW ROW SET INSTEAD OF USING CURRENT ROW SET An& time &ou access a ro# set pro'rammaticall&* &ou s"ould consider
creatin' a secondar& iterator .or t"e ro# set. )"is ensures t"at &ou #ill not disturb t"e current ro# set o. t"e de.ault ro# set iterator
t"at ma& be utiliAed #"en &our eBpose &our vie# objects as data controls to t"e user inter.ace project. >ou can call create/o#%etIterator()
on t"e ro# set &ou are #or+in' #it" to create a secondar& named ro# set iterator. -"en &ou are t"rou'" #it" pro'rammatic iteration* &our code
s"ould call close/o#%etIterator() on t"e ro# set to remove t"e secondar& iterator .rom memor&.
"o( to Access elated Entit, o(s
>ou can use an association accessor to access related entit& ro#s.
"o( to Access elated Entit, o( Sets
I. t"e cardinalit& o. t"e association is suc" t"at multiple ro#s are returned* &ou can use t"e association accessor to return sets o. entit&
ro#s.
/o#%et ne#Products6e.orePost 4 null!
IOverride
public void post="an'es()ransactionEvent transactionEvent)
/H Onl& update re.erences i. %upplier is ne# H/
i. ('etPost%tate() 44 %)A)1%27E-)
/H
H :et a ro#set o. products related to t"is ne# supplier be.ore callin' super
H/
ne#Products6e.orePost 4 (/o#%et)getProductsBase()!
$
super.post="an'es(transactionEvent)!
$
...
Conditionally Preventing an Entity Row from Being Removed
6e.ore an entit& ro# is removed* t"e remove() met"od is invo+ed on an entit& ro#. >ou can t"ro# a JboEBception in t"e remove() met"od to
prevent a ro# .rom bein' removed i. t"e appropriate conditions are not met.
// In t"e Addresses entit& object custom Java class
private boolean isDeleteAllo#ed()
b&te s 4 t"is.'etEntit&%tate()!
return s44%)A)1%27E-!
$

/HH
H Add entit& remove lo'ic in t"is met"od.
H/
public void remove()
i. (isDeleteAllo#ed())
super.remove()!
else
t"ro# ne# JboEBception(5Delete not allo#ed in t"is vie#5)!
$
SO! "E#E!$O%& Removing a row from a '(ery collection witho(t deleting it from the
database
htt-122adfcodebits)blo(s-ot)in234542462bit%57%re'oin(%ro,%fro'%&!ery)ht'l
There are times when you want to remove a row from a query collection (the query result) without actually removing it from the database. The query collection
- oracle.jbo.server.QueryCollection - gets popullated each time the View is executed - when the View's associated query is run, and represents the query result. hile the Row.remove() will
remove the query collection row it will also remove the underlying Entity row - for an Entity-based View - and post a deletion to the database. !f your programming tas" requires that the row is
removed from the query collection only, i.e. removing a table row in the #! without actually posting a delete to the database, use the $ow method removeFromCollection() instead. %ust be
aware that each time the View is re-executed the Row will show up once again&
// in the context of the ApplModule!pl
// re!ove the current row fro! the "uery collection
E!ployeesRow!pl e!ployee # $E!ployeesRow!pl%$this.&etE!ployees$%.&etCurrentRow$%%'
e!ployee.removeFromCollection()'

You might also like