@@ -57,7 +57,8 @@ public class DataChunk implements Chunk {
5757 //cache-dependency parameters
5858 private volatile byte [] chunk ;
5959 private volatile ValueSet dcs ; //datacolumn set
60- private byte [] id ;
60+ private Comparable id ;
61+ private byte [] serializedId ;
6162 private Object entity ;
6263 private Object undoentity ;
6364 private DataChunk source ;
@@ -111,8 +112,8 @@ public DataObject getT() {
111112 return t ;
112113 }
113114
114- public byte [] getId (Session s ) throws InvocationTargetException , NoSuchMethodException , ClassNotFoundException , InstantiationException , IllegalAccessException , UnsupportedEncodingException , InternalException {
115- if (id ==null ) {
115+ public Comparable getId (Session s ) throws InvocationTargetException , NoSuchMethodException , IllegalAccessException {
116+ if (serializedId ==null ) {
116117 if (entity ==null ) {
117118 getEntity ();
118119 }
@@ -130,17 +131,50 @@ public byte[] getId (Session s) throws InvocationTargetException, NoSuchMethodEx
130131 if (sa !=null ) {
131132 Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), null );
132133 Object v = z .invoke (entity , null );
133- id = sr . serialize ( f [ i ]. getType (). getName (), v ) ;
134+ id = ( Comparable ) v ;
134135 } else {
135136 Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), new Class <?>[]{Session .class });
136137 Object v = z .invoke (entity , new Object []{s });
137- id = sr . serialize ( f [ i ]. getType (). getName (), v ) ;
138+ id = ( Comparable ) v ;
138139 }
139140 }
140141 }
141142 }
142143 return id ;
143144 }
145+
146+ public byte [] getSerializedId (Session s ) throws InvocationTargetException , NoSuchMethodException , ClassNotFoundException , InstantiationException , IllegalAccessException , UnsupportedEncodingException , InternalException {
147+ if (serializedId ==null ) {
148+ if (entity ==null ) {
149+ getEntity ();
150+ }
151+ Class c = entity .getClass ();
152+ final TransEntity ta = (TransEntity )c .getAnnotation (TransEntity .class );
153+ final SystemEntity sa = (SystemEntity )c .getAnnotation (SystemEntity .class );
154+ if (ta !=null ) {
155+ //for Transactional Wrapper Entity we must get superclass (original Entity class)
156+ c = c .getSuperclass ();
157+ }
158+ Field [] f = c .getDeclaredFields ();
159+ for (int i =0 ; i <f .length ; i ++) {
160+ final Id a = f [i ].getAnnotation (Id .class );
161+ if (a !=null ) {
162+ if (sa !=null ) {
163+ Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), null );
164+ Object v = z .invoke (entity , null );
165+ id = (Comparable ) v ;
166+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
167+ } else {
168+ Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), new Class <?>[]{Session .class });
169+ Object v = z .invoke (entity , new Object []{s });
170+ id = (Comparable ) v ;
171+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
172+ }
173+ }
174+ }
175+ }
176+ return serializedId ;
177+ }
144178
145179 public int getBytesAmount () {
146180 return this .getChunk ().length +this .getHeader ().getHeader ().length ;
@@ -243,11 +277,13 @@ public DataChunk (Object o, Session s, RowId r) throws IOException, InvocationTa
243277 if (sa !=null ) {
244278 final Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), null );
245279 final Object v = z .invoke (o , null );
246- id = sr .serialize (f [i ].getType ().getName (), v );
280+ id = (Comparable ) v ;
281+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
247282 } else {
248283 final Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), new Class <?>[]{Session .class });
249284 final Object v = z .invoke (o , new Object []{s });
250- id = sr .serialize (f [i ].getType ().getName (), v );
285+ id = (Comparable ) v ;
286+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
251287 }
252288 }
253289 }
@@ -322,13 +358,16 @@ public DataChunk (byte[] b, DataObject t, RowHeader h, DataChunk source) throws
322358 //All var length types is non-primitive
323359 final byte [] data = bs .substring (s +v , s +v +(Types .isVarType (cs [i ])?bs .getIntFromBytes (bs .substring (s ,s +v )):Types .getLength (cs [i ])));
324360 if (a !=null ) {
325- id = data ;
361+ serializedId = data ;
326362 }
327363 try {
328364 if (Modifier .isPrivate (m )) {
329365 cs [i ].setAccessible (true );
330366 }
331367 dcs .getValueSet ()[i ] = sr .deserialize (data , cs [i ]);
368+ if (a !=null ) {
369+ id = (Comparable ) dcs .getValueSet ()[i ];
370+ }
332371 } catch (UnsupportedEncodingException e ) {
333372 dcs .getValueSet ()[i ] = "UnsupportedEncodingException" ;
334373 }
@@ -353,13 +392,16 @@ public DataChunk (String h, FrameData bd) throws ClassNotFoundException, Instant
353392 //All var length types is non-primitive
354393 final byte [] data = bs .substring (s +v , s +v +(Types .isVarType (cs [i ])?bs .getIntFromBytes (bs .substring (s ,s +v )):Types .getLength (cs [i ])));
355394 if (a !=null ) {
356- id = data ;
395+ serializedId = data ;
357396 }
358397 try {
359398 if (Modifier .isPrivate (m )) {
360399 cs [i ].setAccessible (true );
361400 }
362401 dcs .getValueSet ()[i ] = sr .deserialize (data , cs [i ]);
402+ if (a !=null ) {
403+ id = (Comparable ) dcs .getValueSet ()[i ];
404+ }
363405 } catch (UnsupportedEncodingException e ) {
364406 dcs .getValueSet ()[i ] = "UnsupportedEncodingException" ;
365407 }
@@ -387,13 +429,16 @@ public DataChunk (String h, Table t, Transaction tx) throws ClassNotFoundExcepti
387429 //All var length types is non-primitive
388430 final byte [] data = bs .substring (s +v , s +v +(Types .isVarType (cs [i ])?bs .getIntFromBytes (bs .substring (s ,s +v )):Types .getLength (cs [i ])));
389431 if (a !=null ) {
390- id = data ;
432+ serializedId = data ;
391433 }
392434 try {
393435 if (Modifier .isPrivate (m )) {
394436 cs [i ].setAccessible (true );
395437 }
396438 dcs .getValueSet ()[i ] = sr .deserialize (data , cs [i ]);
439+ if (a !=null ) {
440+ id = (Comparable ) dcs .getValueSet ()[i ];
441+ }
397442 } catch (UnsupportedEncodingException e ) {
398443 dcs .getValueSet ()[i ] = "UnsupportedEncodingException" ;
399444 }
@@ -450,11 +495,13 @@ public byte[] flush (Session s) throws IOException, InvocationTargetException, N
450495 if (sa !=null ) {
451496 final Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), null );
452497 final Object v = z .invoke (this .entity , null );
453- id = sr .serialize (f [i ].getType ().getName (), v );
498+ id = (Comparable ) v ;
499+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
454500 } else {
455501 final Method z = c .getMethod ("get" +f [i ].getName ().substring (0 ,1 ).toUpperCase ()+f [i ].getName ().substring (1 ,f [i ].getName ().length ()), new Class <?>[]{Session .class });
456502 final Object v = z .invoke (this .entity , new Object []{s });
457- id = sr .serialize (f [i ].getType ().getName (), v );
503+ id = (Comparable ) v ;
504+ serializedId = sr .serialize (f [i ].getType ().getName (), v );
458505 }
459506 }
460507 }
0 commit comments