You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@polygene.apache.org by Apostolos Krionidis <al...@yahoo.gr.INVALID> on 2017/05/03 10:08:51 UTC

MongoDB Entity Store

Hello I' m Apostolis
I'm working with Qi4j a couple of years and recently I tried to connect with MongoDb Entity Store.
Everything was fine and I successfully insert entities in Mongo when I configure the .property file with hostname and port.

The problem came when I tried to configure in the .property file the nodes property. 
So when I use the nodes property I get back the following error:"Could not find any visible ValueComposite of type [com.mongodb.ServerAddress] in module [config]"
How can I add more nodes in MongoEntityStore.
My current version is 2.1
Thank you very muchApostolis


Re: MongoDB Entity Store

Posted by Niclas Hedhman <ni...@hedhman.org>.
Actually, it is probably one level too much of generics in "extends
ConcernOf". Try to remove the inner MongoEntityStoreConfiguration and cast
the next.get()

It is the most obvious thing from those days (should actually check that in
3.0 as well).

On Sat, May 6, 2017 at 12:02 AM, Niclas Hedhman <ni...@hedhman.org> wrote:

> I need to look at that tomorrow, especially since this is 2.1 and a fair
> amount has changed from 2.1 to 3.0 in type management.
>
> On Fri, May 5, 2017 at 10:14 PM, Apostolos Krionidis <al...@yahoo.gr>
> wrote:
>
>> Hi,
>>
>> I've created a new class:
>>
>> public class CustomMongoMapEntityStoreAssembler extends Assemblers.VisibilityIdentityConfig<CustomMongoMapEntityStoreAssembler>
>> {
>>    @Override
>>    public void assemble(ModuleAssembly module) throws AssemblyException
>>    {
>>       module.services(UuidIdentityGeneratorService.class)
>>             .visibleIn(visibility());
>>
>>       ServiceDeclaration service =
>>          module.services(MongoMapEntityStoreService.class)
>>                .withConcerns(MongoEntityStoreConfigurationConcern.class)
>>                .visibleIn(visibility());
>>
>>       if (hasIdentity()) {
>>
>>          service.identifiedBy(identity());
>>       }
>>       if (hasConfig()) {
>>
>>          configModule().entities(MongoEntityStoreConfiguration.class)
>>                        .visibleIn(configVisibility());
>>       }
>>    }
>> }
>>
>>
>> and then a concern as you suggest:
>>
>> public abstract class MongoEntityStoreConfigurationConcern
>>    extends ConcernOf<Configuration<MongoEntityStoreConfiguration>>
>>    implements Configuration<MongoEntityStoreConfiguration>
>> {
>>    @Override
>>    public MongoEntityStoreConfiguration get()
>>    {
>>       try {
>>          MongoEntityStoreConfiguration conf = next.get();
>>
>>          List<ServerAddress> serverAddresses = new ArrayList<>();
>>
>>          serverAddresses.add(new ServerAddress("1.1.1.5", 27017));
>>          serverAddresses.add(new ServerAddress("1.1.1.6", 27017));
>>          serverAddresses.add(new ServerAddress("1.1.1.7", 27017));
>>
>>          conf.nodes()
>>              .set(serverAddresses);
>>
>>          return conf;
>>       }
>>       catch (UnknownHostException err) {
>>          throw new RuntimeException(err);
>>       }
>>    }
>> }
>>
>> and I called it as:
>>
>> new
>>    CustomMongoMapEntityStoreAssembler().withConfig(configModule, Visibility.application)
>>                                         .visibleIn(Visibility.application)
>>                                         .identifiedBy("mongodb.booking.store")
>>                                         .assemble(module);
>>
>>
>> But then I get back the following error:
>>
>>
>> org.qi4j.bootstrap.AssemblyException: Unable to create Application Model.
>> 	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:76)
>> 	at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:83)
>> 	at com.projectbeagle.gateway.kernel.scope.wiring.ApplicationPool.fillUp(ApplicationPool.java:74)
>> 	... 47 more
>> Caused by: org.qi4j.api.common.InvalidApplicationException: Could not register [interface org.qi4j.entitystore.mongodb.MongoMapEntityStoreService]
>> 	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:74)
>> 	at org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:544)
>> 	at org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl.newApplicationModel(ApplicationModelFactoryImpl.java:86)
>> 	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:72)
>> 	... 49 more
>> Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
>> 	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:132)
>> 	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:119)
>> 	at org.qi4j.runtime.injection.DependencyModel.<init>(DependencyModel.java:96)
>> 	at org.qi4j.runtime.injection.InjectedFieldsModel.addModel(InjectedFieldsModel.java:81)
>> 	at org.qi4j.runtime.injection.InjectedFieldsModel.<init>(InjectedFieldsModel.java:56)
>> 	at org.qi4j.runtime.composite.AbstractModifierModel.<init>(AbstractModifierModel.java:57)
>> 	at org.qi4j.runtime.composite.ConcernModel.<init>(ConcernModel.java:27)
>> 	at org.qi4j.runtime.bootstrap.AssemblyHelper.getConcernModel(AssemblyHelper.java:52)
>> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.concernsFor(CompositeAssemblyImpl.java:591)
>> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMixinType(CompositeAssemblyImpl.java:215)
>> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.buildComposite(CompositeAssemblyImpl.java:181)
>> 	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:64)
>> 	... 52 more
>>
>>
>>
>> Στις 3:29 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
>> niclas@hedhman.org> έγραψε:
>>
>>
>> Yes, the registration of values(ServerAddress.class) should not be there.
>> That was an oversight on my behalf.
>>
>> A few things that could be a work-around.
>>
>> 1. Create a Concern that intercepts the configuration and populates the
>> nodes. You add the Concern in your own Assembler (copy source from
>> MongoDbEntityStoreAssembler), so instead of;
>>
>> ServiceDeclaration service = module
>>         .services( MongoMapEntityStoreService.class )
>>         .visibleIn( visibility() );
>>
>> add the Concern as;
>>
>> ServiceDeclaration service = module
>>         .services( MongoMapEntityStoreService.class )
>>         .withConcerns( MyConfigurationConcern.class )
>>         .visibleIn( visibility() );
>>
>>
>> Then your MyConfigurationConcern would be something like;
>>
>> public abstract class MyConfigurationConcern extends
>> ConcernOf<Configuration<MongoEntityStoreConfiguration>>
>>     implements Configuration<MongoEntityStoreConfiguration>
>> {
>>     @Override
>>     public MongoEntityStoreConfiguration get()
>>     {
>>         MongoEntityStoreConfiguration conf = next.get();
>>         conf.nodes().set( MY_NODES );
>>         return conf;
>>     }
>> }
>>
>>
>> 2. Maybe you want your own Configuration store. Create (or use) an Entity
>> Store that does not require any Polygene Configuration, and drop that into
>> the Configuration Module. Perhaps read configuration from "Java
>> Preferences", maybe a configured Zookeeper cluster or maybe ETCD. And if
>> the configuration entity store is populated, then there will be no
>> fallback
>> to properties/yaml files.
>> This is of course a fairly advanced option, but I would recommend it for
>> production setup.
>>
>>
>> But I am sure Paul will say; "Just ..."  :-)
>>
>> Cheers
>> Niclas
>>
>> On Fri, May 5, 2017 at 7:55 PM, Apostolos Krionidis <al...@yahoo.gr>
>> wrote:
>>
>> > Yes you are right ServerAddress is a Immutable POJO but here the problem
>> > seems to by before
>> > json serialization, in ValueComposite registration.
>> >
>> > Is there any other way to set prices in the nodes() property after the
>> > .property file loading?
>> >
>> >
>> >
>> >
>> > Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
>> > niclas@hedhman.org> έγραψε:
>> >
>> >
>> > Of course... ServerAddress is a pojo, and it doesn't have a POJO
>> > compatible format for Jackson et al.
>> >
>> > Paul, how was this supposed to work?
>> >
>> > Cheers
>> >
>> >
>> > --
>> > Niclas Hedhman, Software Developer
>> > http://polygene.apache.org - New Energy for Java
>>
>> >
>> >
>> >
>>
>>
>> --
>> Niclas Hedhman, Software Developer
>> http://polygene.apache.org - New Energy for Java
>>
>>
>>
>
>
> --
> Niclas Hedhman, Software Developer
> http://polygene.apache.org - New Energy for Java
>



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

Re: MongoDB Entity Store

Posted by Niclas Hedhman <ni...@hedhman.org>.
I need to look at that tomorrow, especially since this is 2.1 and a fair
amount has changed from 2.1 to 3.0 in type management.

On Fri, May 5, 2017 at 10:14 PM, Apostolos Krionidis <al...@yahoo.gr>
wrote:

> Hi,
>
> I've created a new class:
>
> public class CustomMongoMapEntityStoreAssembler extends Assemblers.VisibilityIdentityConfig<CustomMongoMapEntityStoreAssembler>
> {
>    @Override
>    public void assemble(ModuleAssembly module) throws AssemblyException
>    {
>       module.services(UuidIdentityGeneratorService.class)
>             .visibleIn(visibility());
>
>       ServiceDeclaration service =
>          module.services(MongoMapEntityStoreService.class)
>                .withConcerns(MongoEntityStoreConfigurationConcern.class)
>                .visibleIn(visibility());
>
>       if (hasIdentity()) {
>
>          service.identifiedBy(identity());
>       }
>       if (hasConfig()) {
>
>          configModule().entities(MongoEntityStoreConfiguration.class)
>                        .visibleIn(configVisibility());
>       }
>    }
> }
>
>
> and then a concern as you suggest:
>
> public abstract class MongoEntityStoreConfigurationConcern
>    extends ConcernOf<Configuration<MongoEntityStoreConfiguration>>
>    implements Configuration<MongoEntityStoreConfiguration>
> {
>    @Override
>    public MongoEntityStoreConfiguration get()
>    {
>       try {
>          MongoEntityStoreConfiguration conf = next.get();
>
>          List<ServerAddress> serverAddresses = new ArrayList<>();
>
>          serverAddresses.add(new ServerAddress("1.1.1.5", 27017));
>          serverAddresses.add(new ServerAddress("1.1.1.6", 27017));
>          serverAddresses.add(new ServerAddress("1.1.1.7", 27017));
>
>          conf.nodes()
>              .set(serverAddresses);
>
>          return conf;
>       }
>       catch (UnknownHostException err) {
>          throw new RuntimeException(err);
>       }
>    }
> }
>
> and I called it as:
>
> new
>    CustomMongoMapEntityStoreAssembler().withConfig(configModule, Visibility.application)
>                                         .visibleIn(Visibility.application)
>                                         .identifiedBy("mongodb.booking.store")
>                                         .assemble(module);
>
>
> But then I get back the following error:
>
>
> org.qi4j.bootstrap.AssemblyException: Unable to create Application Model.
> 	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:76)
> 	at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:83)
> 	at com.projectbeagle.gateway.kernel.scope.wiring.ApplicationPool.fillUp(ApplicationPool.java:74)
> 	... 47 more
> Caused by: org.qi4j.api.common.InvalidApplicationException: Could not register [interface org.qi4j.entitystore.mongodb.MongoMapEntityStoreService]
> 	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:74)
> 	at org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:544)
> 	at org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl.newApplicationModel(ApplicationModelFactoryImpl.java:86)
> 	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:72)
> 	... 49 more
> Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
> 	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:132)
> 	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:119)
> 	at org.qi4j.runtime.injection.DependencyModel.<init>(DependencyModel.java:96)
> 	at org.qi4j.runtime.injection.InjectedFieldsModel.addModel(InjectedFieldsModel.java:81)
> 	at org.qi4j.runtime.injection.InjectedFieldsModel.<init>(InjectedFieldsModel.java:56)
> 	at org.qi4j.runtime.composite.AbstractModifierModel.<init>(AbstractModifierModel.java:57)
> 	at org.qi4j.runtime.composite.ConcernModel.<init>(ConcernModel.java:27)
> 	at org.qi4j.runtime.bootstrap.AssemblyHelper.getConcernModel(AssemblyHelper.java:52)
> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.concernsFor(CompositeAssemblyImpl.java:591)
> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMixinType(CompositeAssemblyImpl.java:215)
> 	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.buildComposite(CompositeAssemblyImpl.java:181)
> 	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:64)
> 	... 52 more
>
>
>
> Στις 3:29 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
> niclas@hedhman.org> έγραψε:
>
>
> Yes, the registration of values(ServerAddress.class) should not be there.
> That was an oversight on my behalf.
>
> A few things that could be a work-around.
>
> 1. Create a Concern that intercepts the configuration and populates the
> nodes. You add the Concern in your own Assembler (copy source from
> MongoDbEntityStoreAssembler), so instead of;
>
> ServiceDeclaration service = module
>         .services( MongoMapEntityStoreService.class )
>         .visibleIn( visibility() );
>
> add the Concern as;
>
> ServiceDeclaration service = module
>         .services( MongoMapEntityStoreService.class )
>         .withConcerns( MyConfigurationConcern.class )
>         .visibleIn( visibility() );
>
>
> Then your MyConfigurationConcern would be something like;
>
> public abstract class MyConfigurationConcern extends
> ConcernOf<Configuration<MongoEntityStoreConfiguration>>
>     implements Configuration<MongoEntityStoreConfiguration>
> {
>     @Override
>     public MongoEntityStoreConfiguration get()
>     {
>         MongoEntityStoreConfiguration conf = next.get();
>         conf.nodes().set( MY_NODES );
>         return conf;
>     }
> }
>
>
> 2. Maybe you want your own Configuration store. Create (or use) an Entity
> Store that does not require any Polygene Configuration, and drop that into
> the Configuration Module. Perhaps read configuration from "Java
> Preferences", maybe a configured Zookeeper cluster or maybe ETCD. And if
> the configuration entity store is populated, then there will be no fallback
> to properties/yaml files.
> This is of course a fairly advanced option, but I would recommend it for
> production setup.
>
>
> But I am sure Paul will say; "Just ..."  :-)
>
> Cheers
> Niclas
>
> On Fri, May 5, 2017 at 7:55 PM, Apostolos Krionidis <al...@yahoo.gr>
> wrote:
>
> > Yes you are right ServerAddress is a Immutable POJO but here the problem
> > seems to by before
> > json serialization, in ValueComposite registration.
> >
> > Is there any other way to set prices in the nodes() property after the
> > .property file loading?
> >
> >
> >
> >
> > Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
> > niclas@hedhman.org> έγραψε:
> >
> >
> > Of course... ServerAddress is a pojo, and it doesn't have a POJO
> > compatible format for Jackson et al.
> >
> > Paul, how was this supposed to work?
> >
> > Cheers
> >
> >
> > --
> > Niclas Hedhman, Software Developer
> > http://polygene.apache.org - New Energy for Java
>
> >
> >
> >
>
>
> --
> Niclas Hedhman, Software Developer
> http://polygene.apache.org - New Energy for Java
>
>
>


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

Σχετ: MongoDB Entity Store

Posted by Apostolos Krionidis <al...@yahoo.gr.INVALID>.
Hi,
I've created a new class:

public class CustomMongoMapEntityStoreAssembler extends Assemblers.VisibilityIdentityConfig<CustomMongoMapEntityStoreAssembler>
{
   @Override
   public void assemble(ModuleAssembly module) throws AssemblyException
   {
      module.services(UuidIdentityGeneratorService.class)
            .visibleIn(visibility());

      ServiceDeclaration service =
         module.services(MongoMapEntityStoreService.class)
               .withConcerns(MongoEntityStoreConfigurationConcern.class)
               .visibleIn(visibility());

      if (hasIdentity()) {

         service.identifiedBy(identity());
      }
      if (hasConfig()) {

         configModule().entities(MongoEntityStoreConfiguration.class)
                       .visibleIn(configVisibility());
      }
   }
}


and then a concern as you suggest:

public abstract class MongoEntityStoreConfigurationConcern
   extends ConcernOf<Configuration<MongoEntityStoreConfiguration>>
   implements Configuration<MongoEntityStoreConfiguration>
{
   @Override
   public MongoEntityStoreConfiguration get()
   {
      try {
         MongoEntityStoreConfiguration conf = next.get();

         List<ServerAddress> serverAddresses = new ArrayList<>();

         serverAddresses.add(new ServerAddress("1.1.1.5", 27017));
         serverAddresses.add(new ServerAddress("1.1.1.6", 27017));
         serverAddresses.add(new ServerAddress("1.1.1.7", 27017));

         conf.nodes()
             .set(serverAddresses);

         return conf;
      }
      catch (UnknownHostException err) {
         throw new RuntimeException(err);
      }
   }
}

and I called it as:

new
   CustomMongoMapEntityStoreAssembler().withConfig(configModule, Visibility.application)
                                        .visibleIn(Visibility.application)
                                        .identifiedBy("mongodb.booking.store")
                                        .assemble(module);


But then I get back the following error:


org.qi4j.bootstrap.AssemblyException: Unable to create Application Model.
	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:76)
	at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:83)
	at com.projectbeagle.gateway.kernel.scope.wiring.ApplicationPool.fillUp(ApplicationPool.java:74)
	... 47 more
Caused by: org.qi4j.api.common.InvalidApplicationException: Could not register [interface org.qi4j.entitystore.mongodb.MongoMapEntityStoreService]
	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:74)
	at org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:544)
	at org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl.newApplicationModel(ApplicationModelFactoryImpl.java:86)
	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:72)
	... 49 more
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:132)
	at org.qi4j.runtime.injection.DependencyModel.extractRawInjectionClass(DependencyModel.java:119)
	at org.qi4j.runtime.injection.DependencyModel.<init>(DependencyModel.java:96)
	at org.qi4j.runtime.injection.InjectedFieldsModel.addModel(InjectedFieldsModel.java:81)
	at org.qi4j.runtime.injection.InjectedFieldsModel.<init>(InjectedFieldsModel.java:56)
	at org.qi4j.runtime.composite.AbstractModifierModel.<init>(AbstractModifierModel.java:57)
	at org.qi4j.runtime.composite.ConcernModel.<init>(ConcernModel.java:27)
	at org.qi4j.runtime.bootstrap.AssemblyHelper.getConcernModel(AssemblyHelper.java:52)
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.concernsFor(CompositeAssemblyImpl.java:591)
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMixinType(CompositeAssemblyImpl.java:215)
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.buildComposite(CompositeAssemblyImpl.java:181)
	at org.qi4j.runtime.bootstrap.ServiceAssemblyImpl.newServiceModel(ServiceAssemblyImpl.java:64)
	... 52 more

 

    Στις 3:29 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <ni...@hedhman.org> έγραψε:
 

 Yes, the registration of values(ServerAddress.class) should not be there.
That was an oversight on my behalf.

A few things that could be a work-around.

1. Create a Concern that intercepts the configuration and populates the
nodes. You add the Concern in your own Assembler (copy source from
MongoDbEntityStoreAssembler), so instead of;

ServiceDeclaration service = module
        .services( MongoMapEntityStoreService.class )
        .visibleIn( visibility() );

add the Concern as;

ServiceDeclaration service = module
        .services( MongoMapEntityStoreService.class )
        .withConcerns( MyConfigurationConcern.class )
        .visibleIn( visibility() );


Then your MyConfigurationConcern would be something like;

public abstract class MyConfigurationConcern extends
ConcernOf<Configuration<MongoEntityStoreConfiguration>>
    implements Configuration<MongoEntityStoreConfiguration>
{
    @Override
    public MongoEntityStoreConfiguration get()
    {
        MongoEntityStoreConfiguration conf = next.get();
        conf.nodes().set( MY_NODES );
        return conf;
    }
}


2. Maybe you want your own Configuration store. Create (or use) an Entity
Store that does not require any Polygene Configuration, and drop that into
the Configuration Module. Perhaps read configuration from "Java
Preferences", maybe a configured Zookeeper cluster or maybe ETCD. And if
the configuration entity store is populated, then there will be no fallback
to properties/yaml files.
This is of course a fairly advanced option, but I would recommend it for
production setup.


But I am sure Paul will say; "Just ..."  :-)

Cheers
Niclas

On Fri, May 5, 2017 at 7:55 PM, Apostolos Krionidis <al...@yahoo.gr>
wrote:

> Yes you are right ServerAddress is a Immutable POJO but here the problem
> seems to by before
> json serialization, in ValueComposite registration.
>
> Is there any other way to set prices in the nodes() property after the
> .property file loading?
>
>
>
>
> Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
> niclas@hedhman.org> έγραψε:
>
>
> Of course... ServerAddress is a pojo, and it doesn't have a POJO
> compatible format for Jackson et al.
>
> Paul, how was this supposed to work?
>
> Cheers
>
>
> --
> Niclas Hedhman, Software Developer
> http://polygene.apache.org - New Energy for Java
>
>
>


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

   

Re: MongoDB Entity Store

Posted by Niclas Hedhman <ni...@hedhman.org>.
Yes, the registration of values(ServerAddress.class) should not be there.
That was an oversight on my behalf.

A few things that could be a work-around.

1. Create a Concern that intercepts the configuration and populates the
nodes. You add the Concern in your own Assembler (copy source from
MongoDbEntityStoreAssembler), so instead of;

ServiceDeclaration service = module
        .services( MongoMapEntityStoreService.class )
        .visibleIn( visibility() );

add the Concern as;

ServiceDeclaration service = module
        .services( MongoMapEntityStoreService.class )
        .withConcerns( MyConfigurationConcern.class )
        .visibleIn( visibility() );


Then your MyConfigurationConcern would be something like;

public abstract class MyConfigurationConcern extends
ConcernOf<Configuration<MongoEntityStoreConfiguration>>
    implements Configuration<MongoEntityStoreConfiguration>
{
    @Override
    public MongoEntityStoreConfiguration get()
    {
        MongoEntityStoreConfiguration conf = next.get();
        conf.nodes().set( MY_NODES );
        return conf;
    }
}


2. Maybe you want your own Configuration store. Create (or use) an Entity
Store that does not require any Polygene Configuration, and drop that into
the Configuration Module. Perhaps read configuration from "Java
Preferences", maybe a configured Zookeeper cluster or maybe ETCD. And if
the configuration entity store is populated, then there will be no fallback
to properties/yaml files.
This is of course a fairly advanced option, but I would recommend it for
production setup.


But I am sure Paul will say; "Just ..."  :-)

Cheers
Niclas

On Fri, May 5, 2017 at 7:55 PM, Apostolos Krionidis <al...@yahoo.gr>
wrote:

> Yes you are right ServerAddress is a Immutable POJO but here the problem
> seems to by before
> json serialization, in ValueComposite registration.
>
> Is there any other way to set prices in the nodes() property after the
> .property file loading?
>
>
>
>
> Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <
> niclas@hedhman.org> έγραψε:
>
>
> Of course... ServerAddress is a pojo, and it doesn't have a POJO
> compatible format for Jackson et al.
>
> Paul, how was this supposed to work?
>
> Cheers
>
>
> --
> Niclas Hedhman, Software Developer
> http://polygene.apache.org - New Energy for Java
>
>
>


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

Σχετ: MongoDB Entity Store

Posted by Apostolos Krionidis <al...@yahoo.gr.INVALID>.
 Yes you are right ServerAddress is a Immutable POJO but here the problem seems to by before 
json serialization, in ValueComposite registration. 
Is there any other way to set prices in the nodes() property after the .property file loading?




    Στις 2:44 μ.μ. Παρασκευή, 5 Μαΐου 2017, ο/η Niclas Hedhman <ni...@hedhman.org> έγραψε:
 

 Of course... ServerAddress is a pojo, and it doesn't have a POJO compatible format for Jackson et al.
Paul, how was this supposed to work?
Cheers


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

   

Σχετ: MongoDB Entity Store

Posted by Apostolos Krionidis <al...@yahoo.gr.INVALID>.
Hi, 

I've just make the changes that you propose
configModule.values(ServerAddress.class);

new
   MongoMapEntityStoreAssembler().withConfig(configModule, Visibility.application)
                                  .visibleIn(Visibility.application)
                                  .identifiedBy("mongodb.booking.store")
                                  .assemble(module);


I also changed the .properties file.

But now I get back the following exception:



org.qi4j.bootstrap.AssemblyException: Unable to create Application Model.
	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:76)
	at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:83)
	at com.projectbeagle.gateway.kernel.scope.wiring.ApplicationPool.fillUp(ApplicationPool.java:74)
	... 47 more
Caused by: org.qi4j.api.common.InvalidApplicationException: Could not register [class com.mongodb.ServerAddress, interface org.qi4j.api.value.ValueComposite]
	at org.qi4j.runtime.bootstrap.ValueAssemblyImpl.newValueModel(ValueAssemblyImpl.java:105)
	at org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:519)
	at org.qi4j.runtime.bootstrap.ApplicationModelFactoryImpl.newApplicationModel(ApplicationModelFactoryImpl.java:86)
	at org.qi4j.bootstrap.Energy4Java.newApplicationModel(Energy4Java.java:72)
	... 49 more
Caused by: org.qi4j.api.composite.InvalidCompositeException: No implementation found for method 
    public boolean com.mongodb.ServerAddress.sameHost(java.lang.String)
in
    [class com.mongodb.ServerAddress, interface org.qi4j.api.value.ValueComposite]
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMethod(CompositeAssemblyImpl.java:307)
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.implementMixinType(CompositeAssemblyImpl.java:214)
	at org.qi4j.runtime.bootstrap.CompositeAssemblyImpl.buildComposite(CompositeAssemblyImpl.java:181)
	at org.qi4j.runtime.bootstrap.ValueAssemblyImpl.newValueModel(ValueAssemblyImpl.java:96)
	... 52 more




Any suggestions? 

Regards,
Apostolis
 

    Στις 3:24 μ.μ. Τετάρτη, 3 Μαΐου 2017, ο/η Niclas Hedhman <ni...@hedhman.org> έγραψε:
 

 Greetings,Are you on Qi4j 2.1 ?
If I remember correctly, firstly you need to declare the ServerAddress as a value composite in the configuration module of MongoDbEntityStore and secondly you need to use JSON in the bootstrap configuration. I think (and Paul can probably correct me if I am wrong) that you can either use .json file instead of .properties file, or have a JSON object for the nodes properties.
HOWEVER, the ServerAddress doesn't have setters, and I am not sure if Jackson will deserialize that anyway.
But in principle this should work...

nodes=[ { "host":"n1.acme.com"}, { "host":"n2.acme.com"}, { "host":"n3.acme.com"}, { "host":"n4.acme.com"} ]

I would be delighted to hear if it does or not, as this would affect 3.0 release as well.
CheerNiclas

On Wed, May 3, 2017 at 6:08 PM, Apostolos Krionidis <al...@yahoo.gr.invalid> wrote:

Hello I' m Apostolis
I'm working with Qi4j a couple of years and recently I tried to connect with MongoDb Entity Store.
Everything was fine and I successfully insert entities in Mongo when I configure the .property file with hostname and port.

The problem came when I tried to configure in the .property file the nodes property.
So when I use the nodes property I get back the following error:"Could not find any visible ValueComposite of type [com.mongodb.ServerAddress] in module [config]"
How can I add more nodes in MongoEntityStore.
My current version is 2.1
Thank you very muchApostolis





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

   

Re: MongoDB Entity Store

Posted by Niclas Hedhman <ni...@hedhman.org>.
Greetings,
Are you on Qi4j 2.1 ?

If I remember correctly, firstly you need to declare the ServerAddress as a
value composite in the configuration module of MongoDbEntityStore and
secondly you need to use JSON in the bootstrap configuration. I think (and
Paul can probably correct me if I am wrong) that you can either use .json
file instead of .properties file, or have a JSON object for the nodes
properties.

HOWEVER, the ServerAddress doesn't have setters, and I am not sure if
Jackson will deserialize that anyway.

But in principle this should work...

nodes=[ { "host":"n1.acme.com"}, { "host":"n2.acme.com"}, { "host":"
n3.acme.com"}, { "host":"n4.acme.com"} ]


I would be delighted to hear if it does or not, as this would affect 3.0
release as well.

Cheer
Niclas


On Wed, May 3, 2017 at 6:08 PM, Apostolos Krionidis <
aldrigmej@yahoo.gr.invalid> wrote:

> Hello I' m Apostolis
> I'm working with Qi4j a couple of years and recently I tried to connect
> with MongoDb Entity Store.
> Everything was fine and I successfully insert entities in Mongo when I
> configure the .property file with hostname and port.
>
> The problem came when I tried to configure in the .property file the nodes
> property.
> So when I use the nodes property I get back the following error:"Could not
> find any visible ValueComposite of type [com.mongodb.ServerAddress] in
> module [config]"
> How can I add more nodes in MongoEntityStore.
> My current version is 2.1
> Thank you very muchApostolis
>
>


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