Ok, this comes back to the same thing;

* A declared mixin is NOT to say that it must be included in the
Composite, but that it is a CANDIDATE for inclusion. The exact
composition depends on what methods are found in the Composite.

This seems to be a very recurring issue, and perhaps the single most
complicated thing in Qi4j to overcome initially.


When you declare

@Mixins(SomeEntityMixinWithJustLC.class)
   public interface SomeEntityWithJustLC
       extends SomeEntity, EntityComposite
   {
   }

There is no method that needs an implementation provided by the
SomeEntityMixinWithJustLC mixin, hence it will not be part of the
Composite.

OTOH, if you declare
@Mixins(SomeEntityMixinWithJustLC.class)
   public interface SomeEntityWithJustLC
       extends SomeEntity, EntityComposite, Lifecycle
   {
   }

then THERE IS something needed from the SomeEntityMixinWithJustLC
mixin, namely the create() and remove() methods.

I don't know how this can be better documented, but it obviously needs
some improvements and focus.


Cheers
Niclas

On Sat, Oct 23, 2010 at 4:08 PM, Stanislav Muhametsin
<[email protected]> wrote:
> Quoting Niclas Hedhman <[email protected]>:
>
>> Are you talking about LifeCycle or Initializable??
>>
>> They are handled slightly differently. First of all, LifeCycle methods
>> are only called upon creation/deletion of the Entity, not the instance
>> representing the entity in memory. Also, I vaguely recall that for
>> non-Entities, LifeCycle has no meaning.
>>
>> I also recall that unlike other methods, LifeCycle methods are called
>> on ALL mixins of the Entity (need to verify this, since *I* normally
>> limit LifeCycle to a single Mixin.).
>>
>> On the other hand, Initializable is called (if defined) when a Mixin
>> (that implements it) is instantiated.
>>
>>
>> Does that help??
>
> The test-case is attached. When you run it, only
>
> [main] INFO
> org.qi4j.api.entity.LifecycleMixinTest$SomeEntityMixinWithLCAndProperty -
> create called.
>
> will get printed. The test "doTestWithLCAndProperty" will pass, but the test
> "doTestWithJustLC" will fail.
>
> /*
>  * Copyright (c) 2010, Stanislav Muhametsin. All Rights Reserved.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
> http://www.apache.org/licenses/LICENSE-2.0
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  *
>  */
>
> package org.qi4j.api.entity;
>
> import org.junit.Test;
> import org.qi4j.api.common.QualifiedName;
> import org.qi4j.api.injection.scope.State;
> import org.qi4j.api.injection.scope.This;
> import org.qi4j.api.mixin.Mixins;
> import org.qi4j.api.property.Property;
> import org.qi4j.api.property.StateHolder;
> import org.qi4j.api.unitofwork.UnitOfWork;
> import org.qi4j.bootstrap.AssemblyException;
> import org.qi4j.bootstrap.ModuleAssembly;
> import org.qi4j.entitystore.memory.MemoryEntityStoreService;
> import org.qi4j.spi.uuid.UuidIdentityGeneratorService;
> import org.qi4j.test.AbstractQi4jTest;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
> /**
>  *
>  * @author Stanislav Muhametsin
>  */
> public class LifecycleMixinTest extends AbstractQi4jTest
> {
>
>    public interface SomeEntity
>    {
>        public Property<String> someProperty();
>    }
>
>   �...@mixins(SomeEntityMixinWithJustLC.class)
>    public interface SomeEntityWithJustLC
>        extends SomeEntity, EntityComposite
>    {
>    }
>
>   �...@mixins(SomeEntityMixinWithLCAndProperty.class)
>    public interface SomeEntityWithLCAndProperty
>        extends SomeEntity, EntityComposite
>    {
>    }
>
>    public static abstract class SomeEntityMixinWithJustLC
>        implements SomeEntity, Lifecycle
>    {
>        public static final Logger LOGGER = LoggerFactory.getLogger(
> SomeEntityMixinWithJustLC.class );
>
>       �...@this
>        private SomeEntity _me;
>
>       �...@override
>        public void create()
>            throws LifecycleException
>        {
>            LOGGER.info( "create called." );
>            this._me.someProperty().set( "Some value" );
>        }
>
>       �...@override
>        public void remove()
>            throws LifecycleException
>        {
>        }
>    }
>
>    public static abstract class SomeEntityMixinWithLCAndProperty
>        implements SomeEntity, Lifecycle
>    {
>        public static final Logger LOGGER = LoggerFactory.getLogger(
> SomeEntityMixinWithLCAndProperty.class );
>
>       �...@state
>        private StateHolder _state;
>
>       �...@this
>        private SomeEntity _me;
>
>       �...@override
>        public void create()
>            throws LifecycleException
>        {
>            LOGGER.info( "create called." );
>            this._me.someProperty().set( "Some value" );
>        }
>
>       �...@override
>        public void remove()
>            throws LifecycleException
>        {
>        }
>
>       �...@override
>        public Property<String> someProperty()
>        {
>            return this._state.getProperty( QualifiedName.fromClass(
> SomeEntity.class, "someProperty" ) );
>        }
>    }
>
>   �...@override
>    public void assemble( ModuleAssembly module )
>        throws AssemblyException
>    {
>        module.addServices( MemoryEntityStoreService.class,
> UuidIdentityGeneratorService.class );
>
>        module.addEntities( SomeEntityWithJustLC.class,
> SomeEntityWithLCAndProperty.class );
>    }
>
>   �...@test
>    public void doTestWithJustLC()
>    {
>        UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork();
>        try
>        {
>            EntityBuilder<SomeEntityWithJustLC> builder =
> uow.newEntityBuilder( SomeEntityWithJustLC.class );
>
>            builder.newInstance();
>        }
>        finally
>        {
>            uow.discard();
>        }
>    }
>
>   �...@test
>    public void doTestWithLCAndProperty()
>    {
>        UnitOfWork uow = this.unitOfWorkFactory.newUnitOfWork();
>        try
>        {
>            EntityBuilder<SomeEntityWithLCAndProperty> builder = uow
>                .newEntityBuilder( SomeEntityWithLCAndProperty.class );
>
>            builder.newInstance();
>        }
>        finally
>        {
>            uow.discard();
>        }
>    }
> }
>
> _______________________________________________
> qi4j-dev mailing list
> [email protected]
> http://lists.ops4j.org/mailman/listinfo/qi4j-dev
>
>



-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I  live here; http://tinyurl.com/2qq9er
I  work here; http://tinyurl.com/2ymelc
I relax here; http://tinyurl.com/2cgsug

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to