List of usage examples for org.hibernate.mapping Table indexes
Map indexes
To view the source code for org.hibernate.mapping Table indexes.
Click Source Link
From source file:com.github.gekoh.yagen.ddl.CreateDDL.java
License:Apache License
private void addIndexes(StringBuffer buf, Dialect dialect, TableConfig tableConfig) { com.github.gekoh.yagen.api.Table annotation = tableConfig .getTableAnnotationOfType(com.github.gekoh.yagen.api.Table.class); if (annotation != null) { for (UniqueConstraint uniqueConstraint : annotation.uniqueConstraints()) { // only custom declarations of unique keys need to be created with separate unique index DDL // when specifying column names there will be an create table inline unique constraint if (StringUtils.isEmpty(uniqueConstraint.declaration())) { continue; }//from ww w . ja v a 2 s . c o m String constraintName = getProfile().getNamingStrategy().constraintName(uniqueConstraint); if (StringUtils.isEmpty(constraintName)) { throw new IllegalArgumentException( "please specify an unique constraint name in annotation UniqueConstraint for table " + tableConfig.getTableName()); } checkObjectName(dialect, constraintName); StringBuilder objDdl = new StringBuilder(); objDdl.append("create unique index ").append(constraintName); objDdl.append(" on ").append(tableConfig.getTableName()).append(" (") .append(uniqueConstraint.declaration()).append(")"); if (uniqueConstraint.usingLocalIndex() && supportsPartitioning(dialect)) { objDdl.append(" local"); } getProfile().duplex(ObjectType.INDEX, constraintName, objDdl.toString()); buf.append(STATEMENT_SEPARATOR).append(objDdl.toString()); } for (Index index : annotation.indexes()) { if (StringUtils.isEmpty(index.declaration())) { continue; } String indexName = getProfile().getNamingStrategy().indexName(index); if (StringUtils.isEmpty(indexName)) { throw new IllegalArgumentException("please specify an index name in annotation Index for table " + tableConfig.getTableName()); } checkObjectName(dialect, indexName); StringBuilder objDdl = new StringBuilder(); objDdl.append("create index ").append(indexName); objDdl.append(" on ").append(tableConfig.getTableName()).append(" (").append(index.declaration()) .append(")"); if (index.usingLocalIndex() && supportsPartitioning(dialect)) { objDdl.append(" local"); } getProfile().duplex(ObjectType.INDEX, indexName, objDdl.toString()); buf.append(STATEMENT_SEPARATOR).append(objDdl.toString()); } } }