blob: c21d201e5f663ea58eac0f8536ffd5073aa6a8e3 [file] [log] [blame]
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// 10/25/2012-2.5 Guy Pelletier
// - 374688: JPA 2.1 Converter support
// 11/19/2012-2.5 Guy Pelletier
// - 389090: JPA 2.1 DDL Generation Support (foreign key metadata support)
// 11/28/2012-2.5 Guy Pelletier
// - 374688: JPA 2.1 Converter support
package org.eclipse.persistence.testing.models.jpa21.advanced.xml;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converts;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.MapKeyColumn;
import org.eclipse.persistence.testing.models.jpa21.advanced.converters.DistanceConverter;
import org.eclipse.persistence.testing.models.jpa21.advanced.converters.TimeConverter;
import org.eclipse.persistence.testing.models.jpa21.advanced.enums.Gender;
public class Runner extends Athlete {
protected Integer id;
protected Gender gender;
protected RunnerInfo info;
protected List<Race> races;
protected Map<ShoeTag, Shoe> shoes;
// This is mapped here until the JPA schema is corrected. Currently
// cannot specify a convert with a column in JPA (with XML validation on)
@ElementCollection
@Column(name="TIME")
@MapKeyColumn(name="DISTANCE")
@CollectionTable(
name="JPA21_XML_RUNNER_PBS",
joinColumns=@JoinColumn(name="RUNNER_ID")
)
@Converts({
@Convert(attributeName="key", converter = DistanceConverter.class),
@Convert(converter = TimeConverter.class)
})
protected Map<String, String> personalBests;
public Runner() {
races = new ArrayList<Race>();
personalBests = new HashMap<String, String>();
}
public void addPersonalBest(String distance, String time) {
personalBests.put(distance, time);
}
public void addRace(Race race) {
races.add(race);
}
public Gender getGender() {
return gender;
}
public Integer getId() {
return id;
}
public RunnerInfo getInfo() {
return info;
}
public Map<String, String> getPersonalBests() {
return personalBests;
}
public List<Race> getRaces() {
return races;
}
public Map<ShoeTag, Shoe> getShoes() {
return shoes;
}
public boolean isFemale() {
return gender.equals(Gender.Female);
}
public boolean isMale() {
return gender.equals(Gender.Male);
}
public void setGender(Gender gender) {
this.gender = gender;
}
public void setInfo(RunnerInfo info) {
this.info = info;
}
public void setIsFemale() {
this.gender = Gender.Female;
}
public void setIsMale() {
this.gender = Gender.Male;
}
public void setPersonalBests(Map<String, String> personalBests) {
this.personalBests = personalBests;
}
public void setRaces(List<Race> races) {
this.races = races;
}
public void setShoes(Map<ShoeTag, Shoe> shoes) {
this.shoes = shoes;
}
}