HHH-7534 completed test case

This commit is contained in:
Brett Meyer 2014-03-10 15:42:20 -04:00
parent d576bb071f
commit ca9b917622
3 changed files with 38 additions and 8 deletions

View File

@ -118,9 +118,4 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase {
assertEquals( "importers_id", column.getColumnName().getText() );
assertSame( table, index.getTable() );
}
@Test
public void testTableGeneratorIndex(){
//todo
}
}

View File

@ -25,6 +25,7 @@ package org.hibernate.test.annotations.index.jpa;
import java.util.List;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
@ -33,28 +34,37 @@ import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.ManyToMany;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
/**
* @author Strong Liu <stliu@hibernate.org>
*/
@Entity
@Table(indexes = {
@Index(unique = true, columnList = "brand, producer")
, @Index(name = "Car_idx", columnList = "since DESC")
@Table(indexes = { @Index(unique = true, columnList = "brand, producer"),
@Index(name = "Car_idx", columnList = "since DESC")
})
@TableGenerator(name = "idGen", table = "ID_GEN", valueColumnName="GEN_VALUE",
indexes = @Index(columnList = "GEN_VALUE"))
@SecondaryTable(name = "T_DEALER", indexes = @Index(columnList = "dealer_name ASC, rate DESC"))
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "idGen")
private long id;
private String brand;
private String producer;
private long since;
@AttributeOverrides({
@AttributeOverride(name = "name", column = @Column(name = "dealer_name", table = "T_DEALER")),
@AttributeOverride(name = "rate", column = @Column(table = "T_DEALER"))

View File

@ -23,6 +23,18 @@
*/
package org.hibernate.test.annotations.index.jpa;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.test.util.SchemaUtil;
import org.junit.Test;
/**
* @author Strong Liu <stliu@hibernate.org>
@ -37,5 +49,18 @@ public class IndexTest extends AbstractJPAIndexTest {
};
}
@Test
public void testTableGeneratorIndex(){
TableSpecification table = SchemaUtil.getTable( "ID_GEN", metadata() );
Iterator<org.hibernate.metamodel.spi.relational.Index> indexes = table.getIndexes().iterator();
assertTrue( indexes.hasNext() );
org.hibernate.metamodel.spi.relational.Index index = indexes.next();
assertFalse( indexes.hasNext() );
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
assertEquals( 1, index.getColumnSpan() );
org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get( 0 );
assertEquals( "GEN_VALUE", column.getColumnName().getText() );
assertSame( table, index.getTable() );
}
}