You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Anthony <ha...@gmail.com> on 2020/04/13 16:11:31 UTC

Automatically generate Code using java reflection

Hello,
If I have the following java class:

public class Person implements Serializable {
    /** */
    private static final AtomicLong ID_GEN = new AtomicLong();

    /** Person ID (indexed). */
    @QuerySqlField(index = true)
    public Long id;

    /** Organization ID (indexed). */
    @QuerySqlField(index = true)
    public Long orgId;

    /** First name (not-indexed). */
    @QuerySqlField
    public String firstName;

    /** Last name (not indexed). */
    @QuerySqlField
    public String lastName;

    /** Resume text (create LUCENE-based TEXT index for this field). */
    @QueryTextField
    public String resume;

    /** Salary (indexed). */
    @QuerySqlField(index = true)
    public double salary;

    /** Custom cache key to guarantee that person is always collocated with
its organization. */
    private transient AffinityKey<Long> key;


   And I want to create a table, I need to write  the following code in
java or put them in the config file. Is it possible to generate them
automatically? As Java reflection seems can handle this?

CacheConfiguration cacheCfg = new CacheConfiguration("Person");
QueryEntity entity = new QueryEntity();
entity.setKeyType("java.lang.Long");
entity.setValueType("Person");
LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
map.put("orgId", "java.lang.Long");
map.put("firstName", "java.lang.String");
map.put("lastName", "java.lang.String");
map.put("Resume", "java.lang.String");
map.put("Salary", "java.lang.double");
entity.setFields(map);
entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
List<QueryEntity> queryEntities = new ArrayList<>();
queryEntities.add(entity);
cacheCfg.setQueryEntities(queryEntities);
igniteConfiguration.setCacheConfiguration(cacheCfg);
Ignite ignite = Ignition.start(igniteConfiguration);
IgniteCache cache = ignite.getOrCreateCache("Person");

Re: Automatically generate Code using java reflection

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

This code is unrelated to your issue. It is needed for platform
interoperability.

Regards,
-- 
Ilya Kasnacheev


вт, 14 апр. 2020 г. в 19:13, Anthony <ha...@gmail.com>:

> Evgenii,
> It also came to me if there is a similar code in C++ for the following
> java code as I did not find it. If not, Does it mean I need to configure it
> in xml file?
>
>  IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
>         BinaryConfiguration bCfg = new BinaryConfiguration();
>         bCfg.setCompactFooter(false);
>         bCfg.setNameMapper(new BinaryBasicNameMapper(true));
>         bCfg.setIdMapper(new BinaryBasicIdMapper(true));
>
> bCfg.setClassNames(Collections.singleton("org.apache.ignite.examples.datagrid.CrossClass"));
>         igniteConfiguration.setBinaryConfiguration(bCfg);
>
> Thank you !
>
> On Mon, Apr 13, 2020 at 1:57 PM Evgenii Zhuravlev <
> e.zhuravlev.wk@gmail.com> wrote:
>
>> Anthony,
>>
>> No, I don't think so. If you plan to use it from C++, then you will need
>> to configure QueryEntity.
>>
>> Evgenii
>>
>> пн, 13 апр. 2020 г. в 13:02, Anthony <ha...@gmail.com>:
>>
>>> Thank you Evgenii ! BTW, Is there a same thing in c++ ?
>>>
>>> On Mon, Apr 13, 2020 at 9:30 AM Evgenii Zhuravlev <
>>> e.zhuravlev.wk@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> There is no need to create Query Entity if you already have
>>>> annotations. YOu can add
>>>> CacheConfiguration.setIndexedTypes(PersonKey.class, Person.class) and it
>>>> will be generated automatically based on you annotations.
>>>>
>>>> Evgenii
>>>>
>>>> пн, 13 апр. 2020 г. в 09:11, Anthony <ha...@gmail.com>:
>>>>
>>>>> Hello,
>>>>> If I have the following java class:
>>>>>
>>>>> public class Person implements Serializable {
>>>>>     /** */
>>>>>     private static final AtomicLong ID_GEN = new AtomicLong();
>>>>>
>>>>>     /** Person ID (indexed). */
>>>>>     @QuerySqlField(index = true)
>>>>>     public Long id;
>>>>>
>>>>>     /** Organization ID (indexed). */
>>>>>     @QuerySqlField(index = true)
>>>>>     public Long orgId;
>>>>>
>>>>>     /** First name (not-indexed). */
>>>>>     @QuerySqlField
>>>>>     public String firstName;
>>>>>
>>>>>     /** Last name (not indexed). */
>>>>>     @QuerySqlField
>>>>>     public String lastName;
>>>>>
>>>>>     /** Resume text (create LUCENE-based TEXT index for this field). */
>>>>>     @QueryTextField
>>>>>     public String resume;
>>>>>
>>>>>     /** Salary (indexed). */
>>>>>     @QuerySqlField(index = true)
>>>>>     public double salary;
>>>>>
>>>>>     /** Custom cache key to guarantee that person is always collocated
>>>>> with its organization. */
>>>>>     private transient AffinityKey<Long> key;
>>>>>
>>>>>
>>>>>    And I want to create a table, I need to write  the following code
>>>>> in java or put them in the config file. Is it possible to generate them
>>>>> automatically? As Java reflection seems can handle this?
>>>>>
>>>>> CacheConfiguration cacheCfg = new CacheConfiguration("Person");
>>>>> QueryEntity entity = new QueryEntity();
>>>>> entity.setKeyType("java.lang.Long");
>>>>> entity.setValueType("Person");
>>>>> LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
>>>>> map.put("orgId", "java.lang.Long");
>>>>> map.put("firstName", "java.lang.String");
>>>>> map.put("lastName", "java.lang.String");
>>>>> map.put("Resume", "java.lang.String");
>>>>> map.put("Salary", "java.lang.double");
>>>>> entity.setFields(map);
>>>>> entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
>>>>> List<QueryEntity> queryEntities = new ArrayList<>();
>>>>> queryEntities.add(entity);
>>>>> cacheCfg.setQueryEntities(queryEntities);
>>>>> igniteConfiguration.setCacheConfiguration(cacheCfg);
>>>>> Ignite ignite = Ignition.start(igniteConfiguration);
>>>>> IgniteCache cache = ignite.getOrCreateCache("Person");
>>>>>
>>>>>

Re: Automatically generate Code using java reflection

Posted by Anthony <ha...@gmail.com>.
Evgenii,
It also came to me if there is a similar code in C++ for the following java
code as I did not find it. If not, Does it mean I need to configure it in
xml file?

 IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
        BinaryConfiguration bCfg = new BinaryConfiguration();
        bCfg.setCompactFooter(false);
        bCfg.setNameMapper(new BinaryBasicNameMapper(true));
        bCfg.setIdMapper(new BinaryBasicIdMapper(true));

bCfg.setClassNames(Collections.singleton("org.apache.ignite.examples.datagrid.CrossClass"));
        igniteConfiguration.setBinaryConfiguration(bCfg);

Thank you !

On Mon, Apr 13, 2020 at 1:57 PM Evgenii Zhuravlev <e....@gmail.com>
wrote:

> Anthony,
>
> No, I don't think so. If you plan to use it from C++, then you will need
> to configure QueryEntity.
>
> Evgenii
>
> пн, 13 апр. 2020 г. в 13:02, Anthony <ha...@gmail.com>:
>
>> Thank you Evgenii ! BTW, Is there a same thing in c++ ?
>>
>> On Mon, Apr 13, 2020 at 9:30 AM Evgenii Zhuravlev <
>> e.zhuravlev.wk@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> There is no need to create Query Entity if you already have annotations.
>>> YOu can add CacheConfiguration.setIndexedTypes(PersonKey.class,
>>> Person.class) and it will be generated automatically based on you
>>> annotations.
>>>
>>> Evgenii
>>>
>>> пн, 13 апр. 2020 г. в 09:11, Anthony <ha...@gmail.com>:
>>>
>>>> Hello,
>>>> If I have the following java class:
>>>>
>>>> public class Person implements Serializable {
>>>>     /** */
>>>>     private static final AtomicLong ID_GEN = new AtomicLong();
>>>>
>>>>     /** Person ID (indexed). */
>>>>     @QuerySqlField(index = true)
>>>>     public Long id;
>>>>
>>>>     /** Organization ID (indexed). */
>>>>     @QuerySqlField(index = true)
>>>>     public Long orgId;
>>>>
>>>>     /** First name (not-indexed). */
>>>>     @QuerySqlField
>>>>     public String firstName;
>>>>
>>>>     /** Last name (not indexed). */
>>>>     @QuerySqlField
>>>>     public String lastName;
>>>>
>>>>     /** Resume text (create LUCENE-based TEXT index for this field). */
>>>>     @QueryTextField
>>>>     public String resume;
>>>>
>>>>     /** Salary (indexed). */
>>>>     @QuerySqlField(index = true)
>>>>     public double salary;
>>>>
>>>>     /** Custom cache key to guarantee that person is always collocated
>>>> with its organization. */
>>>>     private transient AffinityKey<Long> key;
>>>>
>>>>
>>>>    And I want to create a table, I need to write  the following code in
>>>> java or put them in the config file. Is it possible to generate them
>>>> automatically? As Java reflection seems can handle this?
>>>>
>>>> CacheConfiguration cacheCfg = new CacheConfiguration("Person");
>>>> QueryEntity entity = new QueryEntity();
>>>> entity.setKeyType("java.lang.Long");
>>>> entity.setValueType("Person");
>>>> LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
>>>> map.put("orgId", "java.lang.Long");
>>>> map.put("firstName", "java.lang.String");
>>>> map.put("lastName", "java.lang.String");
>>>> map.put("Resume", "java.lang.String");
>>>> map.put("Salary", "java.lang.double");
>>>> entity.setFields(map);
>>>> entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
>>>> List<QueryEntity> queryEntities = new ArrayList<>();
>>>> queryEntities.add(entity);
>>>> cacheCfg.setQueryEntities(queryEntities);
>>>> igniteConfiguration.setCacheConfiguration(cacheCfg);
>>>> Ignite ignite = Ignition.start(igniteConfiguration);
>>>> IgniteCache cache = ignite.getOrCreateCache("Person");
>>>>
>>>>

Re: Automatically generate Code using java reflection

Posted by Evgenii Zhuravlev <e....@gmail.com>.
Anthony,

No, I don't think so. If you plan to use it from C++, then you will need to
configure QueryEntity.

Evgenii

пн, 13 апр. 2020 г. в 13:02, Anthony <ha...@gmail.com>:

> Thank you Evgenii ! BTW, Is there a same thing in c++ ?
>
> On Mon, Apr 13, 2020 at 9:30 AM Evgenii Zhuravlev <
> e.zhuravlev.wk@gmail.com> wrote:
>
>> Hi,
>>
>> There is no need to create Query Entity if you already have annotations.
>> YOu can add CacheConfiguration.setIndexedTypes(PersonKey.class,
>> Person.class) and it will be generated automatically based on you
>> annotations.
>>
>> Evgenii
>>
>> пн, 13 апр. 2020 г. в 09:11, Anthony <ha...@gmail.com>:
>>
>>> Hello,
>>> If I have the following java class:
>>>
>>> public class Person implements Serializable {
>>>     /** */
>>>     private static final AtomicLong ID_GEN = new AtomicLong();
>>>
>>>     /** Person ID (indexed). */
>>>     @QuerySqlField(index = true)
>>>     public Long id;
>>>
>>>     /** Organization ID (indexed). */
>>>     @QuerySqlField(index = true)
>>>     public Long orgId;
>>>
>>>     /** First name (not-indexed). */
>>>     @QuerySqlField
>>>     public String firstName;
>>>
>>>     /** Last name (not indexed). */
>>>     @QuerySqlField
>>>     public String lastName;
>>>
>>>     /** Resume text (create LUCENE-based TEXT index for this field). */
>>>     @QueryTextField
>>>     public String resume;
>>>
>>>     /** Salary (indexed). */
>>>     @QuerySqlField(index = true)
>>>     public double salary;
>>>
>>>     /** Custom cache key to guarantee that person is always collocated
>>> with its organization. */
>>>     private transient AffinityKey<Long> key;
>>>
>>>
>>>    And I want to create a table, I need to write  the following code in
>>> java or put them in the config file. Is it possible to generate them
>>> automatically? As Java reflection seems can handle this?
>>>
>>> CacheConfiguration cacheCfg = new CacheConfiguration("Person");
>>> QueryEntity entity = new QueryEntity();
>>> entity.setKeyType("java.lang.Long");
>>> entity.setValueType("Person");
>>> LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
>>> map.put("orgId", "java.lang.Long");
>>> map.put("firstName", "java.lang.String");
>>> map.put("lastName", "java.lang.String");
>>> map.put("Resume", "java.lang.String");
>>> map.put("Salary", "java.lang.double");
>>> entity.setFields(map);
>>> entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
>>> List<QueryEntity> queryEntities = new ArrayList<>();
>>> queryEntities.add(entity);
>>> cacheCfg.setQueryEntities(queryEntities);
>>> igniteConfiguration.setCacheConfiguration(cacheCfg);
>>> Ignite ignite = Ignition.start(igniteConfiguration);
>>> IgniteCache cache = ignite.getOrCreateCache("Person");
>>>
>>>

Re: Automatically generate Code using java reflection

Posted by Anthony <ha...@gmail.com>.
Thank you Evgenii ! BTW, Is there a same thing in c++ ?

On Mon, Apr 13, 2020 at 9:30 AM Evgenii Zhuravlev <e....@gmail.com>
wrote:

> Hi,
>
> There is no need to create Query Entity if you already have annotations.
> YOu can add CacheConfiguration.setIndexedTypes(PersonKey.class,
> Person.class) and it will be generated automatically based on you
> annotations.
>
> Evgenii
>
> пн, 13 апр. 2020 г. в 09:11, Anthony <ha...@gmail.com>:
>
>> Hello,
>> If I have the following java class:
>>
>> public class Person implements Serializable {
>>     /** */
>>     private static final AtomicLong ID_GEN = new AtomicLong();
>>
>>     /** Person ID (indexed). */
>>     @QuerySqlField(index = true)
>>     public Long id;
>>
>>     /** Organization ID (indexed). */
>>     @QuerySqlField(index = true)
>>     public Long orgId;
>>
>>     /** First name (not-indexed). */
>>     @QuerySqlField
>>     public String firstName;
>>
>>     /** Last name (not indexed). */
>>     @QuerySqlField
>>     public String lastName;
>>
>>     /** Resume text (create LUCENE-based TEXT index for this field). */
>>     @QueryTextField
>>     public String resume;
>>
>>     /** Salary (indexed). */
>>     @QuerySqlField(index = true)
>>     public double salary;
>>
>>     /** Custom cache key to guarantee that person is always collocated
>> with its organization. */
>>     private transient AffinityKey<Long> key;
>>
>>
>>    And I want to create a table, I need to write  the following code in
>> java or put them in the config file. Is it possible to generate them
>> automatically? As Java reflection seems can handle this?
>>
>> CacheConfiguration cacheCfg = new CacheConfiguration("Person");
>> QueryEntity entity = new QueryEntity();
>> entity.setKeyType("java.lang.Long");
>> entity.setValueType("Person");
>> LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
>> map.put("orgId", "java.lang.Long");
>> map.put("firstName", "java.lang.String");
>> map.put("lastName", "java.lang.String");
>> map.put("Resume", "java.lang.String");
>> map.put("Salary", "java.lang.double");
>> entity.setFields(map);
>> entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
>> List<QueryEntity> queryEntities = new ArrayList<>();
>> queryEntities.add(entity);
>> cacheCfg.setQueryEntities(queryEntities);
>> igniteConfiguration.setCacheConfiguration(cacheCfg);
>> Ignite ignite = Ignition.start(igniteConfiguration);
>> IgniteCache cache = ignite.getOrCreateCache("Person");
>>
>>

Re: Automatically generate Code using java reflection

Posted by Evgenii Zhuravlev <e....@gmail.com>.
Hi,

There is no need to create Query Entity if you already have annotations.
YOu can add CacheConfiguration.setIndexedTypes(PersonKey.class,
Person.class) and it will be generated automatically based on you
annotations.

Evgenii

пн, 13 апр. 2020 г. в 09:11, Anthony <ha...@gmail.com>:

> Hello,
> If I have the following java class:
>
> public class Person implements Serializable {
>     /** */
>     private static final AtomicLong ID_GEN = new AtomicLong();
>
>     /** Person ID (indexed). */
>     @QuerySqlField(index = true)
>     public Long id;
>
>     /** Organization ID (indexed). */
>     @QuerySqlField(index = true)
>     public Long orgId;
>
>     /** First name (not-indexed). */
>     @QuerySqlField
>     public String firstName;
>
>     /** Last name (not indexed). */
>     @QuerySqlField
>     public String lastName;
>
>     /** Resume text (create LUCENE-based TEXT index for this field). */
>     @QueryTextField
>     public String resume;
>
>     /** Salary (indexed). */
>     @QuerySqlField(index = true)
>     public double salary;
>
>     /** Custom cache key to guarantee that person is always collocated
> with its organization. */
>     private transient AffinityKey<Long> key;
>
>
>    And I want to create a table, I need to write  the following code in
> java or put them in the config file. Is it possible to generate them
> automatically? As Java reflection seems can handle this?
>
> CacheConfiguration cacheCfg = new CacheConfiguration("Person");
> QueryEntity entity = new QueryEntity();
> entity.setKeyType("java.lang.Long");
> entity.setValueType("Person");
> LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
> map.put("orgId", "java.lang.Long");
> map.put("firstName", "java.lang.String");
> map.put("lastName", "java.lang.String");
> map.put("Resume", "java.lang.String");
> map.put("Salary", "java.lang.double");
> entity.setFields(map);
> entity.setIndexes(Collections.singletonList(new QueryIndex("orgId")));
> List<QueryEntity> queryEntities = new ArrayList<>();
> queryEntities.add(entity);
> cacheCfg.setQueryEntities(queryEntities);
> igniteConfiguration.setCacheConfiguration(cacheCfg);
> Ignite ignite = Ignition.start(igniteConfiguration);
> IgniteCache cache = ignite.getOrCreateCache("Person");
>
>