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;
}
}