And

public interface AddressValue extends Address, ValueComposite
{}


??

On Fri, Nov 13, 2009 at 5:07 PM, Jacek Sokulski <[email protected]> wrote:
> Hello,
> I have encountered a problem with ValueComposite persistence, i.e
> Property<VC> is not persisted.
> Here is the code:
> Value composite:
> @Mixins(Address.AddressMixin.class)
> public interface Address {
>     String street();
>     String zipcode();
>     String city();
>     String country();
>     String asString();
>
>     interface AddressState {
>         Property<String> street();
>         Property<String> city();
>         Property<String> zipcode();
>         Property<String> country();
>     }
>
>  class AddressMixin implements Address{
>     �...@this AddressState state;
>     public String city() {
>         return state.city().get();
>     }
>
>     public String country() {
>         return state.country().get();
>     }
>
>     public String street() {
>         return state.street().get();
>     }
>
>     public String zipcode() {
>         return state.zipcode().get();
>     }
>     public String asString(){
>         return "country: " + country();
>     }
>  }
> }
>
> Entity Composite:
> @Mixins(Lead.LeadMixin.class)
> public interface Lead
> {
>     String name();
>     Address address();
>     void remove();
>     String asString();
>
>     public interface LeadState
>     {
>         Property<String> name();
>         Property<Boolean> isActive();
>         Property<AddressValue> address();
>     }
>
>     public class LeadMixin implements Lead {
>         @This LeadState state;
>         Property<Boolean> isActive;
>         public void remove() {
>             isActive.set(false);
>         }
>         public Address address() {
>             return state.address().get();
>         }
>         public String name() {
>             return state.name().get();
>         }
>
>         public String asString(){
>             return "Name: " + name() + ", Address: " + address().asString();
>         }
>     }
>
> }
>
> VC creation:
> @Mixins(AddressFactory.AddressFactoryMixin.class)
> public interface AddressFactory {
>     Address create(String country, String city, String street, String
> zipcode);
>
>     class AddressFactoryMixin implements AddressFactory {
>         @Structure ValueBuilderFactory vbf;
>
>         public Address create(String country, String city, String street,
>                 String zipcode) {
>             ValueBuilder<Address> builder =
> vbf.newValueBuilder(Address.class);
>             AddressState addressState =
> builder.prototypeFor(AddressState.class);
>             addressState.country().set(country);
>             addressState.city().set(city);
>             addressState.street().set(street);
>             addressState.zipcode().set(zipcode);
>             Address address = builder.newInstance();
>             return address;
>         }
>
>     }
> }
>
> EC creation:
> @Mixins(LeadFactory.LeadFactoryMixin.class)
> public interface LeadFactory {
>     Lead create(String name, Address address);
>
>     class LeadFactoryMixin implements LeadFactory {
>         @Structure
>         UnitOfWorkFactory uowf;
>
>         public Lead create(String name, Address address) {
>             UnitOfWork uow = uowf.currentUnitOfWork();
>             EntityBuilder<Lead> builder = uow.newEntityBuilder(Lead.class);
>             Lead.LeadState state =
> builder.instanceFor(Lead.LeadState.class);
>             state.name().set(name);
>             state.address().set((AddressValue)address);
>             state.isActive().set(true);
>             return builder.newInstance();
>         }
>     }
> }
>
> Lead properties isActive and name are persisted but address not.
>
> Jacek
>
>
>
>
> _______________________________________________
> 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