private TemporalType getTemporalType(XProperty property) { if ( key ) { MapKeyTemporal ann = property.getAnnotation( MapKeyTemporal.class ); return ann.value(); } else { Temporal ann = property.getAnnotation( Temporal.class ); return ann.value(); } }
@Entity(name = "Person") public static class Person { @Id private Long id; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinTable( name = "phone_register", joinColumns = @JoinColumn(name = "phone_id"), inverseJoinColumns = @JoinColumn(name = "person_id")) @MapKey(name = "since") @MapKeyTemporal(TemporalType.TIMESTAMP) private Map<Date, Phone> phoneRegister = new HashMap<>(); //Getters and setters are omitted for brevity //end::collections-map-unidirectional-example[] public Person() { } public Person(Long id) { this.id = id; } public Map<Date, Phone> getPhoneRegister() { return phoneRegister; } //tag::collections-map-unidirectional-example[] public void addPhone(Phone phone) { phoneRegister.put( phone.getSince(), phone ); } }
@Test public void testMapKeyTemporal() throws Exception { reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" ); assertAnnotationPresent( ElementCollection.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertEquals( TemporalType.DATE, reader.getAnnotation( MapKeyTemporal.class ).value() ); }
@MapKeyTemporal(TemporalType.TIMESTAMP ) private Map<Date, Call> callHistory = new HashMap<>();
@Test public void testMapKeyTemporal() throws Exception { reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertEquals( TemporalType.DATE, reader.getAnnotation( MapKeyTemporal.class ).value() ); }
public Map<String, Gas> gases = new HashMap<String, Gas>(); @MapKeyTemporal(TemporalType.DATE) @ElementCollection(fetch = FetchType.EAGER) @MapKeyColumn(nullable=false)
private TemporalType getTemporalType(XProperty property) { if (key) { MapKeyTemporal ann = property.getAnnotation( MapKeyTemporal.class ); return ann.value(); } else { Temporal ann = property.getAnnotation( Temporal.class ); return ann.value(); } }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link Temporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link Temporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ protected TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link MapKeyTemporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleMapKeyTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
/** * Handles the {@link Temporal} annotation. * * @param member * the member * @param parsed * the list of annotations parsed * @return the map key value * * @since 2.0.0 */ private TemporalType handleTemporalType(Member member, Set<Class<? extends Annotation>> parsed) { final MapKeyTemporal annotation = ReflectHelper.getAnnotation(member, MapKeyTemporal.class); if (annotation != null) { parsed.add(MapKeyTemporal.class); return annotation.value(); } return null; }
private void mapKeySupplementalDetails( XProperty navigableXProperty, MetadataBuildingContext buildingContext) { final MapKeyEnumerated mapKeyEnumeratedAnn = navigableXProperty.getAnnotation( MapKeyEnumerated.class ); if ( mapKeyEnumeratedAnn != null ) { enumType = mapKeyEnumeratedAnn.value(); } final MapKeyTemporal mapKeyTemporalAnn = navigableXProperty.getAnnotation( MapKeyTemporal.class ); if ( mapKeyTemporalAnn != null ) { temporalPrecision = mapKeyTemporalAnn.value(); } } private void normalSupplementalDetails(
private TemporalType getTemporalType(XProperty property) { if ( key ) { MapKeyTemporal ann = property.getAnnotation( MapKeyTemporal.class ); return ann.value(); } else { Temporal ann = property.getAnnotation( Temporal.class ); return ann.value(); } }
private TemporalType getTemporalType(XProperty property) { if ( key ) { MapKeyTemporal ann = property.getAnnotation( MapKeyTemporal.class ); return ann.value(); } else { Temporal ann = property.getAnnotation( Temporal.class ); return ann.value(); } }
/** * Parse @Temporal. */ private void parseMapKeyTemporal(FieldMapping fm, MapKeyTemporal anno) { List<Column> cols = fm.getKeyMapping().getValueInfo().getColumns(); if (!cols.isEmpty() && cols.size() != 1) throw new MetaDataException(_loc.get("num-cols-mismatch", fm, String.valueOf(cols.size()), "1")); if (cols.isEmpty()) { cols = Arrays.asList(new Column[]{ new Column() }); fm.getKeyMapping().getValueInfo().setColumns(cols); } Column col = (Column) cols.get(0); switch (anno.value()) { case DATE: col.setType(Types.DATE); break; case TIME: col.setType(Types.TIME); break; case TIMESTAMP: col.setType(Types.TIMESTAMP); break; } }