-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:ebean-orm/avaje-ebeanorm
- Loading branch information
Showing
8 changed files
with
258 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.avaje.ebean.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* An annotation for declaring an index on a single column. | ||
* | ||
* @author rvbiljouw | ||
*/ | ||
@Target({ElementType.FIELD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Index { | ||
|
||
/** | ||
* Name of the index | ||
* | ||
* @return index name | ||
*/ | ||
String value() default ""; | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/com/avaje/ebeaninternal/server/ddl/CreateIndexVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.avaje.ebeaninternal.server.ddl; | ||
|
||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; | ||
import com.avaje.ebeaninternal.server.deploy.BeanProperty; | ||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne; | ||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyCompound; | ||
|
||
/** | ||
* A visitor that creates indexes for columns annotated with ColumnIndex | ||
* | ||
* @author rvbiljouw | ||
* @see com.avaje.ebean.annotation.Index | ||
*/ | ||
public class CreateIndexVisitor extends AbstractBeanVisitor { | ||
private final IndexPropertyVisitor iv; | ||
|
||
public CreateIndexVisitor(DdlGenContext ctx) { | ||
this.iv = new IndexPropertyVisitor(ctx); | ||
} | ||
|
||
@Override | ||
public void visitBegin() { | ||
|
||
} | ||
|
||
@Override | ||
public boolean visitBean(BeanDescriptor<?> descriptor) { | ||
return descriptor.isInheritanceRoot(); | ||
} | ||
|
||
@Override | ||
public PropertyVisitor visitProperty(BeanProperty p) { | ||
return iv; | ||
} | ||
|
||
@Override | ||
public void visitBeanEnd(BeanDescriptor<?> descriptor) { | ||
visitInheritanceProperties(descriptor, iv); | ||
} | ||
|
||
@Override | ||
public void visitEnd() { | ||
|
||
} | ||
|
||
private static final class IndexPropertyVisitor extends BaseTablePropertyVisitor { | ||
private final DdlGenContext ctx; | ||
|
||
public IndexPropertyVisitor(DdlGenContext ctx) { | ||
this.ctx = ctx; | ||
} | ||
|
||
@Override | ||
public void visitEmbeddedScalar(BeanProperty p, BeanPropertyAssocOne<?> embedded) { | ||
|
||
} | ||
|
||
@Override | ||
public void visitOneImported(BeanPropertyAssocOne<?> p) { | ||
|
||
} | ||
|
||
@Override | ||
public void visitScalar(BeanProperty p) { | ||
String baseTable = p.getBeanDescriptor().getBaseTable(); | ||
if (p.isIndexed()) { | ||
String indexName = p.getIndexName(); | ||
if (indexName.length() == 0) { | ||
indexName = ctx.getDdlSyntax().getIndexName(baseTable, p.getDbColumn(), ctx.incrementIxCount()); | ||
} | ||
ctx.write("create index ") | ||
.write(indexName) | ||
.write(" on ") | ||
.write(baseTable) | ||
.write("(") | ||
.write(p.getDbColumn()) | ||
.write(");") | ||
.writeNewLine(); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitCompoundScalar(BeanPropertyCompound compound, BeanProperty p) { | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.