Indices in Existing Active Objects

I have a confluence server plugin with a lot of active objects. While it already has the primary key and foreign key indices, is there a simplest way to add indices to an existing column in an Active Object (which is neither a primary or a foreign key)? I tried by adding @Indexed over the getter and setter of the AO interface, but it doesnt seem to work. Any ideas here? Some code examples and snippets would be greatly appreciated, as well as any relavant documentation.

Hi @yagnesh.bhat,

Here’s an example for a simple class I have. The trick is the methodNames has to be the actual method names and not the data fields.

package com.atlassian.moremlorem.ao;

import com.atlassian.moremlorem.data.MoremType;
import net.java.ao.Entity;
import net.java.ao.schema.Index;
import net.java.ao.schema.Indexes;
import net.java.ao.schema.StringLength;

@Indexes({
        @Index(name = "lookup", methodNames = {"getContentId", "getMoremType", "getParagraphs"})
})
public interface Morem extends Entity {

    long getContentId();

    void setContentId(long contentId);

    MoremType getMoremType();

    void setMoremType(MoremType moremType);

    int getParagraphs();

    void setParagraphs(int paragraphs);

    String getText();

    @StringLength(StringLength.UNLIMITED)
    void setText(String text);
}

And this creates this table in PostgreSQL

-- auto-generated definition
create table "AO_DFCAD7_MOREM"
(
    "CONTENT_ID" bigint  default 0,
    "ID"         serial
        primary key,
    "MOREM_TYPE" varchar(255),
    "PARAGRAPHS" integer default 0,
    "TEXT"       text
);

alter table "AO_DFCAD7_MOREM"
    owner to confluence;

create index index_ao_dfcad7_morem_lookup
    on "AO_DFCAD7_MOREM" ("CONTENT_ID", "MOREM_TYPE", "PARAGRAPHS");

Hope this helps.

Regards,
James.

3 Likes