Can ebean be told to create indexes?

1,122 views
Skip to first unread message

Chris

unread,
Jul 12, 2012, 6:04:32 AM7/12/12
to eb...@googlegroups.com
Hi

From the DDL generated, I see that ebean creates a whole load of indexes for columns that are marked IDs, and foreign keys, etc. Is it possible to specify an annotation, or some other way. I see in the AddForeignKeyVisitors there is some code to add the index. Perhaps it would be possibly to abstract that away and introduce an index annotation? For example, Hibernate has a @Index annotation. 

if (ctx.getDdlSyntax().isRenderIndexForFkey()){

//create index idx_fk_o_address_ctry on o_address(country_code);
ctx.write("create index ");

String idxName = ctx.getDdlSyntax().getIndexName(tableName, p.getName(), ctx.incrementIxCount());
if (idxName != null){
ctx.write(idxName);
}

ctx.write(" on ").write(baseTable).write(" (");
for (int i = 0; i < columns.length; i++) {
if (i > 0){
ctx.write(",");
}
ctx.write(columns[i].getLocalDbColumn());
}
ctx.write(");").writeNewLine();
}

Cheers
Chris

edge

unread,
Jul 12, 2012, 9:31:25 AM7/12/12
to eb...@googlegroups.com
If you are looking for a unique index you can use 

@Column(unique=true)

otherwise Ebean will create all the indices required for ids and foreign keys 

Chris Burrell

unread,
Jul 12, 2012, 9:33:52 AM7/12/12
to eb...@googlegroups.com
Yes, i realise this about unique indexes and primary key indexes. I'm interested in functionality similar to the hibernate functionality where I can create an arbitrary index on any column of my choice, i.e. whether unique or not unique.

Looks like the code is pretty much there already, just needing a new annotation and a bit of refactoring?

Chris

edge

unread,
Jul 12, 2012, 10:01:57 AM7/12/12
to eb...@googlegroups.com, ch...@burrell.me.uk
probably not that difficult to do - fancy taking a crack at implementing it?

Chris

unread,
Jul 14, 2012, 8:24:44 AM7/14/12
to eb...@googlegroups.com, ch...@burrell.me.uk
Happy to have a go. However, I downloaded the latest copy and it doesn't seem to build... Is trunk broken? I'm getting the following issues:

Description Resource Path Location Type
The type PreparedStatementDelegator must implement the inherited abstract method Statement.closeOnCompletion() PreparedStatementDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 43 Java Problem
The type PreparedStatementDelegator must implement the inherited abstract method Statement.isCloseOnCompletion() PreparedStatementDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 43 Java Problem
The type DataSourcePool must implement the inherited abstract method CommonDataSource.getParentLogger() DataSourcePool.java /ebean/src/main/java/com/avaje/ebeaninternal/server/lib/sql line 53 Java Problem
The type ConnectionDelegator must implement the inherited abstract method Connection.getSchema() ConnectionDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 38 Java Problem
The type ConnectionDelegator must implement the inherited abstract method Connection.abort(Executor) ConnectionDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 38 Java Problem
The type ConnectionDelegator must implement the inherited abstract method Connection.getNetworkTimeout() ConnectionDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 38 Java Problem
The type ConnectionDelegator must implement the inherited abstract method Connection.setSchema(String) ConnectionDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 38 Java Problem
The type ConnectionDelegator must implement the inherited abstract method Connection.setNetworkTimeout(Executor, int) ConnectionDelegator.java /ebean/src/jdk_1.6/java/com/avaje/ebeaninternal/jdbc line 38 Java Problem

Same for 2.7.7 and 2.7.6. Are there particular flags to maven I'm supposed to use? (I'm using jdk 1.7 btw)
Cheers
Chris

Angelo K. Huang

unread,
Oct 26, 2012, 11:21:35 PM10/26/12
to eb...@googlegroups.com
Is this index annotation available yet?

Chris Burrell

unread,
Oct 27, 2012, 6:22:45 AM10/27/12
to eb...@googlegroups.com
Hi

I'm afraid I didn't progress it since my last post went un-answered and was busy with parts of my own code-base too, I haven't touched it since. Not sure if the other guys at ebean have progressed it however...

Chris
Reply all
Reply to author
Forward
0 new messages