#660353 : fixed identifier handling

This commit is contained in:
Timo Westkämper 2010-10-14 10:30:11 +00:00
parent 112ccfe02e
commit 009380a0f3
5 changed files with 146 additions and 7 deletions

View File

@ -152,7 +152,10 @@ public class HibernateDomainExporter {
EntityType entityType = createEntityType(pc.getMappedClass());
if (pc.getDeclaredIdentifierProperty() != null){
handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty());
}
}else if (!pc.isInherited() && pc.hasIdentifierProperty()){
System.out.println(entityType.toString() + pc.getIdentifierProperty());
handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty());
}
Iterator<?> properties = pc.getDeclaredPropertyIterator();
while (properties.hasNext()){
handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
@ -239,6 +242,7 @@ public class HibernateDomainExporter {
}
private Map<Class<?>,Annotation> getAnnotations(Class<?> cl, String propertyName) throws NoSuchMethodException {
// TODO : merge annotations
try {
Field field = cl.getDeclaredField(propertyName);
return getAnnotations(field.getAnnotations());

View File

@ -52,7 +52,5 @@ public class DocumentProp {
public void setPropValueDetails(String propValueDetails) {
this.propValueDetails = propValueDetails;
}
}

View File

@ -0,0 +1,89 @@
package com.mysema.query.jpa.domain3;
import java.io.Serializable;
public class Store implements Serializable {
private static final long serialVersionUID = 7221730732392000227L;
private String code;
private String name;
private String address;
private String city;
private String phoneDetails;
private String faxDetails;
private String zipCode;
private String chainCode;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPhoneDetails() {
return phoneDetails;
}
public void setPhoneDetails(String phoneDetails) {
this.phoneDetails = phoneDetails;
}
public String getFaxDetails() {
return faxDetails;
}
public void setFaxDetails(String faxDetails) {
this.faxDetails = faxDetails;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getChainCode() {
return chainCode;
}
public void setChainCode(String chainCode) {
this.chainCode = chainCode;
}
}

View File

@ -24,7 +24,7 @@ public class HibernateDomainExporterTest {
private SerializerConfig serializerConfig = SimpleSerializerConfig.getConfig(Domain.class.getPackage().getAnnotation(Config.class));
@Test
public void Execute_Single() throws IOException {
public void Execute_Contact() throws IOException {
FileUtils.deleteDirectory(new File("target/gen1"));
File contact = new File("src/test/resources/contact.hbm.xml");
Configuration config = new Configuration();
@ -34,11 +34,11 @@ public class HibernateDomainExporterTest {
exporter.execute();
File targetFile = new File("target/gen1/com/mysema/query/jpa/domain2/QContact.java");
assertContains(targetFile, "StringPath firstName", "StringPath lastName");
assertContains(targetFile, "NumberPath<Long> id", "StringPath firstName", "StringPath lastName");
}
@Test
public void Execute_Single2() throws IOException {
public void Execute_Contact2() throws IOException {
FileUtils.deleteDirectory(new File("target/gen2"));
File contact = new File("src/test/resources/contact2.hbm.xml");
Configuration config = new Configuration();
@ -48,7 +48,7 @@ public class HibernateDomainExporterTest {
exporter.execute();
File targetFile = new File("target/gen2/com/mysema/query/jpa/domain2/QContact.java");
assertContains(targetFile, "StringPath firstName", "StringPath lastName");
assertContains(targetFile, "NumberPath<Long> id", "StringPath firstName", "StringPath lastName");
}
@Test
@ -108,6 +108,21 @@ public class HibernateDomainExporterTest {
}
}
@Test
public void Execute_Store() throws IOException {
FileUtils.deleteDirectory(new File("target/gen5"));
File contact = new File("src/test/resources/store.hbm.xml");
Configuration config = new Configuration();
config.addFile(contact);
config.buildMappings();
HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen5"), config);
exporter.execute();
File targetFile = new File("target/gen5/com/mysema/query/jpa/domain3/QStore.java");
assertContains(targetFile, "StringPath code");
}
private static void assertContains(File file, String... strings) throws IOException{
assertTrue(file.getPath() + " doesn't exist", file.exists());

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.mysema.query.jpa.domain3.Store" table="STORE">
<cache usage="nonstrict-read-write"/>
<id name="code" type="java.lang.String" column="CODE">
<generator class="assigned"/>
</id>
<property name="name">
<column name="NAME"/>
</property>
<property name="address">
<column name="ADDRESS"/>
</property>
<property name="city">
<column name="CITY"/>
</property>
<property name="phoneDetails">
<column name="PHONE_DETAILS" length="30"/>
</property>
<property name="faxDetails">
<column name="FAX_DETAILS" length="30"/>
</property>
<property name="zipCode">
<column name="ZIP_CODE" length="15"/>
</property>
<property name="chainCode">
<column name="CHAIN_CODE"/>
</property>
</class>
</hibernate-mapping>