-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Marking owner of custom persistent set dirty when modifying
PostPosted: Sun Dec 20, 2009 2:47 pm 
Newbie

Joined: Sun Dec 20, 2009 9:17 am
Posts: 1
Hi -

I am trying to build my own little application server. The application server is to use optimistic concurrency control, e.g. I use update ticks (Lamport) on every entity.
More concretely I have a common interface that all entities must implement.
The interface is called IObject:
Code:
public interface IObject extends Serializable
{
   long getId();
   long getUpdateTick();
   Class<? extends IObject> getInterface();
   void setUpateTick(long updateTick);
}


Let us now have a look a specialization of IObject
Code:
@Implementor(implementor = OneToMany.class)
public interface IOneToMany extends IObject
{
   Set<IManyToOne> getManyToOne();
}

and its implementation:
Code:
@SuppressWarnings("serial")
class OneToMany extends BaseObject implements IOneToMany
{
   @ReferenceSet(clazz = IManyToOne.class)
   @Bidirectional(properyRef = "oneToMany")
   private final Set<IManyToOne> manyToOne;
   public OneToMany()
   {
      manyToOne = new BidirectionalSet<IManyToOne>(this, "manyToOne");
   }
   @Override
   public Set<IManyToOne> getManyToOne()
   {
      return manyToOne;
   }
   @Override
   public final Class<? extends IObject> getInterface()
   {
      return IOneToMany.class;
   }
}

Do not mind the special collection BidirectionalSet<IManyToOne>. The collection enables me to detect updates on bidirectional mappings.

My problem is that when I modify the manyToOne set I only get a change on the collection not the collections owner.
My question is, how would one mark the owner of an collection dirty when the collection is modified.

Once I have this my interceptor will take care of update tick incrementation
Code:
public class UpdateTickInterceptor extends AbstractSimpleInterceptor
{
   @Override
   public InterceptResult onFlushDirty(Object entity, Serializable id, Object currentState, Object previousState, String propertyName, Type type)
   {
      if(entity instanceof IObject && propertyName.equals("updateTick"))
      {
         long updateTick = (Long) previousState + 1;
         long currentUpdateTick = (Long) currentState;
         if(updateTick > currentUpdateTick)
         {
            TraceLoggers.PERSISTENCE.info("Increased update tick of " + entity + " to " + currentState);
            return new InterceptResult(updateTick);
         }
      }
      return InterceptResult.NOT_CHANGED;
   }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.