Ok, so I came to think about one issue that we are always struggling with
in ES... polymorphism. I.e. we can fetch entities from the store using any
of the declared types and not the "primaryType" used when it is stored.

However, that raises the question... Should the following work at all?

Person person = uow.get( Identity.class, "Niclas" );
if( entity instanceof  Engineer )
{
    Person p = (Person) entity;
    :
    :
}

I think at the moment, it will actually cast to Engineer (assuming I was
saved as it)  and one can do whatever one wants with that. But, I could
imagine that the proper contract to be that downcasting should not work, as
only the Person interface is wrapping the entity state. Under the hood, the
complete entity state of Engineer (and others) is still preserved in full
and not lost during a new save cycle.

Again, I am leaving out Query for a later discussion.

Cheers

On Sun, Oct 16, 2016 at 10:20 AM, Niclas Hedhman <nic...@hedhman.org> wrote:

> Hi again,
> While looking into the feasibility of implementing a Repository
> EntityStore I realized that the current SPI seems flawed.
>
> The TYPE of an entity is stored with the entity and not the entity type
> that is being processed by the outside world. And then type lookup is used
> via the current Module associated to the current UnitOfWork.
>
> It seems more logical to me that an EnttyDscriptor is passed down to the
> EntityStore, so that the type doesn't need to be looked up. For ES, this
> seems to work well, although this doesn't solve a similar issue in the
> Query system.
>
> I would like to change the EntityStoreSPI from
>
>
> public interface EntityStoreSPI
> {
>     EntityState newEntityState( EntityStoreUnitOfWork unitOfWork,
>                                 EntityReference identity,
>                                 EntityDescriptor entityDescriptor
>     );
>
>     EntityState entityStateOf( EntityStoreUnitOfWork unitOfWork,
>                                ModuleDescriptor module,
>                                EntityReference identity );
>
>     String versionOf( EntityStoreUnitOfWork unitOfWork,
>                       EntityReference identity );
>
>     StateCommitter applyChanges( EntityStoreUnitOfWork unitOfWork,
>                                  Iterable<EntityState> state );
> }
>
> to
>
> public interface EntityStoreSPI
> {
>     EntityState newEntityState( EntityStoreUnitOfWork unitOfWork,
>                                 EntityReference identity,
>                                 EntityDescriptor entityDescriptor
>     );
>
>     EntityState entityStateOf( EntityStoreUnitOfWork unitOfWork,
>                                EntityReference identity,
>                                EntityDescriptor entityDescriptor );
>
>     String versionOf( EntityStoreUnitOfWork unitOfWork,
>                       EntityReference identity,
>                       EntityDescriptor entityDescriptor );
>
>     StateCommitter applyChanges( EntityStoreUnitOfWork unitOfWork,
>                                  Iterable<EntityState> state );
> }
>
>
> which I think can handle the requirements of Repository ES more elegantly.
>
> WDYT?
>
> Cheers
> --
> Niclas Hedhman, Software Developer
> http://zest.apache.org - New Energy for Java
>



-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Reply via email to