METAGEN-57 Adding support for embedded id to XmlMetaEntity and adding testcase
This commit is contained in:
parent
807fa02bbf
commit
2d245a3798
|
@ -29,13 +29,13 @@ import javax.lang.model.type.ExecutableType;
|
|||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
|
||||
import org.hibernate.jpamodelgen.Context;
|
||||
import org.hibernate.jpamodelgen.ImportContextImpl;
|
||||
import org.hibernate.jpamodelgen.MetaModelGenerationException;
|
||||
import org.hibernate.jpamodelgen.model.ImportContext;
|
||||
import org.hibernate.jpamodelgen.model.MetaAttribute;
|
||||
import org.hibernate.jpamodelgen.model.MetaEntity;
|
||||
import org.hibernate.jpamodelgen.util.AccessTypeInformation;
|
||||
import org.hibernate.jpamodelgen.util.StringUtil;
|
||||
import org.hibernate.jpamodelgen.util.TypeUtils;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.Attributes;
|
||||
|
@ -44,6 +44,7 @@ import org.hibernate.jpamodelgen.xml.jaxb.ElementCollection;
|
|||
import org.hibernate.jpamodelgen.xml.jaxb.Embeddable;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.EmbeddableAttributes;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.Embedded;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.EmbeddedId;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.Entity;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.Id;
|
||||
import org.hibernate.jpamodelgen.xml.jaxb.ManyToMany;
|
||||
|
@ -350,6 +351,16 @@ public class XmlMetaEntity implements MetaEntity {
|
|||
}
|
||||
}
|
||||
|
||||
if ( attributes.getEmbeddedId() != null ) {
|
||||
EmbeddedId embeddedId = attributes.getEmbeddedId();
|
||||
ElementKind elementKind = getElementKind( embeddedId.getAccess() );
|
||||
String type = getType( embeddedId.getName(), null, elementKind );
|
||||
if ( type != null ) {
|
||||
attribute = new XmlMetaSingleAttribute( this, embeddedId.getName(), type );
|
||||
members.add( attribute );
|
||||
}
|
||||
}
|
||||
|
||||
for ( Basic basic : attributes.getBasic() ) {
|
||||
parseBasic( basic );
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.hibernate.jpamodelgen.test.embeddedid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.TestUtil;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class EmbeddedIdTest extends CompilationTest {
|
||||
@Test
|
||||
public void testGeneratedAnnotationNotGenerated() {
|
||||
assertMetamodelClassGeneratedFor( Person.class );
|
||||
assertPresenceOfFieldInMetamodelFor(
|
||||
Person.class, "id", "Property id should be in metamodel"
|
||||
);
|
||||
|
||||
assertPresenceOfFieldInMetamodelFor(
|
||||
Person.class, "address", "Property id should be in metamodel"
|
||||
);
|
||||
|
||||
assertPresenceOfFieldInMetamodelFor(
|
||||
XmlPerson.class, "id", "Property id should be in metamodel"
|
||||
);
|
||||
|
||||
assertPresenceOfFieldInMetamodelFor(
|
||||
XmlPerson.class, "address", "Property id should be in metamodel"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPackageNameOfCurrentTest() {
|
||||
return EmbeddedIdTest.class.getPackage().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<String> getOrmFiles() {
|
||||
List<String> ormFiles = new ArrayList<String>();
|
||||
String dir = TestUtil.fcnToPath( EmbeddedIdTest.class.getPackage().getName() );
|
||||
ormFiles.add( dir + "/orm.xml" );
|
||||
return ormFiles;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.hibernate.jpamodelgen.test.embeddedid;
|
||||
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@Entity
|
||||
public class Person {
|
||||
@EmbeddedId
|
||||
private PersonId id;
|
||||
|
||||
private String address;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.hibernate.jpamodelgen.test.embeddedid;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
@Embeddable
|
||||
public class PersonId {
|
||||
private String name;
|
||||
private String snn;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSnn() {
|
||||
return snn;
|
||||
}
|
||||
|
||||
public void setSnn(String snn) {
|
||||
this.snn = snn;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2012, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.hibernate.jpamodelgen.test.embeddedid;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
*/
|
||||
public class XmlPerson {
|
||||
private PersonId id;
|
||||
private String address;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||
version="2.0"
|
||||
>
|
||||
<package>org.hibernate.jpamodelgen.test.embeddedid</package>
|
||||
<entity class="XmlPerson" access="FIELD">
|
||||
<attributes>
|
||||
<embedded-id name="id"/>
|
||||
<basic name="address"/>
|
||||
</attributes>
|
||||
</entity>
|
||||
<embeddable class="PersonId">
|
||||
<attributes>
|
||||
<basic name="name"/>
|
||||
<basic name="snn"/>
|
||||
</attributes>
|
||||
</embeddable>
|
||||
</entity-mappings>
|
||||
|
Loading…
Reference in New Issue