How can I create multicolumn index for Active Objects entity?

Volodymyr Pasechnyk March 27, 2013

I have an entity with 4 fields, for example:

@Preload
interface SomeEntity extends Entity {
    @NotNull
    String getProperty1();
    void setPropery1(String value);
    @NotNull
    String getProperty2();
    void setPropery2(String value);
    @NotNull
    String getProperty3();
    void setPropery3(String value);
    @NotNull
    String getProperty4();
    void setPropery4(String value);
}

And I know, that users will mostly query for entity using first 3 fields with a query like:

Query.select().where("property1 = ? AND property2 = ? AND property3 = ?",
        property1, property2, property3);

If I add @Index annotation to all fields, it will create 4 idexes for each of field, and this will be not effective for query. Is there any way to create multicolumn index in Active Objects?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
resah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2013

Hi,

as far as I know this is not possible with AO at the moment: https://ecosystem.atlassian.net/browse/AO-96.

The capabilities of the library are still quite limited.

Regards

Theresa

Volodymyr Pasechnyk April 2, 2013

This issue does not exist.
Anyway, are there any chances, that if I create this index manually, AO will not delete it?

resah
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2013

Sry, the URL was with a dot behind it, so it didn't work, this one exists:

https://ecosystem.atlassian.net/browse/AO-96

I am actually curious too if manually creating an index on AO tables would work. Add the AO logger: net.java.ao.sql and check what AO actually does on plugin deployment or when starting/stoping an instance.

I am not sure, but if I remember correctly, the tables will be updated and indexes newly created on every plugin update. You could also recreate your index new on every plugin update, too.

If you try this, I would be happy to hear about your steps and the results.

2 votes
Simon Tost _TNG_ September 2, 2017

Update: Since Version 1.2 of Active Objects this should be possible:

import net.java.ao.Entity;
import net.java.ao.schema.Index;
import net.java.ao.schema.Indexes;
 
@Indexes({
    @Index(name = "names", methodNames = {"getFirstName", "getLastName"}),
    @Index(name = "age", methodNames = "getAge")
})
public interface Person extends Entity {
    public String getFirstName();
    public void setFirstName(String firstName);
    public void setLastName(String lastName);
    public String getLastName();
    public int getAge();
    public void setAge(int age);
}

Source: Active Objects 1.2.0 Upgrade guide

 

I have yet to try it, though ... ;)

Asif Diwan October 24, 2018

I have tried putting this entity but still not getting index reflected in Database. 

My activeobjects version is 1.2. Please let me know if you are able to get Index reflected in DB for multiple columns using @Indexed annotation.

Simon Tost _TNG_ October 24, 2018

It's been some time ago, but i think i did not try it back then, so i cannot confirm that it really works. As stated in the answer, the info is from the AO upgrade notes.

TAGS
AUG Leaders

Atlassian Community Events