Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

Commit

Permalink
METAGEN-62 Adding support for SortedMap and SortedSet
Browse files Browse the repository at this point in the history
  • Loading branch information
hferentschik committed Jan 17, 2012
1 parent f31c441 commit fbdb70d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Expand Up @@ -113,7 +113,6 @@ public AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element
TypeElement returnedElement = (TypeElement) context.getTypeUtils().asElement( declaredType );
// WARNING: .toString() is necessary here since Name equals does not compare to String
String fqNameOfReturnType = returnedElement.getQualifiedName().toString();
// TODO - need to fix METAGEN-62, need to check whether the specified type is a subtype of a collection type
String collection = Constants.COLLECTIONS.get( fqNameOfReturnType );
String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/hibernate/jpamodelgen/util/Constants.java
Expand Up @@ -36,6 +36,10 @@ public final class Constants {
COLLECTIONS.put( java.util.Set.class.getName(), javax.persistence.metamodel.SetAttribute.class.getName() );
COLLECTIONS.put( java.util.List.class.getName(), javax.persistence.metamodel.ListAttribute.class.getName() );
COLLECTIONS.put( java.util.Map.class.getName(), javax.persistence.metamodel.MapAttribute.class.getName() );

// Hibernate also supports the SortedSet and SortedMap interfaces
COLLECTIONS.put( java.util.SortedSet.class.getName(), javax.persistence.metamodel.SetAttribute.class.getName() );
COLLECTIONS.put( java.util.SortedMap.class.getName(), javax.persistence.metamodel.MapAttribute.class.getName() );
}

public static List<String> BASIC_TYPES = new ArrayList<String>();
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.hibernate.jpamodelgen.test.onetomanysorted;

import java.util.SortedMap;
import java.util.SortedSet;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand All @@ -36,6 +37,10 @@ public class Printer {
@OneToMany
@Sort
private SortedSet<PrintJob> printQueue;

@OneToMany
@Sort
private SortedMap<String, PrintJob> printedJobs;
}


Expand Up @@ -14,31 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.hibernate.jpamodelgen.test.onetomanysorted;

import org.testng.annotations.Test;

import org.hibernate.jpamodelgen.test.util.CompilationTest;
import org.hibernate.jpamodelgen.test.util.TestForIssue;

import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;

/**
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
public class OneToManySortedTest extends CompilationTest {
public class SortedCollectionTest extends CompilationTest {

@Test
@TestForIssue(jiraKey = "METAGEN-62")
public void testGenerics() {
assertMetamodelClassGeneratedFor( Printer.class );
assertMetamodelClassGeneratedFor( PrintJob.class );
assertPresenceOfFieldInMetamodelFor( Printer.class, "printQueue", "There one to many attribute is missing" );
assertPresenceOfFieldInMetamodelFor( Printer.class, "printQueue", "There sorted set attribute is missing" );
assertPresenceOfFieldInMetamodelFor( Printer.class, "printedJobs", "There sorted map attribute is missing" );
}

@Override
protected String getPackageNameOfCurrentTest() {
return OneToManySortedTest.class.getPackage().getName();
return SortedCollectionTest.class.getPackage().getName();
}
}

0 comments on commit fbdb70d

Please sign in to comment.