code
stringlengths
3
1.18M
language
stringclasses
1 value
package com.anli.busstation.dal.jpa.entities.geography; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.jpa.entities.vehicles.BusImpl; import com.anli.busstation.dal.jpa.entities.staff.EmployeeImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.interfaces.entities.geography.Station; import java.math.BigDecimal; import java.util.List; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OrderColumn; import javax.persistence.Table; import static javax.persistence.FetchType.LAZY; @Entity(name = "Station") @Table(name = "stations") @AttributeOverride(name = "id", column = @Column(name = "station_id")) public class StationImpl extends BSEntityImpl implements Station { @Column(name = "name") protected String name; @Column(name = "latitude") protected BigDecimal latitude; @Column(name = "longitude") protected BigDecimal longitude; @OneToMany(fetch = LAZY) @JoinColumn(name = "station", referencedColumnName = "station_id") @OrderColumn(name = "station_order") protected List<EmployeeImpl> employees; @OneToMany(fetch = LAZY) @JoinColumn(name = "station", referencedColumnName = "station_id") @OrderColumn(name = "station_order") protected List<BusImpl> buses; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public BigDecimal getLatitude() { return latitude; } @Override public void setLatitude(BigDecimal latitude) { this.latitude = latitude; } @Override public BigDecimal getLongitude() { return longitude; } @Override public void setLongitude(BigDecimal longitude) { this.longitude = longitude; } @Override public List<Employee> getEmployees() { return (List) employees; } public void setEmployees(List<EmployeeImpl> employees) { this.employees = employees; } @Override public List<Bus> getBuses() { return (List) buses; } public void setBuses(List<BusImpl> buses) { this.buses = buses; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } StationImpl stationComparee = (StationImpl) comparee; return nullableEquals(this.name, stationComparee.name) && nullableEquals(this.latitude, stationComparee.latitude) && nullableEquals(this.longitude, stationComparee.longitude) && nullableListDeepEquals((List) this.employees, (List) stationComparee.employees) && nullableListDeepEquals((List) this.buses, (List) stationComparee.buses); } @Override public String toString() { return super.toString() + " name = " + name + " latitude = " + latitude + " longitude = " + longitude + " employees = " + employees + " buses = " + buses; } }
Java
package com.anli.busstation.dal.jpa.entities.geography; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.geography.Region; import com.anli.busstation.dal.interfaces.entities.geography.Station; import java.util.List; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.OrderColumn; import javax.persistence.Table; import static javax.persistence.FetchType.LAZY; @Entity(name = "Region") @Table(name = "regions") @AttributeOverride(name = "id", column = @Column(name = "region_id")) public class RegionImpl extends BSEntityImpl implements Region { @Column(name = "name") protected String name; @Column(name = "num_code") protected Integer code; @OneToMany(fetch = LAZY) @JoinColumn(name = "region", referencedColumnName = "region_id") @OrderColumn(name = "region_order") protected List<StationImpl> stations; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public Integer getCode() { return code; } @Override public void setCode(Integer code) { this.code = code; } @Override public List<Station> getStations() { return (List) stations; } public void setStations(List<StationImpl> stations) { this.stations = stations; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } RegionImpl regComparee = (RegionImpl) comparee; return nullableEquals(this.name, regComparee.name) && nullableEquals(this.code, regComparee.code) && nullableListDeepEquals((List) this.stations, (List) regComparee.stations); } @Override public String toString() { return super.toString() + " name = " + name + " code = " + code + " stations = " + stations; } }
Java
package com.anli.busstation.dal.jpa.entities.geography; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.geography.Road; import com.anli.busstation.dal.interfaces.entities.geography.Station; import java.math.BigDecimal; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity(name = "Road") @Table(name = "roads") @AttributeOverride(name = "id", column = @Column(name = "road_id")) @NamedQueries(value = { @NamedQuery(name = "Road.findByStation", query = "select distinct r from Road r where r.aStation = ?1 or r.zStation = ?1"), @NamedQuery(name = "Road.findByNullStation", query = "select distinct r from Road r where r.aStation is null or r.zStation is null"), @NamedQuery(name = "Road.findByAnyStation", query = "select distinct r from Road r where " + "r.aStation in ?1 or r.zStation in ?1"), @NamedQuery(name = "Road.collectIdsByStation", query = "select distinct r.id from Road r where r.aStation = ?1 or r.zStation = ?1"), @NamedQuery(name = "Road.collectIdsByNullStation", query = "select distinct r.id from Road r where r.aStation is null or r.zStation is null"), @NamedQuery(name = "Road.collectIdsByAnyStation", query = "select distinct r.id from Road r where r.aStation in ?1 or r.zStation in ?1")}) public class RoadImpl extends BSEntityImpl implements Road { @OneToOne @JoinColumn(name = "a_station", referencedColumnName = "station_id") protected StationImpl aStation; @OneToOne @JoinColumn(name = "z_station", referencedColumnName = "station_id") protected StationImpl zStation; @Column(name = "\"length\"") protected Integer length; @Column(name = "ride_price") protected BigDecimal ridePrice; @Override public Station getAStation() { return aStation; } @Override public void setAStation(Station aStation) { this.aStation = (StationImpl) aStation; } @Override public Station getZStation() { return zStation; } @Override public void setZStation(Station zStation) { this.zStation = (StationImpl) zStation; } @Override public Integer getLength() { return length; } @Override public void setLength(Integer length) { this.length = length; } @Override public BigDecimal getRidePrice() { return ridePrice; } @Override public void setRidePrice(BigDecimal ridePrice) { this.ridePrice = ridePrice; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } RoadImpl roadComparee = (RoadImpl) comparee; return nullableDeepEquals(this.aStation, roadComparee.aStation) && nullableDeepEquals(this.zStation, roadComparee.zStation) && nullableEquals(this.length, roadComparee.length) && nullableEquals(this.ridePrice, roadComparee.ridePrice); } @Override public String toString() { return super.toString() + " aStation = {" + aStation + "} zStation = {" + zStation + "} length = " + length + " ridePrice = " + ridePrice; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.Mechanic; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; @Entity(name = "Mechanics") @Table(name = "mechanics") @PrimaryKeyJoinColumn(name = "employee_id", referencedColumnName = "employee_id") public class MechanicImpl extends EmployeeImpl implements Mechanic { @OneToOne @JoinColumn(name = "skill", referencedColumnName = "skill_id") protected MechanicSkillImpl skill; @Override public MechanicSkill getSkill() { return skill; } @Override public void setSkill(MechanicSkill skill) { this.skill = (MechanicSkillImpl) skill; } @Override public boolean deepEquals(BSEntity comparee) { if (!super.deepEquals(comparee)) { return false; } MechanicImpl mechComparee = (MechanicImpl) comparee; return nullableDeepEquals(this.skill, mechComparee.skill); } @Override public String toString() { return super.toString() + " skill = {" + skill + "}"; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.Salesman; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; @Entity(name = "Salesman") @Table(name = "salesmen") @PrimaryKeyJoinColumn(name = "employee_id", referencedColumnName = "employee_id") public class SalesmanImpl extends EmployeeImpl implements Salesman { @Column(name = "total_sales") protected Integer totalSales; @Override public Integer getTotalSales() { return totalSales; } @Override public void setTotalSales(Integer totalSales) { this.totalSales = totalSales; } @Override public boolean deepEquals(BSEntity comparee) { if (!super.deepEquals(comparee)) { return false; } SalesmanImpl salesComparee = (SalesmanImpl) comparee; return nullableEquals(this.totalSales, salesComparee.totalSales); } @Override public String toString() { return super.toString() + " totalSales = " + totalSales; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "MechanicSkill") @Table(name = "mechanic_skills") @AttributeOverride(name = "id", column = @Column(name = "skill_id")) public class MechanicSkillImpl extends BSEntityImpl implements MechanicSkill { @Column(name = "name") protected String name; @Column(name = "max_diff_level") protected Integer maxDiffLevel; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public Integer getMaxDiffLevel() { return maxDiffLevel; } @Override public void setMaxDiffLevel(Integer maxDiffLevel) { this.maxDiffLevel = maxDiffLevel; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } MechanicSkillImpl msComparee = (MechanicSkillImpl) comparee; return nullableEquals(this.name, msComparee.name) && nullableEquals(this.maxDiffLevel, msComparee.maxDiffLevel); } @Override public String toString() { return super.toString() + " name = " + name + " maxDiffLevel = " + maxDiffLevel; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.jpa.converters.DateTimeConverter; import com.anli.busstation.dal.jpa.extractors.EmployeeExtractor; import java.math.BigDecimal; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.Table; import javax.persistence.Temporal; import org.eclipse.persistence.annotations.ClassExtractor; import org.joda.time.DateTime; import static javax.persistence.InheritanceType.JOINED; import static javax.persistence.TemporalType.TIMESTAMP; @Entity(name = "Employee") @Inheritance(strategy = JOINED) @ClassExtractor(EmployeeExtractor.class) @Table(name = "employees") @AttributeOverride(name = "id", column = @Column(name = "employee_id")) public abstract class EmployeeImpl extends BSEntityImpl implements Employee { @Column(name = "name") protected String name; @Column(name = "salary") protected BigDecimal salary; @Temporal(TIMESTAMP) @Column(name = "hiring_date") @Convert(converter = DateTimeConverter.class) protected DateTime hiringDate; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public BigDecimal getSalary() { return salary; } @Override public void setSalary(BigDecimal salary) { this.salary = salary; } @Override public DateTime getHiringDate() { return hiringDate; } @Override public void setHiringDate(DateTime hiringDate) { this.hiringDate = hiringDate; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } EmployeeImpl empComparee = (EmployeeImpl) comparee; return nullableEquals(this.name, empComparee.name) && nullableEquals(this.hiringDate, empComparee.hiringDate) && nullableEquals(this.salary, empComparee.salary); } @Override public String toString() { return super.toString() + " name = " + name + " salary = " + salary + " hiringDate = " + hiringDate; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "DriverSkill") @Table(name = "driver_skills") @AttributeOverride(name = "id", column = @Column(name = "skill_id")) public class DriverSkillImpl extends BSEntityImpl implements DriverSkill { @Column(name = "name") protected String name; @Column(name = "max_ride_length") protected Integer maxRideLength; @Column(name = "max_passengers") protected Integer maxPassengers; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public Integer getMaxRideLength() { return maxRideLength; } @Override public void setMaxRideLength(Integer maxRideLength) { this.maxRideLength = maxRideLength; } @Override public Integer getMaxPassengers() { return maxPassengers; } @Override public void setMaxPassengers(Integer maxPassengers) { this.maxPassengers = maxPassengers; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } DriverSkillImpl dsComparee = (DriverSkillImpl) comparee; return nullableEquals(this.name, dsComparee.name) && nullableEquals(this.maxPassengers, dsComparee.maxPassengers) && nullableEquals(this.maxRideLength, dsComparee.maxRideLength); } @Override public String toString() { return super.toString() + " name = " + name + " maxPassengers = " + maxPassengers + " maxRideLength = " + maxRideLength; } }
Java
package com.anli.busstation.dal.jpa.entities.staff; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.staff.Driver; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; @Entity(name = "Driver") @Table(name = "drivers") @PrimaryKeyJoinColumn(name = "employee_id", referencedColumnName = "employee_id") public class DriverImpl extends EmployeeImpl implements Driver { @OneToOne @JoinColumn(name = "skill", referencedColumnName = "skill_id") protected DriverSkillImpl skill; @Override public DriverSkill getSkill() { return skill; } @Override public void setSkill(DriverSkill skill) { this.skill = (DriverSkillImpl) skill; } @Override public boolean deepEquals(BSEntity comparee) { if (!super.deepEquals(comparee)) { return false; } DriverImpl drComparee = (DriverImpl) comparee; return nullableDeepEquals(this.skill, drComparee.skill); } @Override public String toString() { return super.toString() + " skill = {" + skill + "}"; } }
Java
package com.anli.busstation.dal.jpa.entities.vehicles; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "TechnicalState") @Table(name = "technical_states") @AttributeOverride(name = "id", column = @Column(name = "state_id")) public class TechnicalStateImpl extends BSEntityImpl implements TechnicalState { @Column(name = "description") protected String description; @Column(name = "difficulty_level") protected Integer difficultyLevel; @Override public String getDescription() { return description; } @Override public void setDescription(String description) { this.description = description; } @Override public Integer getDifficultyLevel() { return difficultyLevel; } @Override public void setDifficultyLevel(Integer difficultyLevel) { this.difficultyLevel = difficultyLevel; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } TechnicalStateImpl tsComparee = (TechnicalStateImpl) comparee; return nullableEquals(this.description, tsComparee.description) && nullableEquals(this.difficultyLevel, tsComparee.difficultyLevel); } @Override public String toString() { return super.toString() + " description = " + description + " difficultyLevel = " + difficultyLevel; } }
Java
package com.anli.busstation.dal.jpa.entities.vehicles; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity(name = "Bus") @Table(name = "buses") @AttributeOverride(name = "id", column = @Column(name = "bus_id")) public class BusImpl extends BSEntityImpl implements Bus { @OneToOne @JoinColumn(name = "model", referencedColumnName = "model_id") protected ModelImpl model; @OneToOne @JoinColumn(name = "state", referencedColumnName = "state_id") protected TechnicalStateImpl state; @Column(name = "plate") protected String plate; @Override public Model getModel() { return model; } @Override public void setModel(Model model) { this.model = (ModelImpl) model; } @Override public TechnicalState getState() { return state; } @Override public void setState(TechnicalState state) { this.state = (TechnicalStateImpl) state; } @Override public String getPlate() { return plate; } @Override public void setPlate(String plate) { this.plate = plate; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } BusImpl busComparee = (BusImpl) comparee; return nullableDeepEquals(this.model, busComparee.model) && nullableDeepEquals(this.state, busComparee.state) && nullableEquals(this.plate, busComparee.plate); } @Override public String toString() { return super.toString() + " plate = " + plate + " state = {" + state + "} model = {" + model + "}"; } }
Java
package com.anli.busstation.dal.jpa.entities.vehicles; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import java.math.BigDecimal; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "GasLabel") @Table(name = "gas_labels") @AttributeOverride(name = "id", column = @Column(name = "label_id")) public class GasLabelImpl extends BSEntityImpl implements GasLabel { @Column(name = "name") protected String name; @Column(name = "price") protected BigDecimal price; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public BigDecimal getPrice() { return price; } @Override public void setPrice(BigDecimal price) { this.price = price; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } GasLabelImpl glComparee = (GasLabelImpl) comparee; return nullableEquals(this.name, glComparee.name) && nullableEquals(this.price, glComparee.price); } @Override public String toString() { return super.toString() + " name = " + name + " price = " + price; } }
Java
package com.anli.busstation.dal.jpa.entities.vehicles; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import java.math.BigDecimal; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; @Entity(name = "Model") @Table(name = "models") @AttributeOverride(name = "id", column = @Column(name = "model_id")) public class ModelImpl extends BSEntityImpl implements Model { @Column(name = "name") protected String name; @Column(name = "seats_number") protected Integer seatsNumber; @Column(name = "tank_volume") protected Integer tankVolume; @OneToOne @JoinColumn(name = "gas_label", referencedColumnName = "label_id") protected GasLabelImpl gasLabel; @Column(name = "gas_rate") protected BigDecimal gasRate; @Override public String getName() { return name; } @Override public void setName(String name) { this.name = name; } @Override public Integer getSeatsNumber() { return seatsNumber; } @Override public void setSeatsNumber(Integer seatsNumber) { this.seatsNumber = seatsNumber; } @Override public Integer getTankVolume() { return tankVolume; } @Override public void setTankVolume(Integer tankVolume) { this.tankVolume = tankVolume; } @Override public GasLabel getGasLabel() { return gasLabel; } @Override public void setGasLabel(GasLabel gasLabel) { this.gasLabel = (GasLabelImpl) gasLabel; } @Override public BigDecimal getGasRate() { return gasRate; } @Override public void setGasRate(BigDecimal gasRate) { this.gasRate = gasRate; } @Override public boolean deepEquals(BSEntity comparee) { if (!this.equals(comparee)) { return false; } ModelImpl modelComparee = (ModelImpl) comparee; return nullableEquals(this.name, modelComparee.name) && nullableEquals(this.seatsNumber, modelComparee.seatsNumber) && nullableEquals(this.tankVolume, modelComparee.tankVolume) && nullableEquals(this.gasRate, modelComparee.gasRate) && nullableDeepEquals(this.gasLabel, modelComparee.gasLabel); } @Override public String toString() { return super.toString() + " name = " + name + " seatsNumber = " + seatsNumber + " tankVolume = " + tankVolume + " gasRate = " + gasRate + " gasLabel = {" + gasLabel + "}"; } }
Java
package com.anli.busstation.dal.jpa.queries; public class FieldQueryHolder { protected final JpqlQueryBuilder builder; protected final String entityName; protected final String fieldName; protected String selectByEquals; protected String collectByEquals; protected String selectByNull; protected String collectByNull; protected String selectByAny; protected String collectByAny; protected String selectByContains; protected String collectByContains; protected String selectByRegexp; protected String collectByRegexp; protected String selectByOpenRangeTemplate; protected String collectByOpenRangeTemplate; protected String selectByClosedRangeTemplate; protected String collectByClosedRangeTemplate; public FieldQueryHolder(JpqlQueryBuilder queryBuilder, String entityName, String fieldName) { this.builder = queryBuilder; this.entityName = entityName; this.fieldName = fieldName; } public String getSelectByEquals() { if (selectByEquals == null) { selectByEquals = builder.buildSelectByEqualsQuery(entityName, fieldName, true); } return selectByEquals; } public String getCollectByEquals() { if (collectByEquals == null) { collectByEquals = builder.buildSelectByEqualsQuery(entityName, fieldName, false); } return collectByEquals; } public String getSelectByNull() { if (selectByNull == null) { selectByNull = builder.buildSelectByNullQuery(entityName, fieldName, true); } return selectByNull; } public String getCollectByNull() { if (collectByNull == null) { collectByNull = builder.buildSelectByNullQuery(entityName, fieldName, false); } return collectByNull; } public String getSelectByAny() { if (selectByAny == null) { selectByAny = builder.buildSelectByAnyQuery(entityName, fieldName, true); } return selectByAny; } public String getCollectByAny() { if (collectByAny == null) { collectByAny = builder.buildSelectByAnyQuery(entityName, fieldName, false); } return collectByAny; } public String getSelectByContains() { if (selectByContains == null) { selectByContains = builder.buildSelectByContainsQuery(entityName, fieldName, true); } return selectByContains; } public String getCollectByContains() { if (collectByContains == null) { collectByContains = builder.buildSelectByContainsQuery(entityName, fieldName, false); } return collectByContains; } public String getSelectByRegexp() { if (selectByRegexp == null) { selectByRegexp = builder.buildSelectByRegexpQuery(entityName, fieldName, true); } return selectByRegexp; } public String getCollectByRegexp() { if (collectByRegexp == null) { collectByRegexp = builder.buildSelectByRegexpQuery(entityName, fieldName, false); } return collectByRegexp; } public String getSelectByOpenRange(boolean left, boolean strict) { if (selectByOpenRangeTemplate == null) { selectByOpenRangeTemplate = builder.buildSelectByOpenRangeTemplate(entityName, fieldName, true); } return builder.formatOpenRangeTemplate(selectByOpenRangeTemplate, left, strict); } public String getCollectByOpenRange(boolean left, boolean strict) { if (collectByOpenRangeTemplate == null) { collectByOpenRangeTemplate = builder.buildSelectByOpenRangeTemplate(entityName, fieldName, false); } return builder.formatOpenRangeTemplate(collectByOpenRangeTemplate, left, strict); } public String getSelectByClosedRange(boolean leftStrict, boolean rightStrict) { if (selectByClosedRangeTemplate == null) { selectByClosedRangeTemplate = builder.buildSelectByClosedRangeTemplate(entityName, fieldName, true); } return builder.formatClosedRangeTemplate(selectByClosedRangeTemplate, leftStrict, rightStrict); } public String getCollectByClosedRange(boolean leftStrict, boolean rightStrict) { if (collectByClosedRangeTemplate == null) { collectByClosedRangeTemplate = builder.buildSelectByClosedRangeTemplate(entityName, fieldName, false); } return builder.formatClosedRangeTemplate(collectByClosedRangeTemplate, leftStrict, rightStrict); } }
Java
package com.anli.busstation.dal.jpa.queries; import javax.inject.Singleton; @Singleton public class JpqlQueryBuilder { protected static final String ID = "id"; protected void appendSelectAndFrom(StringBuilder clause, String entityName, String entityAlias, boolean full) { clause.append("select distinct ").append(entityAlias); if (!full) { clause.append(".").append(ID); } clause.append(" from ").append(entityName).append(" ").append(entityAlias); } protected void appendBinaryOperatorCondition(StringBuilder clause, String entityAlias, String fieldName, String operator, int parameterNumber) { clause.append(entityAlias).append(".").append(fieldName).append(" ") .append(operator).append(" ?").append(parameterNumber); } protected void appendIsNullCondition(StringBuilder clause, String entityAlias, String fieldName) { clause.append(entityAlias).append(".").append(fieldName) .append(" is null"); } protected void appendMemberOfCondition(StringBuilder clause, String entityAlias, String fieldName, int parameterNumber) { clause.append("?").append(parameterNumber).append(" member of ") .append(entityAlias).append(".").append(fieldName); } protected String buildSelectBySingleBinaryOperator(String entityName, String fieldName, String operator, boolean full) { StringBuilder query = new StringBuilder(); String entityAlias = entityName.toLowerCase(); appendSelectAndFrom(query, entityName, entityAlias, full); query.append(" where "); appendBinaryOperatorCondition(query, entityAlias, fieldName, operator, 1); return query.toString(); } public String buildSelectAllQuery(String entityName, boolean full) { StringBuilder query = new StringBuilder(); String entityAlias = entityName.toLowerCase(); appendSelectAndFrom(query, entityName, entityAlias, full); return query.toString(); } public String buildSelectByEqualsQuery(String entityName, String fieldName, boolean full) { return buildSelectBySingleBinaryOperator(entityName, fieldName, "=", full); } public String buildSelectByNullQuery(String entityName, String fieldName, boolean full) { StringBuilder query = new StringBuilder(); String entityAlias = entityName.toLowerCase(); appendSelectAndFrom(query, entityName, entityAlias, full); query.append(" where "); appendIsNullCondition(query, entityAlias, fieldName); return query.toString(); } public String buildSelectByOpenRangeTemplate(String entityName, String fieldName, boolean full) { return buildSelectBySingleBinaryOperator(entityName, fieldName, "%s", full); } public String buildSelectByAnyQuery(String entityName, String fieldName, boolean full) { return buildSelectBySingleBinaryOperator(entityName, fieldName, "IN", full); } public String buildSelectByRegexpQuery(String entityName, String fieldName, boolean full) { return buildSelectBySingleBinaryOperator(entityName, fieldName, "REGEXP", full); } public String buildSelectByContainsQuery(String entityName, String fieldName, boolean full) { StringBuilder query = new StringBuilder(); String entityAlias = entityName.toLowerCase(); appendSelectAndFrom(query, entityName, entityAlias, full); query.append(" where "); appendMemberOfCondition(query, entityAlias, fieldName, 1); return query.toString(); } public String buildSelectByClosedRangeTemplate(String entityName, String fieldName, boolean full) { StringBuilder query = new StringBuilder(); String entityAlias = entityName.toLowerCase(); appendSelectAndFrom(query, entityName, entityAlias, full); query.append(" where "); appendBinaryOperatorCondition(query, entityAlias, fieldName, "%s", 1); query.append(" and "); appendBinaryOperatorCondition(query, entityAlias, fieldName, "%s", 2); return query.toString(); } public String formatOpenRangeTemplate(String template, boolean left, boolean strict) { return String.format(template, left ? buildGreaterOperator(strict) : buildLessOperator(strict)); } public String formatClosedRangeTemplate(String template, boolean leftStrict, boolean rightStrict) { return String.format(template, buildGreaterOperator(leftStrict), buildLessOperator(rightStrict)); } protected String buildGreaterOperator(boolean strict) { return ">" + (strict ? "" : "="); } protected String buildLessOperator(boolean strict) { return "<" + (strict ? "" : "="); } }
Java
package com.anli.busstation.dal.jpa.queries; import java.util.HashMap; import java.util.Map; public class EntityQueryHolder { protected final JpqlQueryBuilder builder; protected final String entityName; protected final Map<String, FieldQueryHolder> fieldHolders; protected String selectAll; protected String collectKeysAll; public EntityQueryHolder(JpqlQueryBuilder builder, String entityName) { this.builder = builder; this.entityName = entityName; this.fieldHolders = new HashMap<>(); } public String getSelectAll() { if (selectAll == null) { selectAll = builder.buildSelectAllQuery(entityName, true); } return selectAll; } public String getCollectKeysAll() { if (collectKeysAll == null) { collectKeysAll = builder.buildSelectAllQuery(entityName, false); } return collectKeysAll; } public FieldQueryHolder getFieldHolder(String fieldName) { FieldQueryHolder holder = fieldHolders.get(fieldName); if (holder == null) { holder = new FieldQueryHolder(builder, entityName, fieldName); fieldHolders.put(fieldName, holder); } return holder; } }
Java
package com.anli.busstation.dal.jpa.queries; import java.util.HashMap; import java.util.Map; import javax.inject.Inject; import javax.inject.Singleton; @Singleton public class QueryHolder { protected final JpqlQueryBuilder builder; protected final Map<String, EntityQueryHolder> holders; @Inject public QueryHolder(JpqlQueryBuilder builder) { this.builder = builder; this.holders = new HashMap<>(); } public EntityQueryHolder getHolder(String entityName) { EntityQueryHolder holder = holders.get(entityName); if (holder == null) { holder = new EntityQueryHolder(builder, entityName); holders.put(entityName, holder); } return holder; } }
Java
package com.anli.busstation.dal.ejb3.factories; import com.anli.busstation.dal.interfaces.providers.BSEntityProvider; import javax.naming.InitialContext; import javax.naming.NamingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ProviderFactory implements com.anli.busstation.dal.interfaces.factories.ProviderFactory { private static final Logger LOG = LoggerFactory.getLogger(ProviderFactory.class); @Override public <I extends BSEntityProvider> I getProvider(Class<I> abstraction) { try { return (I) InitialContext.doLookup(abstraction.getCanonicalName()); } catch (NamingException namingException) { LOG.error("Could not lookup provider", namingException); throw new RuntimeException(namingException); } } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.BusService; import com.anli.busstation.dal.interfaces.providers.maintenance.BusServiceProvider; import com.anli.busstation.dal.jpa.entities.maintenance.BusServiceImpl; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(BusServiceProvider.class) @TransactionAttribute(REQUIRED) public class BusServiceProviderBean extends AbstractBusServiceProviderBean<BusService, BusServiceImpl> implements BusServiceProvider { @Override protected BusServiceImpl getEntityInstance() { return null; } @Override protected Class<BusServiceImpl> getEntityClass() { return BusServiceImpl.class; } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.BusService; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.providers.maintenance.GenericBusServiceProvider; import com.anli.busstation.dal.jpa.entities.maintenance.BusServiceImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @TransactionAttribute(REQUIRED) public abstract class AbstractBusServiceProviderBean<I extends BusService, E extends BusServiceImpl> extends AbstractTechnicalAssignmentProviderBean<I, E> implements GenericBusServiceProvider<I> { @Override public List<I> findByBus(Bus bus) { return findByEquals("bus", bus); } @Override public List<I> findByAnyBus(Collection<Bus> buses) { return findByAny("bus", buses); } @Override public List<BigInteger> collectIdsByBus(Bus bus) { return collectIdsByEquals("bus", bus); } @Override public List<BigInteger> collectIdsByAnyBus(Collection<Bus> buses) { return collectIdsByAny("bus", buses); } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.BusRepairment; import com.anli.busstation.dal.interfaces.providers.maintenance.BusRepairmentProvider; import com.anli.busstation.dal.jpa.entities.maintenance.BusRepairmentImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(BusRepairmentProvider.class) @TransactionAttribute(REQUIRED) public class BusRepairmentProviderBean extends AbstractBusServiceProviderBean<BusRepairment, BusRepairmentImpl> implements BusRepairmentProvider { @Override protected BusRepairmentImpl getEntityInstance() { return new BusRepairmentImpl(); } @Override protected Class<BusRepairmentImpl> getEntityClass() { return BusRepairmentImpl.class; } @Override public List<BusRepairment> findByExpendablesPriceRange(BigDecimal expendablesPriceLeft, boolean strictLeft, BigDecimal expendablesPriceRight, boolean strictRight) { return findByRange("expendablesPrice", expendablesPriceLeft, strictLeft, expendablesPriceRight, strictRight); } @Override public List<BigInteger> collectIdsByExpendablesPriceRange(BigDecimal expendablesPriceLeft, boolean strictLeft, BigDecimal expendablesPriceRight, boolean strictRight) { return collectIdsByRange("expendablesPrice", expendablesPriceLeft, strictLeft, expendablesPriceRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.maintenance.TechnicalAssignment; import com.anli.busstation.dal.interfaces.entities.staff.Mechanic; import com.anli.busstation.dal.interfaces.providers.maintenance.GenericTechnicalAssignmentProvider; import com.anli.busstation.dal.jpa.entities.maintenance.TechnicalAssignmentImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.TransactionAttribute; import org.joda.time.DateTime; import static javax.ejb.TransactionAttributeType.REQUIRED; @TransactionAttribute(REQUIRED) public abstract class AbstractTechnicalAssignmentProviderBean<I extends TechnicalAssignment, E extends TechnicalAssignmentImpl> extends AbstractBSProviderBean<I, E> implements GenericTechnicalAssignmentProvider<I> { @Override public List<I> findByMechanic(Mechanic mechanic) { return findByEquals("mechanic", mechanic); } @Override public List<I> findByAnyMechanic(Collection<Mechanic> mechanics) { return findByAny("mechanic", mechanics); } @Override public List<I> findByBeginTimeRange(DateTime beginTimeLeft, boolean strictLeft, DateTime beginTimeRight, boolean strictRight) { return findByRange("beginTime", beginTimeLeft, strictLeft, beginTimeRight, strictRight); } @Override public List<I> findByEndTimeRange(DateTime endTimeLeft, boolean strictLeft, DateTime endTimeRight, boolean strictRight) { return findByRange("endTime", endTimeLeft, strictLeft, endTimeRight, strictRight); } @Override public List<I> findByServiceCostRange(BigDecimal serviceCostLeft, boolean strictLeft, BigDecimal serviceCostRight, boolean strictRight) { return findByRange("serviceCost", serviceCostLeft, strictLeft, serviceCostRight, strictRight); } @Override public List<BigInteger> collectIdsByMechanic(Mechanic mechanic) { return collectIdsByEquals("mechanic", mechanic); } @Override public List<BigInteger> collectIdsByAnyMechanic(Collection<Mechanic> mechanics) { return collectIdsByAny("mechanic", mechanics); } @Override public List<BigInteger> collectIdsByBeginTimeRange(DateTime beginTimeLeft, boolean strictLeft, DateTime beginTimeRight, boolean strictRight) { return collectIdsByRange("beginTime", beginTimeLeft, strictLeft, beginTimeRight, strictRight); } @Override public List<BigInteger> collectIdsByEndTimeRange(DateTime endTimeLeft, boolean strictLeft, DateTime endTimeRight, boolean strictRight) { return collectIdsByRange("endTime", endTimeLeft, strictLeft, endTimeRight, strictRight); } @Override public List<BigInteger> collectIdsByServiceCostRange(BigDecimal serviceCostLeft, boolean strictLeft, BigDecimal serviceCostRight, boolean strictRight) { return collectIdsByRange("serviceCost", serviceCostLeft, strictLeft, serviceCostRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.TechnicalAssignment; import com.anli.busstation.dal.interfaces.providers.maintenance.TechnicalAssignmentProvider; import com.anli.busstation.dal.jpa.entities.maintenance.TechnicalAssignmentImpl; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(TechnicalAssignmentProvider.class) @TransactionAttribute(REQUIRED) public class TechnicalAssignmentProviderBean extends AbstractTechnicalAssignmentProviderBean<TechnicalAssignment, TechnicalAssignmentImpl> implements TechnicalAssignmentProvider { @Override protected TechnicalAssignmentImpl getEntityInstance() { return null; } @Override protected Class<TechnicalAssignmentImpl> getEntityClass() { return TechnicalAssignmentImpl.class; } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.StationService; import com.anli.busstation.dal.interfaces.providers.maintenance.StationServiceProvider; import com.anli.busstation.dal.jpa.entities.maintenance.StationServiceImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(StationServiceProvider.class) @TransactionAttribute(REQUIRED) public class StationServiceProviderBean extends AbstractTechnicalAssignmentProviderBean<StationService, StationServiceImpl> implements StationServiceProvider { @Override protected StationServiceImpl getEntityInstance() { return new StationServiceImpl(); } @Override protected Class<StationServiceImpl> getEntityClass() { return StationServiceImpl.class; } @Override public List<StationService> findByDescriptionRegexp(String descriptionRegexp) { return findByRegexp("description", descriptionRegexp); } @Override public List<BigInteger> collectIdsByDescriptionRegexp(String descriptionRegexp) { return collectIdsByRegexp("description", descriptionRegexp); } }
Java
package com.anli.busstation.dal.ejb3.providers.maintenance; import com.anli.busstation.dal.interfaces.entities.maintenance.BusRefuelling; import com.anli.busstation.dal.interfaces.providers.maintenance.BusRefuellingProvider; import com.anli.busstation.dal.jpa.entities.maintenance.BusRefuellingImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(BusRefuellingProvider.class) @TransactionAttribute(REQUIRED) public class BusRefuellingProviderBean extends AbstractBusServiceProviderBean<BusRefuelling, BusRefuellingImpl> implements BusRefuellingProvider { @Override protected BusRefuellingImpl getEntityInstance() { return new BusRefuellingImpl(); } @Override protected Class<BusRefuellingImpl> getEntityClass() { return BusRefuellingImpl.class; } @Override public List<BusRefuelling> findByVolumeRange(Integer volumeLeft, boolean strictLeft, Integer volumeRight, boolean strictRight) { return findByRange("volume", volumeLeft, strictLeft, volumeRight, strictRight); } @Override public List<BigInteger> collectIdsByVolumeRange(Integer volumeLeft, boolean strictLeft, Integer volumeRight, boolean strictRight) { return collectIdsByRange("volume", volumeLeft, strictLeft, volumeRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.geography.Road; import com.anli.busstation.dal.interfaces.entities.staff.Driver; import com.anli.busstation.dal.interfaces.entities.traffic.RideRoad; import com.anli.busstation.dal.interfaces.providers.traffic.RideRoadProvider; import com.anli.busstation.dal.jpa.entities.traffic.RideRoadImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RideRoadProvider.class) @TransactionAttribute(REQUIRED) public class RideRoadProviderBean extends AbstractBSProviderBean<RideRoad, RideRoadImpl> implements RideRoadProvider { @Override protected RideRoadImpl getEntityInstance() { return new RideRoadImpl(); } @Override protected Class<RideRoadImpl> getEntityClass() { return RideRoadImpl.class; } @Override public List<RideRoad> findByRoad(Road road) { return findByEquals("road", road); } @Override public List<RideRoad> findByAnyRoad(Collection<Road> roads) { return findByAny("road", roads); } @Override public List<RideRoad> findByDriver(Driver driver) { return findByEquals("driver", driver); } @Override public List<RideRoad> findByAnyDriver(Collection<Driver> drivers) { return findByAny("driver", drivers); } @Override public List<BigInteger> collectIdsByRoad(Road road) { return collectIdsByEquals("road", road); } @Override public List<BigInteger> collectIdsByAnyRoad(Collection<Road> roads) { return collectIdsByAny("road", roads); } @Override public List<BigInteger> collectIdsByDriver(Driver driver) { return collectIdsByEquals("driver", driver); } @Override public List<BigInteger> collectIdsByAnyDriver(Collection<Driver> drivers) { return collectIdsByAny("driver", drivers); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.traffic.Ride; import com.anli.busstation.dal.interfaces.entities.traffic.Route; import com.anli.busstation.dal.interfaces.entities.traffic.RoutePoint; import com.anli.busstation.dal.interfaces.providers.traffic.RouteProvider; import com.anli.busstation.dal.jpa.entities.traffic.RouteImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RouteProvider.class) @TransactionAttribute(REQUIRED) public class RouteProviderBean extends AbstractBSProviderBean<Route, RouteImpl> implements RouteProvider { @Override protected RouteImpl getEntityInstance() { return new RouteImpl(); } @Override protected Class<RouteImpl> getEntityClass() { return RouteImpl.class; } @Override public Route pullRoutePoints(Route route) { RouteImpl originalRoute = (RouteImpl) route; RouteImpl reference = getEntityReference(originalRoute); originalRoute.setRoutePoints((List) getCloner() .cloneCollection(reference.getRoutePoints(), false)); return originalRoute; } @Override public Route pullRides(Route route) { RouteImpl originalRoute = (RouteImpl) route; RouteImpl reference = getEntityReference(originalRoute); originalRoute.setRides((List) getCloner() .cloneCollection(reference.getRides(), false)); return originalRoute; } @Override public List<Route> findByNumCode(String numCode) { return findByEquals("numCode", numCode); } @Override public List<Route> findByAnyNumCode(Collection<String> numCodes) { return findByAny("numCode", numCodes); } @Override public List<Route> findByTicketPriceRange(BigDecimal ticketPriceLeft, boolean strictLeft, BigDecimal ticketPriceRight, boolean strictRight) { return findByRange("ticketPrice", ticketPriceLeft, strictLeft, ticketPriceRight, strictRight); } @Override public List<Route> findByRoutePoint(RoutePoint routePoint) { return findByContains("routePoints", routePoint); } @Override public List<Route> findByAnyRoutePoint(Collection<RoutePoint> routePoints) { return findByAny("routePoints", routePoints); } @Override public List<Route> findByRide(Ride ride) { return findByContains("rides", ride); } @Override public List<Route> findByAnyRide(Collection<Ride> rides) { return findByAny("rides", rides); } @Override public List<BigInteger> collectIdsByNumCode(String numCode) { return collectIdsByEquals("numCode", numCode); } @Override public List<BigInteger> collectIdsByAnyNumCode(Collection<String> numCodes) { return collectIdsByAny("numCode", numCodes); } @Override public List<BigInteger> collectIdsByTicketPriceRange(BigDecimal ticketPriceLeft, boolean strictLeft, BigDecimal ticketPriceRight, boolean strictRight) { return collectIdsByRange("ticketPrice", ticketPriceLeft, strictLeft, ticketPriceRight, strictRight); } @Override public List<BigInteger> collectIdsByRoutePoint(RoutePoint routePoint) { return collectIdsByContains("routePoints", routePoint); } @Override public List<BigInteger> collectIdsByAnyRoutePoint(Collection<RoutePoint> routePoints) { return collectIdsByAny("routePoints", routePoints); } @Override public List<BigInteger> collectIdsByRide(Ride ride) { return collectIdsByContains("rides", ride); } @Override public List<BigInteger> collectIdsByAnyRide(Collection<Ride> rides) { return collectIdsByAny("rides", rides); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.traffic.Ride; import com.anli.busstation.dal.interfaces.entities.traffic.RidePoint; import com.anli.busstation.dal.interfaces.entities.traffic.RideRoad; import com.anli.busstation.dal.interfaces.entities.traffic.Ticket; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.providers.traffic.RideProvider; import com.anli.busstation.dal.jpa.entities.traffic.RideImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RideProvider.class) @TransactionAttribute(REQUIRED) public class RideProviderBean extends AbstractBSProviderBean<Ride, RideImpl> implements RideProvider { @Override protected RideImpl getEntityInstance() { return new RideImpl(); } @Override protected Class<RideImpl> getEntityClass() { return RideImpl.class; } @Override public Ride pullRidePoints(Ride ride) { RideImpl originalRide = (RideImpl) ride; RideImpl reference = getEntityReference(originalRide); originalRide.setRidePoints((List) getCloner() .cloneCollection(reference.getRidePoints(), false)); return originalRide; } @Override public Ride pullRideRoads(Ride ride) { RideImpl originalRide = (RideImpl) ride; RideImpl reference = getEntityReference(originalRide); originalRide.setRideRoads((List) getCloner() .cloneCollection(reference.getRideRoads(), false)); return originalRide; } @Override public Ride pullTickets(Ride ride) { RideImpl originalRide = (RideImpl) ride; RideImpl reference = getEntityReference(originalRide); originalRide.setTickets((List) getCloner() .cloneCollection(reference.getTickets(), false)); return originalRide; } @Override public List<Ride> findByBus(Bus bus) { return findByEquals("bus", bus); } @Override public List<Ride> findByAnyBus(Collection<Bus> buses) { return findByAny("bus", buses); } @Override public List<Ride> findByRidePoint(RidePoint ridePoint) { return findByContains("ridePoints", ridePoint); } @Override public List<Ride> findByAnyRidePoint(Collection<RidePoint> ridePoints) { return findByAny("ridePoints", ridePoints); } @Override public List<Ride> findByRideRoad(RideRoad rideRoad) { return findByContains("rideRoads", rideRoad); } @Override public List<Ride> findByAnyRideRoad(Collection<RideRoad> rideRoads) { return findByAny("rideRoads", rideRoads); } @Override public List<Ride> findByTicket(Ticket ticket) { return findByContains("tickets", ticket); } @Override public List<Ride> findByAnyTicket(Collection<Ticket> tickets) { return findByAny("tickets", tickets); } @Override public List<BigInteger> collectIdsByBus(Bus bus) { return collectIdsByEquals("bus", bus); } @Override public List<BigInteger> collectIdsByAnyBus(Collection<Bus> buses) { return collectIdsByAny("bus", buses); } @Override public List<BigInteger> collectIdsByRidePoint(RidePoint ridePoint) { return collectIdsByContains("ridePoints", ridePoint); } @Override public List<BigInteger> collectIdsByAnyRidePoint(Collection<RidePoint> ridePoints) { return collectIdsByAny("ridePoints", ridePoints); } @Override public List<BigInteger> collectIdsByRideRoad(RideRoad rideRoad) { return collectIdsByContains("rideRoads", rideRoad); } @Override public List<BigInteger> collectIdsByAnyRideRoad(Collection<RideRoad> rideRoads) { return collectIdsByAny("rideRoads", rideRoads); } @Override public List<BigInteger> collectIdsByTicket(Ticket ticket) { return collectIdsByContains("tickets", ticket); } @Override public List<BigInteger> collectIdsByAnyTicket(Collection<Ticket> tickets) { return collectIdsByAny("tickets", tickets); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.staff.Salesman; import com.anli.busstation.dal.interfaces.entities.traffic.RidePoint; import com.anli.busstation.dal.interfaces.entities.traffic.Ticket; import com.anli.busstation.dal.interfaces.providers.traffic.TicketProvider; import com.anli.busstation.dal.jpa.entities.traffic.TicketImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import org.joda.time.DateTime; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(TicketProvider.class) @TransactionAttribute(REQUIRED) public class TicketProviderBean extends AbstractBSProviderBean<Ticket, TicketImpl> implements TicketProvider { @Override protected TicketImpl getEntityInstance() { return new TicketImpl(); } @Override protected Class<TicketImpl> getEntityClass() { return TicketImpl.class; } @Override public List<Ticket> findByDeparturePoint(RidePoint departurePoint) { return findByEquals("departurePoint", departurePoint); } @Override public List<Ticket> findByAnyDeparturePoint(Collection<RidePoint> departurePoints) { return findByAny("departurePoint", departurePoints); } @Override public List<Ticket> findByArrivalPoint(RidePoint arrivalPoint) { return findByEquals("arrivalPoint", arrivalPoint); } @Override public List<Ticket> findByAnyArrivalPoint(Collection<RidePoint> arrivalPoints) { return findByAny("arrivalPoint", arrivalPoints); } @Override public List<Ticket> findBySeat(Integer seat) { return findByEquals("seat", seat); } @Override public List<Ticket> findBySeatRange(Integer seatLeft, boolean strictLeft, Integer seatRight, boolean strictRight) { return findByRange("seat", seatLeft, strictLeft, seatRight, strictRight); } @Override public List<Ticket> findBySalesman(Salesman salesman) { return findByEquals("salesman", salesman); } @Override public List<Ticket> findByAnySalesman(Collection<Salesman> salesmen) { return findByAny("salesman", salesmen); } @Override public List<Ticket> findBySaleDateRange(DateTime saleDateLeft, boolean strictLeft, DateTime saleDateRight, boolean strictRight) { return findByRange("saleDate", saleDateLeft, strictLeft, saleDateRight, strictRight); } @Override public List<Ticket> findByCustomerName(String customerName) { return findByEquals("customerName", customerName); } @Override public List<Ticket> findByCustomerNameRegexp(String customerNameRegexp) { return findByRegexp("customerName", customerNameRegexp); } @Override public List<Ticket> findByPriceRange(BigDecimal priceLeft, boolean strictLeft, BigDecimal priceRight, boolean strictRight) { return findByRange("price", priceLeft, strictLeft, priceRight, strictRight); } @Override public List<Ticket> findBySold(boolean sold) { return findByEquals("sold", sold); } @Override public List<BigInteger> collectIdsByDeparturePoint(RidePoint departurePoint) { return collectIdsByEquals("departurePoint", departurePoint); } @Override public List<BigInteger> collectIdsByAnyDeparturePoint(Collection<RidePoint> departurePoints) { return collectIdsByAny("departurePoint", departurePoints); } @Override public List<BigInteger> collectIdsByArrivalPoint(RidePoint arrivalPoint) { return collectIdsByEquals("arrivalPoint", arrivalPoint); } @Override public List<BigInteger> collectIdsByAnyArrivalPoint(Collection<RidePoint> arrivalPoints) { return collectIdsByAny("arrivalPoint", arrivalPoints); } @Override public List<BigInteger> collectIdsBySeat(Integer seat) { return collectIdsByEquals("seat", seat); } @Override public List<BigInteger> collectIdsBySeatRange(Integer seatLeft, boolean strictLeft, Integer seatRight, boolean strictRight) { return collectIdsByRange("seat", seatLeft, strictLeft, seatRight, strictRight); } @Override public List<BigInteger> collectIdsBySalesman(Salesman salesman) { return collectIdsByEquals("salesman", salesman); } @Override public List<BigInteger> collectIdsByAnySalesman(Collection<Salesman> salesmen) { return collectIdsByAny("salesman", salesmen); } @Override public List<BigInteger> collectIdsBySaleDateRange(DateTime saleDateLeft, boolean strictLeft, DateTime saleDateRight, boolean strictRight) { return collectIdsByRange("saleDate", saleDateLeft, strictLeft, saleDateRight, strictRight); } @Override public List<BigInteger> collectIdsByCustomerName(String customerName) { return collectIdsByEquals("customerName", customerName); } @Override public List<BigInteger> collectIdsByCustomerNameRegexp(String customerNameRegexp) { return collectIdsByRegexp("customerName", customerNameRegexp); } @Override public List<BigInteger> collectIdsByPriceRange(BigDecimal priceLeft, boolean strictLeft, BigDecimal priceRight, boolean strictRight) { return collectIdsByRange("price", priceLeft, strictLeft, priceRight, strictRight); } @Override public List<BigInteger> collectIdsBySold(boolean sold) { return collectIdsByEquals("sold", sold); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.traffic.RidePoint; import com.anli.busstation.dal.interfaces.entities.traffic.RoutePoint; import com.anli.busstation.dal.interfaces.providers.traffic.RidePointProvider; import com.anli.busstation.dal.jpa.entities.traffic.RidePointImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import org.joda.time.DateTime; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RidePointProvider.class) @TransactionAttribute(REQUIRED) public class RidePointProviderBean extends AbstractBSProviderBean<RidePoint, RidePointImpl> implements RidePointProvider { @Override protected RidePointImpl getEntityInstance() { return new RidePointImpl(); } @Override protected Class<RidePointImpl> getEntityClass() { return RidePointImpl.class; } @Override public List<RidePoint> findByRoutePoint(RoutePoint routePoint) { return findByEquals("routePoint", routePoint); } @Override public List<RidePoint> findByAnyRoutePoint(Collection<RoutePoint> routePoints) { return findByAny("routePoint", routePoints); } @Override public List<RidePoint> findByArrivalTimeRange(DateTime arrivalTimeLeft, boolean strictLeft, DateTime arrivalTimeRight, boolean strictRight) { return findByRange("arrivalTime", arrivalTimeLeft, strictLeft, arrivalTimeRight, strictRight); } @Override public List<RidePoint> findByDepartureTimeRange(DateTime departureTimeLeft, boolean strictLeft, DateTime departureTimeRight, boolean strictRight) { return findByRange("departureTime", departureTimeLeft, strictLeft, departureTimeRight, strictRight); } @Override public List<BigInteger> collectIdsByRoutePoint(RoutePoint routePoint) { return collectIdsByEquals("routePoint", routePoint); } @Override public List<BigInteger> collectIdsByAnyRoutePoint(Collection<RoutePoint> routePoints) { return collectIdsByAny("routePoint", routePoints); } @Override public List<BigInteger> collectIdsByArrivalTimeRange(DateTime arrivalTimeLeft, boolean strictLeft, DateTime arrivalTimeRight, boolean strictRight) { return collectIdsByRange("arrivalTime", arrivalTimeLeft, strictLeft, arrivalTimeRight, strictRight); } @Override public List<BigInteger> collectIdsByDepartureTimeRange(DateTime departureTimeLeft, boolean strictLeft, DateTime departureTimeRight, boolean strictRight) { return collectIdsByRange("departureTime", departureTimeLeft, strictLeft, departureTimeRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.traffic; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.interfaces.entities.traffic.RoutePoint; import com.anli.busstation.dal.interfaces.providers.traffic.RoutePointProvider; import com.anli.busstation.dal.jpa.entities.traffic.RoutePointImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RoutePointProvider.class) @TransactionAttribute(REQUIRED) public class RoutePointProviderBean extends AbstractBSProviderBean<RoutePoint, RoutePointImpl> implements RoutePointProvider { @Override protected RoutePointImpl getEntityInstance() { return new RoutePointImpl(); } @Override protected Class<RoutePointImpl> getEntityClass() { return RoutePointImpl.class; } @Override public List<RoutePoint> findByStation(Station station) { return findByEquals("station", station); } @Override public List<RoutePoint> findByAnyStation(Collection<Station> stations) { return findByAny("station", stations); } @Override public List<BigInteger> collectIdsByStation(Station station) { return collectIdsByEquals("station", station); } @Override public List<BigInteger> collectIdsByAnyStation(Collection<Station> stations) { return collectIdsByAny("station", stations); } }
Java
package com.anli.busstation.dal.ejb3.providers; import com.anli.busstation.dal.ejb3.exceptions.ManageableConsistencyException; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.providers.BSEntityProvider; import com.anli.busstation.dal.jpa.entities.BSEntityImpl; import com.anli.busstation.dal.jpa.queries.EntityQueryHolder; import com.anli.busstation.dal.jpa.queries.FieldQueryHolder; import com.anli.busstation.dal.jpa.queries.QueryHolder; import com.anli.busstation.dal.jpa.reflective.EntityCloner; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import javax.ejb.TransactionAttribute; import javax.inject.Inject; import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.EntityNotFoundException; import javax.persistence.PersistenceContext; import javax.persistence.Query; import javax.persistence.TypedQuery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static javax.ejb.TransactionAttributeType.REQUIRED; @TransactionAttribute(REQUIRED) public abstract class AbstractBSProviderBean<I extends BSEntity, E extends BSEntityImpl> implements BSEntityProvider<I> { private static final Logger LOG = LoggerFactory.getLogger(AbstractBSProviderBean.class); @PersistenceContext(unitName = "busstation") protected EntityManager manager; @Inject protected QueryHolder queryHolder; @Inject protected EntityCloner cloner; protected abstract E getEntityInstance(); protected abstract Class<E> getEntityClass(); protected EntityManager getManager() { return manager; } protected QueryHolder getQueryHolder() { return queryHolder; } protected EntityCloner getCloner() { return cloner; } protected EntityQueryHolder getEntityQueryHolder() { String entityName = getEntityClass().getAnnotation(Entity.class).name(); return getQueryHolder().getHolder(entityName); } protected void setQueryParameters(Query query, Collection parameters) { if (parameters == null) { return; } int index = 0; for (Object param : parameters) { index++; query.setParameter(index, param); } } protected <T> List<T> selectByQuery(String query, Collection parameters, Class<T> type) { return selectByQuery(query, parameters, type, false); } protected <T> List<T> selectByQuery(String query, Collection parameters, Class<T> type, boolean named) { TypedQuery<T> typedQuery; if (named) { typedQuery = getManager().createNamedQuery(query, type); } else { typedQuery = getManager().createQuery(query, type); } setQueryParameters(typedQuery, parameters); return typedQuery.getResultList(); } protected List<I> findByQuery(String query, Collection parameters) { return findByQuery(query, parameters, false); } protected List<I> findByQuery(String query, Collection parameters, boolean named) { return (List) getCloner().cloneCollection(selectByQuery(query, parameters, getEntityClass(), named)); } protected List<BigInteger> collectIdsByQuery(String query, Collection parameters) { return collectIdsByQuery(query, parameters, false); } protected List<BigInteger> collectIdsByQuery(String query, Collection parameters, boolean named) { return selectByQuery(query, parameters, BigInteger.class, named); } protected List<I> findByEquals(String field, Object value) { FieldQueryHolder fieldHolder = getEntityQueryHolder().getFieldHolder(field); if (value != null) { return findByQuery(fieldHolder.getSelectByEquals(), Arrays.asList(value)); } else { return findByQuery(fieldHolder.getSelectByNull(), null); } } protected List<BigInteger> collectIdsByEquals(String field, Object value) { FieldQueryHolder fieldHolder = getEntityQueryHolder().getFieldHolder(field); if (value != null) { return collectIdsByQuery(fieldHolder.getCollectByEquals(), Arrays.asList(value)); } else { return collectIdsByQuery(fieldHolder.getCollectByNull(), null); } } protected List<I> findByAny(String field, Collection values) { if (values == null || values.isEmpty()) { return new LinkedList<>(); } String query = getEntityQueryHolder().getFieldHolder(field).getSelectByAny(); return findByQuery(query, Arrays.asList(values)); } protected List<BigInteger> collectIdsByAny(String field, Collection values) { if (values == null || values.isEmpty()) { return new LinkedList<>(); } String query = getEntityQueryHolder().getFieldHolder(field).getCollectByAny(); return collectIdsByQuery(query, Arrays.asList(values)); } protected List<I> findByContains(String field, Object value) { if (value == null) { return new LinkedList<>(); } String query = getEntityQueryHolder().getFieldHolder(field).getSelectByContains(); return findByQuery(query, Arrays.asList(value)); } protected List<BigInteger> collectIdsByContains(String field, Object value) { if (value == null) { return new LinkedList<>(); } String query = getEntityQueryHolder().getFieldHolder(field).getCollectByContains(); return collectIdsByQuery(query, Arrays.asList(value)); } protected List<I> findByRegexp(String field, String regexp) { String query = getEntityQueryHolder().getFieldHolder(field).getSelectByRegexp(); return findByQuery(query, Arrays.asList(regexp)); } protected List<BigInteger> collectIdsByRegexp(String field, String regexp) { String query = getEntityQueryHolder().getFieldHolder(field).getCollectByRegexp(); return collectIdsByQuery(query, Arrays.asList(regexp)); } protected List<I> findByRange(String field, Object leftValue, boolean leftStrict, Object rightValue, boolean rightStrict) { if (leftValue == null && rightValue == null) { return findAll(); } FieldQueryHolder holder = getEntityQueryHolder().getFieldHolder(field); String query; ArrayList parameters = new ArrayList(2); boolean isLeft = leftValue != null; boolean isRight = rightValue != null; if (!isLeft || !isRight) { query = holder.getSelectByOpenRange(isLeft, isLeft ? leftStrict : rightStrict); } else { query = holder.getSelectByClosedRange(leftStrict, rightStrict); } if (isLeft) { parameters.add(leftValue); } if (isRight) { parameters.add(rightValue); } return findByQuery(query, parameters); } protected List<BigInteger> collectIdsByRange(String field, Object leftValue, boolean leftStrict, Object rightValue, boolean rightStrict) { if (leftValue == null && rightValue == null) { return collectIdsAll(); } FieldQueryHolder holder = getEntityQueryHolder().getFieldHolder(field); String query; ArrayList parameters = new ArrayList(2); boolean isLeft = leftValue != null; boolean isRight = rightValue != null; if (!isLeft || !isRight) { query = holder.getCollectByOpenRange(isLeft, isLeft ? leftStrict : rightStrict); } else { query = holder.getCollectByClosedRange(leftStrict, rightStrict); } if (isLeft) { parameters.add(leftValue); } if (isRight) { parameters.add(rightValue); } return collectIdsByQuery(query, parameters); } protected E getEntityReference(E entity) { E reference = getManager().find(getEntityClass(), entity.getId()); if (reference == null) { throw new ManageableConsistencyException(Collections .<BSEntity>singletonList(entity), null); } return reference; } @Override public I create() { E entity = getEntityInstance(); if (entity == null) { return null; } getManager().persist(entity); return (I) getCloner().clone(entity); } @Override public I save(I entity) { E concreteEntity = (E) entity; E reference = getEntityReference(concreteEntity); List inconsistent = getCloner().populateEntity(concreteEntity, reference, getManager()); if (!inconsistent.isEmpty()) { LOG.error("Could not find entities : " + inconsistent); throw new ManageableConsistencyException((Collection) inconsistent, null); } return entity; } @Override public void remove(I entity) { E concreteEntity = (E) entity; E toRemove = getEntityReference(concreteEntity); getManager().remove(toRemove); } @Override public I findById(BigInteger id) { if (id == null) { return null; } return (I) getCloner().clone(getManager().find(getEntityClass(), id)); } @Override public List<I> findAll() { return findByQuery(getEntityQueryHolder().getSelectAll(), null); } @Override public List<BigInteger> collectIdsAll() { return collectIdsByQuery(getEntityQueryHolder().getCollectKeysAll(), null); } }
Java
package com.anli.busstation.dal.ejb3.providers.geography; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.geography.Region; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.interfaces.providers.geography.RegionProvider; import com.anli.busstation.dal.jpa.entities.geography.RegionImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RegionProvider.class) @TransactionAttribute(REQUIRED) public class RegionProviderBean extends AbstractBSProviderBean<Region, RegionImpl> implements RegionProvider { @Override protected RegionImpl getEntityInstance() { return new RegionImpl(); } @Override protected Class<RegionImpl> getEntityClass() { return RegionImpl.class; } @Override public Region pullStations(Region region) { RegionImpl originalRegion = (RegionImpl) region; RegionImpl reference = getEntityReference(originalRegion); originalRegion.setStations((List) getCloner() .cloneCollection(reference.getStations(), false)); return originalRegion; } @Override public List<Region> findByName(String name) { return findByEquals("name", name); } @Override public List<Region> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<Region> findByCode(Integer code) { return findByEquals("code", code); } @Override public List<Region> findByAnyCode(Collection<Integer> codes) { return findByAny("code", codes); } @Override public List<Region> findByStation(Station station) { return findByContains("stations", station); } @Override public List<Region> findByAnyStation(Collection<Station> stations) { return findByAny("stations", stations); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsByCode(Integer code) { return collectIdsByEquals("code", code); } @Override public List<BigInteger> collectIdsByAnyCode(Collection<Integer> codes) { return collectIdsByAny("code", codes); } @Override public List<BigInteger> collectIdsByStation(Station station) { return collectIdsByContains("stations", station); } @Override public List<BigInteger> collectIdsByAnyStation(Collection<Station> stations) { return collectIdsByAny("stations", stations); } }
Java
package com.anli.busstation.dal.ejb3.providers.geography; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.providers.geography.StationProvider; import com.anli.busstation.dal.jpa.entities.geography.StationImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(StationProvider.class) @TransactionAttribute(REQUIRED) public class StationProviderBean extends AbstractBSProviderBean<Station, StationImpl> implements StationProvider { @Override protected StationImpl getEntityInstance() { return new StationImpl(); } @Override protected Class<StationImpl> getEntityClass() { return StationImpl.class; } @Override public Station pullEmployees(Station station) { StationImpl originalStation = (StationImpl) station; StationImpl reference = getEntityReference(originalStation); originalStation.setEmployees((List) getCloner() .cloneCollection(reference.getEmployees(), false)); return originalStation; } @Override public Station pullBuses(Station station) { StationImpl originalStation = (StationImpl) station; StationImpl reference = getEntityReference(originalStation); originalStation.setBuses((List) getCloner() .cloneCollection(reference.getBuses(), false)); return originalStation; } @Override public List<Station> findByName(String name) { return findByEquals("name", name); } @Override public List<Station> findByNameRegexp(String regexpName) { return findByRegexp("name", regexpName); } @Override public List<Station> findByLatitudeRange(BigDecimal latitudeLeft, boolean strictLeft, BigDecimal latitudeRight, boolean strictRight) { return findByRange("latitude", latitudeLeft, strictLeft, latitudeRight, strictRight); } @Override public List<Station> findByLongitudeRange(BigDecimal longitudeLeft, boolean strictLeft, BigDecimal longitudeRight, boolean strictRight) { return findByRange("longitude", longitudeLeft, strictLeft, longitudeRight, strictRight); } @Override public List<Station> findByEmployee(Employee employee) { return findByContains("employees", employee); } @Override public List<Station> findByAnyEmployee(Collection<Employee> employees) { return findByAny("employees", employees); } @Override public List<Station> findByBus(Bus bus) { return findByContains("buses", bus); } @Override public List<Station> findByAnyBus(Collection<Bus> buses) { return findByAny("buses", buses); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String regexpName) { return collectIdsByRegexp("name", regexpName); } @Override public List<BigInteger> collectIdsByLatitudeRange(BigDecimal latitudeLeft, boolean strictLeft, BigDecimal latitudeRight, boolean strictRight) { return collectIdsByRange("latitude", latitudeLeft, strictLeft, latitudeRight, strictRight); } @Override public List<BigInteger> collectIdsByLongitudeRange(BigDecimal longitudeLeft, boolean strictLeft, BigDecimal longitudeRight, boolean strictRight) { return collectIdsByRange("longitude", longitudeLeft, strictLeft, longitudeRight, strictRight); } @Override public List<BigInteger> collectIdsByEmployee(Employee employee) { return collectIdsByContains("employees", employee); } @Override public List<BigInteger> collectIdsByAnyEmployee(Collection<Employee> employees) { return collectIdsByAny("employees", employees); } @Override public List<BigInteger> collectIdsByBus(Bus bus) { return collectIdsByContains("buses", bus); } @Override public List<BigInteger> collectIdsByAnyBus(Collection<Bus> buses) { return collectIdsByAny("buses", buses); } }
Java
package com.anli.busstation.dal.ejb3.providers.geography; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.geography.Road; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.interfaces.providers.geography.RoadProvider; import com.anli.busstation.dal.jpa.entities.geography.RoadImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.Collections; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(RoadProvider.class) @TransactionAttribute(REQUIRED) public class RoadProviderBean extends AbstractBSProviderBean<Road, RoadImpl> implements RoadProvider { @Override protected RoadImpl getEntityInstance() { return new RoadImpl(); } @Override protected Class<RoadImpl> getEntityClass() { return RoadImpl.class; } @Override public List<Road> findByAStation(Station aStation) { return findByEquals("aStation", aStation); } @Override public List<Road> findByAnyAStation(Collection<Station> aStations) { return findByAny("aStation", aStations); } @Override public List<Road> findByZStation(Station zStation) { return findByEquals("zStation", zStation); } @Override public List<Road> findByAnyZStation(Collection<Station> zStations) { return findByAny("zStation", zStations); } @Override public List<Road> findByStation(Station station) { if (station == null) { return findByQuery("Road.findByNullStation", Collections.emptyList(), true); } else { return findByQuery("Road.findByStation", Collections.singletonList(station), true); } } @Override public List<Road> findByAnyStation(Collection<Station> stations) { if (stations == null || stations.isEmpty()) { return Collections.emptyList(); } else { return findByQuery("Road.findByAnyStation", Collections.singletonList(stations), true); } } @Override public List<Road> findByLengthRange(Integer lengthLeft, boolean strictLeft, Integer lengthRight, boolean strictRight) { return findByRange("length", lengthLeft, strictLeft, lengthRight, strictRight); } @Override public List<Road> findByRidePriceRange(BigDecimal ridePriceLeft, boolean strictLeft, BigDecimal ridePriceRight, boolean strictRight) { return findByRange("ridePrice", ridePriceLeft, strictLeft, ridePriceRight, strictRight); } @Override public List<BigInteger> collectIdsByAStation(Station aStation) { return collectIdsByEquals("aStation", aStation); } @Override public List<BigInteger> collectIdsByAnyAStation(Collection<Station> aStations) { return collectIdsByAny("aStation", aStations); } @Override public List<BigInteger> collectIdsByZStation(Station zStation) { return collectIdsByEquals("zStation", zStation); } @Override public List<BigInteger> collectIdsByAnyZStation(Collection<Station> zStations) { return collectIdsByAny("zStation", zStations); } @Override public List<BigInteger> collectIdsByStation(Station station) { if (station == null) { return collectIdsByQuery("Road.collectIdsByNullStation", Collections.emptyList(), true); } else { return collectIdsByQuery("Road.collectIdsByStation", Collections.singletonList(station), true); } } @Override public List<BigInteger> collectIdsByAnyStation(Collection<Station> stations) { if (stations == null || stations.isEmpty()) { return Collections.emptyList(); } else { return collectIdsByQuery("Road.collectIdsByAnyStation", Collections.singletonList(stations), true); } } @Override public List<BigInteger> collectIdsByLengthRange(Integer lengthLeft, boolean strictLeft, Integer lengthRight, boolean strictRight) { return collectIdsByRange("length", lengthLeft, strictLeft, lengthRight, strictRight); } @Override public List<BigInteger> collectIdsByRidePriceRange(BigDecimal ridePriceLeft, boolean strictLeft, BigDecimal ridePriceRight, boolean strictRight) { return collectIdsByRange("ridePrice", ridePriceLeft, strictLeft, ridePriceRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.interfaces.providers.staff.GenericEmployeeProvider; import com.anli.busstation.dal.jpa.entities.staff.EmployeeImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.List; import javax.ejb.TransactionAttribute; import org.joda.time.DateTime; import static javax.ejb.TransactionAttributeType.REQUIRED; @TransactionAttribute(REQUIRED) public abstract class AbstractEmployeeProviderBean<I extends Employee, E extends EmployeeImpl> extends AbstractBSProviderBean<I, E> implements GenericEmployeeProvider<I> { @Override public List<I> findByName(String name) { return findByEquals("name", name); } @Override public List<I> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<I> findBySalaryRange(BigDecimal salaryLeft, boolean strictLeft, BigDecimal salaryRight, boolean strictRight) { return findByRange("salary", salaryLeft, strictLeft, salaryRight, strictRight); } @Override public List<I> findByHiringDateRange(DateTime hiringDateLeft, boolean strictLeft, DateTime hiringDateRight, boolean strictRight) { return findByRange("hiringDate", hiringDateLeft, strictLeft, hiringDateRight, strictRight); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsBySalaryRange(BigDecimal salaryLeft, boolean strictLeft, BigDecimal salaryRight, boolean strictRight) { return collectIdsByRange("salary", salaryLeft, strictLeft, salaryRight, strictRight); } @Override public List<BigInteger> collectIdsByHiringDateRange(DateTime hiringDateLeft, boolean strictLeft, DateTime hiringDateRight, boolean strictRight) { return collectIdsByRange("hiringDate", hiringDateLeft, strictLeft, hiringDateRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.interfaces.providers.staff.EmployeeProvider; import com.anli.busstation.dal.jpa.entities.staff.EmployeeImpl; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(EmployeeProvider.class) @TransactionAttribute(REQUIRED) public class EmployeeProviderBean extends AbstractEmployeeProviderBean<Employee, EmployeeImpl> implements EmployeeProvider { @Override protected EmployeeImpl getEntityInstance() { return null; } @Override protected Class<EmployeeImpl> getEntityClass() { return EmployeeImpl.class; } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.interfaces.entities.staff.Mechanic; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import com.anli.busstation.dal.interfaces.providers.staff.MechanicProvider; import com.anli.busstation.dal.jpa.entities.staff.MechanicImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(MechanicProvider.class) @TransactionAttribute(REQUIRED) public class MechanicProviderBean extends AbstractEmployeeProviderBean<Mechanic, MechanicImpl> implements MechanicProvider { @Override protected MechanicImpl getEntityInstance() { return new MechanicImpl(); } @Override protected Class<MechanicImpl> getEntityClass() { return MechanicImpl.class; } @Override public List<Mechanic> findBySkill(MechanicSkill skill) { return findByEquals("skill", skill); } @Override public List<Mechanic> findByAnySkill(Collection<MechanicSkill> skills) { return findByAny("skill", skills); } @Override public List<BigInteger> collectIdsBySkill(MechanicSkill skill) { return collectIdsByEquals("skill", skill); } @Override public List<BigInteger> collectIdsByAnySkill(Collection<MechanicSkill> skills) { return collectIdsByAny("skill", skills); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import com.anli.busstation.dal.interfaces.providers.staff.DriverSkillProvider; import com.anli.busstation.dal.jpa.entities.staff.DriverSkillImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(DriverSkillProvider.class) @TransactionAttribute(REQUIRED) public class DriverSkillProviderBean extends AbstractBSProviderBean<DriverSkill, DriverSkillImpl> implements DriverSkillProvider { @Override protected DriverSkillImpl getEntityInstance() { return new DriverSkillImpl(); } @Override protected Class<DriverSkillImpl> getEntityClass() { return DriverSkillImpl.class; } @Override public List<DriverSkill> findByName(String name) { return findByEquals("name", name); } @Override public List<DriverSkill> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<DriverSkill> findByMaxRideLengthRange(Integer maxRideLengthLeft, boolean strictLeft, Integer maxRideLengthRight, boolean strictRight) { return findByRange("maxRideLength", maxRideLengthLeft, strictLeft, maxRideLengthRight, strictRight); } @Override public List<DriverSkill> findByMaxPassengersRange(Integer maxPassengersLeft, boolean strictLeft, Integer maxPassengersRight, boolean strictRight) { return findByRange("maxPassengers", maxPassengersLeft, strictLeft, maxPassengersRight, strictRight); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsByMaxRideLengthRange(Integer maxRideLengthLeft, boolean strictLeft, Integer maxRideLengthRight, boolean strictRight) { return collectIdsByRange("maxRideLength", maxRideLengthLeft, strictLeft, maxRideLengthRight, strictRight); } @Override public List<BigInteger> collectIdsByMaxPassengersRange(Integer maxPassengersLeft, boolean strictLeft, Integer maxPassengersRight, boolean strictRight) { return collectIdsByRange("maxPassengers", maxPassengersLeft, strictLeft, maxPassengersRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.interfaces.entities.staff.Driver; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import com.anli.busstation.dal.interfaces.providers.staff.DriverProvider; import com.anli.busstation.dal.jpa.entities.staff.DriverImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(DriverProvider.class) @TransactionAttribute(REQUIRED) public class DriverProviderBean extends AbstractEmployeeProviderBean<Driver, DriverImpl> implements DriverProvider { @Override protected DriverImpl getEntityInstance() { return new DriverImpl(); } @Override protected Class<DriverImpl> getEntityClass() { return DriverImpl.class; } @Override public List<Driver> findBySkill(DriverSkill skill) { return findByEquals("skill", skill); } @Override public List<Driver> findByAnySkill(Collection<DriverSkill> skills) { return findByAny("skill", skills); } @Override public List<BigInteger> collectIdsBySkill(DriverSkill skill) { return collectIdsByEquals("skill", skill); } @Override public List<BigInteger> collectIdsByAnySkill(Collection<DriverSkill> skills) { return collectIdsByAny("skill", skills); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.interfaces.entities.staff.Salesman; import com.anli.busstation.dal.interfaces.providers.staff.SalesmanProvider; import com.anli.busstation.dal.jpa.entities.staff.SalesmanImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(SalesmanProvider.class) @TransactionAttribute(REQUIRED) public class SalesmanProviderBean extends AbstractEmployeeProviderBean<Salesman, SalesmanImpl> implements SalesmanProvider { @Override protected SalesmanImpl getEntityInstance() { return new SalesmanImpl(); } @Override protected Class<SalesmanImpl> getEntityClass() { return SalesmanImpl.class; } @Override public List<Salesman> findByTotalSalesRange(Integer totalSalesLeft, boolean strictLeft, Integer totalSalesRight, boolean strictRight) { return findByRange("totalSales", totalSalesLeft, strictLeft, totalSalesRight, strictRight); } @Override public List<BigInteger> collectIdsByTotalSalesRange(Integer totalSalesLeft, boolean strictLeft, Integer totalSalesRight, boolean strictRight) { return collectIdsByRange("totalSales", totalSalesLeft, strictLeft, totalSalesRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.staff; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import com.anli.busstation.dal.interfaces.providers.staff.MechanicSkillProvider; import com.anli.busstation.dal.jpa.entities.staff.MechanicSkillImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(MechanicSkillProvider.class) @TransactionAttribute(REQUIRED) public class MechanicSkillProviderBean extends AbstractBSProviderBean<MechanicSkill, MechanicSkillImpl> implements MechanicSkillProvider { @Override protected MechanicSkillImpl getEntityInstance() { return new MechanicSkillImpl(); } @Override protected Class<MechanicSkillImpl> getEntityClass() { return MechanicSkillImpl.class; } @Override public List<MechanicSkill> findByName(String name) { return findByEquals("name", name); } @Override public List<MechanicSkill> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<MechanicSkill> findByMaxDiffLevelRange(Integer maxDiffLevelLeft, boolean strictLeft, Integer maxDiffLevelRight, boolean strictRight) { return findByRange("maxDiffLevel", maxDiffLevelLeft, strictLeft, maxDiffLevelRight, strictRight); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsByMaxDiffLevelRange(Integer maxDiffLevelLeft, boolean strictLeft, Integer maxDiffLevelRight, boolean strictRight) { return collectIdsByRange("maxDiffLevel", maxDiffLevelLeft, strictLeft, maxDiffLevelRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.vehicles; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import com.anli.busstation.dal.interfaces.providers.vehicles.ModelProvider; import com.anli.busstation.dal.jpa.entities.vehicles.ModelImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(ModelProvider.class) @TransactionAttribute(REQUIRED) public class ModelProviderBean extends AbstractBSProviderBean<Model, ModelImpl> implements ModelProvider { @Override protected ModelImpl getEntityInstance() { return new ModelImpl(); } @Override protected Class<ModelImpl> getEntityClass() { return ModelImpl.class; } @Override public List<Model> findByName(String name) { return findByEquals("name", name); } @Override public List<Model> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<Model> findBySeatsNumberRange(Integer seatsNumberLeft, boolean strictLeft, Integer seatsNumberRight, boolean strictRight) { return findByRange("seatsNumber", seatsNumberLeft, strictLeft, seatsNumberRight, strictRight); } @Override public List<Model> findByTankVolumeRange(Integer tankVolumeLeft, boolean strictLeft, Integer tankVolumeRight, boolean strictRight) { return findByRange("tankVolume", tankVolumeLeft, strictLeft, tankVolumeRight, strictRight); } @Override public List<Model> findByGasLabel(GasLabel gasLabel) { return findByEquals("gasLabel", gasLabel); } @Override public List<Model> findByAnyGasLabel(Collection<GasLabel> gasLabels) { return findByAny("gasLabel", gasLabels); } @Override public List<Model> findByGasRateRange(BigDecimal gasRateLeft, boolean strictLeft, BigDecimal gasRateRight, boolean strictRight) { return findByRange("gasRate", gasRateLeft, strictLeft, gasRateRight, strictRight); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsBySeatsNumberRange(Integer seatsNumberLeft, boolean strictLeft, Integer seatsNumberRight, boolean strictRight) { return collectIdsByRange("seatsNumber", seatsNumberLeft, strictLeft, seatsNumberRight, strictRight); } @Override public List<BigInteger> collectIdsByGasLabel(GasLabel gasLabel) { return collectIdsByEquals("gasLabel", gasLabel); } @Override public List<BigInteger> collectIdsByAnyGasLabel(Collection<GasLabel> gasLabels) { return collectIdsByAny("gasLabel", gasLabels); } @Override public List<BigInteger> collectIdsByGasRateRange(BigDecimal gasRateLeft, boolean strictLeft, BigDecimal gasRateRight, boolean strictRight) { return collectIdsByRange("gasRate", gasRateLeft, strictLeft, gasRateRight, strictRight); } @Override public List<BigInteger> collectIdsByTankVolumeRange(Integer tankVolumeLeft, boolean strictLeft, Integer tankVolumeRight, boolean strictRight) { return collectIdsByRange("tankVolume", tankVolumeLeft, strictLeft, tankVolumeRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.vehicles; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import com.anli.busstation.dal.interfaces.providers.vehicles.BusProvider; import com.anli.busstation.dal.jpa.entities.vehicles.BusImpl; import java.math.BigInteger; import java.util.Collection; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(BusProvider.class) @TransactionAttribute(REQUIRED) public class BusProviderBean extends AbstractBSProviderBean<Bus, BusImpl> implements BusProvider { @Override protected BusImpl getEntityInstance() { return new BusImpl(); } @Override protected Class<BusImpl> getEntityClass() { return BusImpl.class; } @Override public List<Bus> findByModel(Model model) { return findByEquals("model", model); } @Override public List<Bus> findByAnyModel(Collection<Model> models) { return findByAny("model", models); } @Override public List<Bus> findByState(TechnicalState state) { return findByEquals("state", state); } @Override public List<Bus> findByAnyState(Collection<TechnicalState> states) { return findByAny("state", states); } @Override public List<Bus> findByPlate(String plate) { return findByEquals("plate", plate); } @Override public List<BigInteger> collectIdsByModel(Model model) { return collectIdsByEquals("model", model); } @Override public List<BigInteger> collectIdsByAnyModel(Collection<Model> models) { return collectIdsByAny("model", models); } @Override public List<BigInteger> collectIdsByState(TechnicalState state) { return collectIdsByEquals("state", state); } @Override public List<BigInteger> collectIdsByAnyState(Collection<TechnicalState> states) { return collectIdsByAny("state", states); } @Override public List<BigInteger> collectIdsByPlate(String plate) { return collectIdsByEquals("plate", plate); } }
Java
package com.anli.busstation.dal.ejb3.providers.vehicles; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import com.anli.busstation.dal.interfaces.providers.vehicles.GasLabelProvider; import com.anli.busstation.dal.jpa.entities.vehicles.GasLabelImpl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(GasLabelProvider.class) @TransactionAttribute(REQUIRED) public class GasLabelProviderBean extends AbstractBSProviderBean<GasLabel, GasLabelImpl> implements GasLabelProvider { @Override protected GasLabelImpl getEntityInstance() { return new GasLabelImpl(); } @Override protected Class<GasLabelImpl> getEntityClass() { return GasLabelImpl.class; } @Override public List<GasLabel> findByName(String name) { return findByEquals("name", name); } @Override public List<GasLabel> findByNameRegexp(String nameRegexp) { return findByRegexp("name", nameRegexp); } @Override public List<GasLabel> findByPriceRange(BigDecimal priceLeft, boolean strictLeft, BigDecimal priceRight, boolean strictRight) { return findByRange("price", priceLeft, strictLeft, priceRight, strictRight); } @Override public List<BigInteger> collectIdsByName(String name) { return collectIdsByEquals("name", name); } @Override public List<BigInteger> collectIdsByNameRegexp(String nameRegexp) { return collectIdsByRegexp("name", nameRegexp); } @Override public List<BigInteger> collectIdsByPriceRange(BigDecimal priceLeft, boolean strictLeft, BigDecimal priceRight, boolean strictRight) { return collectIdsByRange("price", priceLeft, strictLeft, priceRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.providers.vehicles; import com.anli.busstation.dal.ejb3.providers.AbstractBSProviderBean; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import com.anli.busstation.dal.interfaces.providers.vehicles.TechnicalStateProvider; import com.anli.busstation.dal.jpa.entities.vehicles.TechnicalStateImpl; import java.math.BigInteger; import java.util.List; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.ejb.TransactionAttribute; import static javax.ejb.TransactionAttributeType.REQUIRED; @Stateless @Remote(TechnicalStateProvider.class) @TransactionAttribute(REQUIRED) public class TechnicalStateProviderBean extends AbstractBSProviderBean<TechnicalState, TechnicalStateImpl> implements TechnicalStateProvider { @Override protected TechnicalStateImpl getEntityInstance() { return new TechnicalStateImpl(); } @Override protected Class<TechnicalStateImpl> getEntityClass() { return TechnicalStateImpl.class; } @Override public List<TechnicalState> findByDescriptionRegexp(String descriptionRegexp) { return findByRegexp("description", descriptionRegexp); } @Override public List<TechnicalState> findByDifficultyLevel(Integer difficultyLevel) { return findByEquals("difficultyLevel", difficultyLevel); } @Override public List<TechnicalState> findByDifficultyLevelRange(Integer difficultyLevelLeft, boolean strictLeft, Integer difficultyLevelRight, boolean strictRight) { return findByRange("difficultyLevel", difficultyLevelLeft, strictLeft, difficultyLevelRight, strictRight); } @Override public List<BigInteger> collectIdsByDescriptionRegexp(String descriptionRegexp) { return collectIdsByRegexp("description", descriptionRegexp); } @Override public List<BigInteger> collectIdsByDifficultyLevel(Integer difficultyLevel) { return collectIdsByEquals("difficultyLevel", difficultyLevel); } @Override public List<BigInteger> collectIdsByDifficultyLevelRange(Integer difficultyLevelLeft, boolean strictLeft, Integer difficultyLevelRight, boolean strictRight) { return collectIdsByRange("difficultyLevel", difficultyLevelLeft, strictLeft, difficultyLevelRight, strictRight); } }
Java
package com.anli.busstation.dal.ejb3.exceptions; import com.anli.busstation.dal.exceptions.ConsistencyException; import com.anli.busstation.dal.interfaces.entities.BSEntity; import java.util.Collection; import javax.ejb.ApplicationException; @ApplicationException(rollback = true) public class ManageableConsistencyException extends ConsistencyException { public ManageableConsistencyException(Collection<BSEntity> inconsistentEntities, Throwable cause) { super(inconsistentEntities, cause); } }
Java
package com.anli.busstation.dal.test.servlet; import com.anli.integrationtesting.Test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public abstract class AbstractTester extends HttpServlet { protected static final String TEMPLATE_PATH = "/template.html"; protected static final String TESTS_EXPRESSION = "${tests}"; protected static final String URL_EXPRESSION = "${url}"; protected static final String TITLE_EXPRESSION = "${title}"; protected static final List<String> vehiclesTests = Arrays.asList("GasLabelTest", "TechnicalStateTest", "ModelTest", "BusTest"); protected static final List<String> staffTests = Arrays.asList("DriverSkillTest", "MechanicSkillTest", "SalesmanTest", "DriverTest", "MechanicTest", "EmployeeTest"); protected static final List<String> geographyTests = Arrays .asList("StationTest", "RegionTest", "RoadTest"); protected static final List<String> maintenanceTests = Arrays.asList("BusRepairmentTest", "BusRefuellingTest", "BusServiceTest", "StationServiceTest", "TechnicalAssignmentTest"); protected static final List<String> trafficTests = Arrays.asList("RoutePointTest", "RidePointTest", "RideRoadTest", "TicketTest", "RideTest", "RouteTest"); protected static final List<String> additionalTests = Arrays.asList("ReferenceMutationTest", "ConsistencyTest", "TransactionTest", "ThreadingTest"); @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); String resultHtml = getHtml(request.getServletContext()); out.print(resultHtml); } protected String getHtml(ServletContext context) throws IOException { String template = getTemplateHtml(context); return getEvaluatedHtml(template, getTestList(), getExecutorUrl(), getTitle()); } protected String getTestList() { ArrayList<Test> testList = new ArrayList<>(); for (String vehiclesTest : vehiclesTests) { testList.add(new Test(vehiclesTest, getBasePackage() + ".vehicles." + vehiclesTest)); } for (String staffTest : staffTests) { testList.add(new Test(staffTest, getBasePackage() + ".staff." + staffTest)); } for (String geographyTest : geographyTests) { testList.add(new Test(geographyTest, getBasePackage() + ".geography." + geographyTest)); } for (String maintenanceTest : maintenanceTests) { testList.add(new Test(maintenanceTest, getBasePackage() + ".maintenance." + maintenanceTest)); } for (String trafficTest : trafficTests) { testList.add(new Test(trafficTest, getBasePackage() + ".traffic." + trafficTest)); } for (String additionalTest : additionalTests) { testList.add(new Test(additionalTest, getBasePackage() + ".additional." + additionalTest)); } StringBuilder builder = new StringBuilder(); builder.append("["); boolean isFirst = true; for (Test test : testList) { if (!isFirst) { builder.append(", "); } else { isFirst = false; } builder.append(test.toJson()); } return builder.append("]").toString(); } protected String getTemplateHtml(ServletContext context) throws IOException { InputStream templateStream = context.getResourceAsStream(TEMPLATE_PATH); BufferedReader templateReader = new BufferedReader(new InputStreamReader(templateStream)); StringBuilder templateHtml = new StringBuilder(); String line = templateReader.readLine(); while (line != null) { templateHtml.append(line).append("\n"); line = templateReader.readLine(); } return templateHtml.toString(); } protected String getEvaluatedHtml(String template, String tests, String url, String title) { return template.replace(TESTS_EXPRESSION, tests) .replace(URL_EXPRESSION, url) .replace(TITLE_EXPRESSION, title); } protected abstract String getBasePackage(); protected abstract String getExecutorUrl(); protected abstract String getTitle(); }
Java
package com.anli.busstation.dal.test; import com.anli.busstation.dal.interfaces.entities.BSEntity; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; public abstract class BasicDataAccessTestSceleton<I extends BSEntity> extends AbstractDataAccessTest { protected static volatile long currentId = 1001L; protected static synchronized BigInteger generateId() { BigInteger id = BigInteger.valueOf(currentId); currentId++; return id; } @Override public void test() throws Exception { clearStorageSpace(); resetCaches(); createPrerequisites(); testCreation(); testReading(); testUpdate(); testDeletion(); clearStorageSpace(); resetCaches(); createPrerequisites(); testPulling(); clearStorageSpace(); resetCaches(); createPrerequisites(); testCollecting(); clearStorageSpace(); resetCaches(); createPrerequisites(); testSearch(); } protected abstract BigInteger createEntityByProvider(I entity) throws Exception; protected abstract I getEntityByProvider(BigInteger id) throws Exception; protected abstract void updateEntityByProvider(BigInteger id, I data) throws Exception; protected abstract void deleteEntityByProvider(BigInteger id) throws Exception; protected abstract List<List<I>> performSearches() throws Exception; protected abstract List<List<BigInteger>> performCollectings() throws Exception; protected abstract BigInteger createEntityManually(I entity) throws Exception; protected abstract I getEntityManually(BigInteger id) throws Exception; protected abstract List<I> getCreationTestSets() throws Exception; protected abstract List<I> getUpdateTestSets() throws Exception; protected abstract List<I> getSearchTestSets() throws Exception; protected abstract List<int[]> getExpectedSearchSets(); protected abstract List<int[]> getExpectedCollectingSets(); protected abstract void clearStorageSpace() throws Exception; protected List<I> getPullEtalons() throws Exception { return Collections.emptyList(); } protected I pull(I entity, int index) { return entity; } protected boolean hasCollections() { return false; } protected void createPrerequisites() throws Exception { } protected void testCreation() throws Exception { List<I> testEntities = getCreationTestSets(); for (I testEntity : testEntities) { BigInteger id = createEntityByProvider(testEntity); setEntityId(testEntity, id); I actualEntity = getEntityManually(id); assertEntity(testEntity, actualEntity); } } protected void testReading() throws Exception { List<I> testEntities = getCreationTestSets(); for (I testEntity : testEntities) { BigInteger id = createEntityManually(testEntity); setEntityId(testEntity, id); nullifyCollections(testEntity); I actualEntity = getEntityByProvider(id); assertEntity(testEntity, actualEntity); } } protected void testPulling() throws Exception { if (!hasCollections()) { return; } List<I> testEntities = getCreationTestSets(); int index = 0; List<I> pullEtalons = getPullEtalons(); Iterator<I> pullIter = pullEtalons.iterator(); for (I testEntity : testEntities) { BigInteger id = createEntityManually(testEntity); I pullEtalon = pullIter.next(); setEntityId(pullEtalon, id); I pulled = pull(getEntityByProvider(id), index); assertEntity(pullEtalon, pulled); index++; } } protected void testUpdate() throws Exception { List<I> creationEntities = getCreationTestSets(); List<BigInteger> createdIds = new ArrayList<>(creationEntities.size()); for (I creationEntity : creationEntities) { createdIds.add(createEntityManually(creationEntity)); } List<I> testEntities = getUpdateTestSets(); Iterator<I> testEntityIter = testEntities.iterator(); Iterator<BigInteger> idIter = createdIds.iterator(); while (testEntityIter.hasNext()) { BigInteger id = idIter.next(); I testEntity = testEntityIter.next(); setEntityId(testEntity, id); updateEntityByProvider(id, testEntity); I actualEntity = getEntityManually(id); assertEntity(testEntity, actualEntity); } } protected void testDeletion() throws Exception { List<I> creationEntities = getCreationTestSets(); List<BigInteger> createdIds = new ArrayList<>(creationEntities.size()); for (I creationEntity : creationEntities) { createdIds.add(createEntityManually(creationEntity)); } for (BigInteger id : createdIds) { deleteEntityByProvider(id); BSEntity actualEntity = getEntityManually(id); if (actualEntity != null) { throw new AssertionError("Expected null Actual " + actualEntity); } } } protected void testSearch() throws Exception { List<I> searchEntities = getSearchTestSets(); List<I> createdEntities = new ArrayList<>(searchEntities.size()); for (I searchEntity : searchEntities) { createdEntities.add(getEntityManually(createEntityManually(searchEntity))); } List<List<I>> rawExpected = getEntitiesByIndices(getExpectedSearchSets(), createdEntities); List<List<I>> expected = new ArrayList<>(rawExpected.size()); for (List<I> set : rawExpected) { expected.add(nullifyCollections(set)); } List<List<I>> actual = performSearches(); Iterator<List<I>> expectedIter = expected.iterator(); Iterator<List<I>> actualIter = actual.iterator(); int setNumber = 0; while (expectedIter.hasNext() && actualIter.hasNext()) { List<I> expectedList = expectedIter.next(); List<I> actualList = actualIter.next(); assertUnorderedEntityList(expectedList, actualList, setNumber); setNumber++; } if (expectedIter.hasNext() || actualIter.hasNext()) { throw new AssertionError("Search set size Expected " + expected.size() + "Actual" + actual.size()); } } protected List<List<I>> getEntitiesByIndices(List<int[]> indices, List<I> entities) { List<List<I>> setList = new ArrayList<>(indices.size()); for (int[] indexSet : indices) { List<I> entitySet = new ArrayList<>(indexSet.length); for (int index : indexSet) { entitySet.add(entities.get(index)); } setList.add(entitySet); } return setList; } protected List<List<BigInteger>> getIdsByIndices(List<int[]> indices, List<BigInteger> ids) { List<List<BigInteger>> setList = new ArrayList<>(indices.size()); for (int[] indexSet : indices) { List<BigInteger> idSet = new ArrayList<>(indexSet.length); for (int index : indexSet) { idSet.add(ids.get(index)); } setList.add(idSet); } return setList; } protected void testCollecting() throws Exception { List<I> searchSets = getSearchTestSets(); List<BigInteger> createdIds = new ArrayList<>(searchSets.size()); for (I searchSet : searchSets) { createdIds.add(createEntityManually(searchSet)); } List<List<BigInteger>> expected = getIdsByIndices(getExpectedCollectingSets(), createdIds); List<List<BigInteger>> actual = performCollectings(); Iterator<List<BigInteger>> expectedIter = expected.iterator(); Iterator<List<BigInteger>> actualIter = actual.iterator(); int setNumber = 0; while (expectedIter.hasNext() && actualIter.hasNext()) { List<BigInteger> expectedList = expectedIter.next(); List<BigInteger> actualList = actualIter.next(); Collections.sort(expectedList); Collections.sort(actualList); if (!expectedList.equals(actualList)) { throw new AssertionError("Set number " + setNumber + " Expected " + expected + " Actual " + actual); } setNumber++; } if (expectedIter.hasNext() || actualIter.hasNext()) { throw new AssertionError("Search set size Expected " + expected.size() + "Actual" + actual.size()); } } protected void assertUnorderedEntityList(List<I> expected, List<I> actual, int setNumber) { Collections.sort(expected, new IdComparator()); Collections.sort(actual, new IdComparator()); Iterator<I> expectedIter = expected.iterator(); Iterator<I> actualIter = actual.iterator(); int count = 0; while (expectedIter.hasNext() && actualIter.hasNext()) { I expectedEntity = expectedIter.next(); I acutalEntity = actualIter.next(); if (!expectedEntity.deepEquals(acutalEntity)) { throw new AssertionError("Set number " + setNumber + " Expected " + expected + " Actual " + actual + " on " + count + " item"); } count++; } if (expectedIter.hasNext() || actualIter.hasNext()) { throw new AssertionError("Set number " + setNumber + " Expected " + expected + " Actual " + actual + " Expected length " + expected.size() + " Actual length " + actual.size()); } } protected void assertEntity(I expected, I actual) { boolean success; if (expected != null) { success = expected.deepEquals(actual); } else { success = (actual == null); } if (!success) { throw new AssertionError("Expected " + expected + " Actual " + actual); } } protected List<I> nullifyCollections(List<I> entities) { ArrayList<I> result = new ArrayList<>(entities.size()); for (I entity : entities) { result.add(nullifyCollections(entity)); } return result; } protected abstract I nullifyCollections(I entity); protected class IdComparator implements Comparator<I> { @Override public int compare(I first, I second) { return first.getId().compareTo(second.getId()); } } }
Java
package com.anli.busstation.dal.test; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.entities.geography.Road; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.interfaces.entities.staff.Driver; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import com.anli.busstation.dal.interfaces.entities.staff.Employee; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import com.anli.busstation.dal.interfaces.entities.staff.Mechanic; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import com.anli.busstation.dal.interfaces.entities.staff.Salesman; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.interfaces.entities.traffic.Ride; import com.anli.busstation.dal.interfaces.entities.traffic.RidePoint; import com.anli.busstation.dal.interfaces.entities.traffic.RideRoad; import com.anli.busstation.dal.interfaces.entities.traffic.RoutePoint; import com.anli.busstation.dal.interfaces.entities.traffic.Ticket; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import com.anli.busstation.dal.interfaces.factories.ProviderFactory; import com.anli.busstation.dal.interfaces.providers.geography.RoadProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.BusProvider; import com.anli.busstation.dal.interfaces.providers.staff.DriverProvider; import com.anli.busstation.dal.interfaces.providers.staff.DriverSkillProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.GasLabelProvider; import com.anli.busstation.dal.interfaces.providers.staff.MechanicProvider; import com.anli.busstation.dal.interfaces.providers.staff.MechanicSkillProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.ModelProvider; import com.anli.busstation.dal.interfaces.providers.staff.SalesmanProvider; import com.anli.busstation.dal.interfaces.providers.geography.StationProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RidePointProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RideProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RideRoadProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RoutePointProvider; import com.anli.busstation.dal.interfaces.providers.traffic.TicketProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.TechnicalStateProvider; import java.math.BigDecimal; import java.math.BigInteger; import java.util.HashMap; import java.util.List; import java.util.Map; import org.joda.time.DateTime; public abstract class FixtureCreator { protected abstract ProviderFactory getFactory(); protected abstract void setIdManually(BSEntity entity, BigInteger id); public Map<BigInteger, GasLabel> createGasLabelFixture(int minId, int count) { GasLabelProvider glProvider = getFactory().getProvider(GasLabelProvider.class); Map<BigInteger, GasLabel> gasLabels = new HashMap<>(); for (int i = 0; i < count; i++) { GasLabel gasLabel = glProvider.findById(BigInteger.valueOf(minId + i)); if (gasLabel == null) { gasLabel = glProvider.create(); setIdManually(gasLabel, BigInteger.valueOf(minId + i)); gasLabel = glProvider.findById(BigInteger.valueOf(minId + i)); } gasLabel.setName("GL" + i); gasLabel.setPrice(BigDecimal.valueOf(30 + i)); gasLabel = glProvider.save(gasLabel); gasLabels.put(gasLabel.getId(), gasLabel); } return gasLabels; } public Map<BigInteger, TechnicalState> createTechnicalStateFixture(int minId, int count) { TechnicalStateProvider sProvider = getFactory().getProvider(TechnicalStateProvider.class); Map<BigInteger, TechnicalState> technicalStates = new HashMap<>(); for (int i = 0; i < count; i++) { TechnicalState state = sProvider.findById(BigInteger.valueOf(minId + i)); if (state == null) { state = sProvider.create(); setIdManually(state, BigInteger.valueOf(minId + i)); state = sProvider.findById(BigInteger.valueOf(minId + i)); } state.setDescription("Description " + i); state.setDifficultyLevel(i); state = sProvider.save(state); technicalStates.put(state.getId(), state); } return technicalStates; } public Map<BigInteger, Model> createModelFixture(int minId, int count, List<GasLabel> gasLabels) { ModelProvider mProvider = getFactory().getProvider(ModelProvider.class); Map<BigInteger, Model> models = new HashMap<>(); for (int i = 0; i < count; i++) { Model model = mProvider.findById(BigInteger.valueOf(minId + i)); if (model == null) { model = mProvider.create(); setIdManually(model, BigInteger.valueOf(minId + i)); model = mProvider.findById(BigInteger.valueOf(minId + i)); } model.setGasLabel(gasLabels.isEmpty() ? null : gasLabels.get(i % gasLabels.size())); model.setGasRate(BigDecimal.valueOf(50 + i * 10)); model.setName("Model " + i); model.setSeatsNumber(i * 10); model.setTankVolume(i * 15); model = mProvider.save(model); models.put(model.getId(), model); } return models; } public Map<BigInteger, DriverSkill> createDriverSkillFixture(int minId, int count) { DriverSkillProvider dsProvider = getFactory().getProvider(DriverSkillProvider.class); Map<BigInteger, DriverSkill> driverSkills = new HashMap<>(); for (int i = 0; i < count; i++) { DriverSkill skill = dsProvider.findById(BigInteger.valueOf(minId + i)); if (skill == null) { skill = dsProvider.create(); setIdManually(skill, BigInteger.valueOf(minId + i)); skill = dsProvider.findById(BigInteger.valueOf(minId + i)); } skill.setName("Skill " + i); skill.setMaxPassengers(20 + i * 3); skill.setMaxRideLength(1000 * i); skill = dsProvider.save(skill); driverSkills.put(skill.getId(), skill); } return driverSkills; } public Map<BigInteger, MechanicSkill> createMechanicSkillFixture(int minId, int count) { MechanicSkillProvider msProvider = getFactory().getProvider(MechanicSkillProvider.class); Map<BigInteger, MechanicSkill> mechanicSkills = new HashMap<>(); for (int i = 0; i < 5; i++) { MechanicSkill skill = msProvider.findById(BigInteger.valueOf(minId + i)); if (skill == null) { skill = msProvider.create(); setIdManually(skill, BigInteger.valueOf(minId + i)); skill = msProvider.findById(BigInteger.valueOf(minId + i)); } skill.setName("Skill " + i); skill.setMaxDiffLevel(i * 2); skill = msProvider.save(skill); mechanicSkills.put(skill.getId(), skill); } return mechanicSkills; } public Map<BigInteger, Bus> createBusFixture(int minId, int count, List<Model> models, List<TechnicalState> states) { BusProvider busProvider = getFactory().getProvider(BusProvider.class); Map<BigInteger, Bus> buses = new HashMap<>(); for (int i = 0; i < count; i++) { Bus bus = busProvider.findById(BigInteger.valueOf(minId + i)); if (bus == null) { bus = busProvider.create(); setIdManually(bus, BigInteger.valueOf(minId + i)); bus = busProvider.findById(BigInteger.valueOf(minId + i)); } bus.setModel(models.isEmpty() ? null : models.get(i % models.size())); bus.setPlate("P" + i * 100 + "LT"); bus.setState(states.isEmpty() ? null : states.get(i % states.size())); bus = busProvider.save(bus); buses.put(bus.getId(), bus); } return buses; } public Map<BigInteger, Driver> createDriverFixture(int minId, int count, List<DriverSkill> skills) { DriverProvider driverProvider = getFactory().getProvider(DriverProvider.class); Map<BigInteger, Driver> drivers = new HashMap<>(); for (int i = 0; i < count; i++) { Driver driver = driverProvider.findById(BigInteger.valueOf(minId + i)); if (driver == null) { driver = driverProvider.create(); setIdManually(driver, BigInteger.valueOf(minId + i)); driver = driverProvider.findById(BigInteger.valueOf(minId + i)); } driver.setHiringDate(new DateTime(1990 + i, i % 11 + 1, i % 29 + 1, 0, 0, 0, 0)); driver.setName("Driver " + i); driver.setSalary(BigDecimal.valueOf(i * 1000)); driver.setSkill(skills.isEmpty() ? null : skills.get(i % skills.size())); driver = driverProvider.save(driver); drivers.put(driver.getId(), driver); } return drivers; } public Map<BigInteger, Mechanic> createMechanicFixture(int minId, int count, List<MechanicSkill> skills) { MechanicProvider mechanicProvider = getFactory().getProvider(MechanicProvider.class); Map<BigInteger, Mechanic> mechanics = new HashMap<>(); for (int i = 0; i < count; i++) { Mechanic mechanic = mechanicProvider.findById(BigInteger.valueOf(minId + i)); if (mechanic == null) { mechanic = mechanicProvider.create(); setIdManually(mechanic, BigInteger.valueOf(minId + i)); mechanic = mechanicProvider.findById(BigInteger.valueOf(minId + i)); } mechanic.setHiringDate(new DateTime(1990 + i, i % 11 + 1, i % 29 + 1, 0, 0, 0, 0)); mechanic.setName("Mechanic " + i); mechanic.setSalary(BigDecimal.valueOf(i * 1000)); mechanic.setSkill(skills.isEmpty() ? null : skills.get(i % skills.size())); mechanic = mechanicProvider.save(mechanic); mechanics.put(mechanic.getId(), mechanic); } return mechanics; } public Map<BigInteger, Salesman> createSalesmanFixture(int minId, int count) { SalesmanProvider salesmanProvider = getFactory().getProvider(SalesmanProvider.class); Map<BigInteger, Salesman> salesmen = new HashMap<>(); for (int i = 0; i < count; i++) { Salesman salesman = salesmanProvider.findById(BigInteger.valueOf(minId + i)); if (salesman == null) { salesman = salesmanProvider.create(); setIdManually(salesman, BigInteger.valueOf(minId + i)); salesman = salesmanProvider.findById(BigInteger.valueOf(minId + i)); } salesman.setHiringDate(new DateTime(1990 + i, i % 11 + 1, i % 29 + 1, 0, 0, 0, 0)); salesman.setName("Mechanic " + i); salesman.setSalary(BigDecimal.valueOf(i * 1000)); salesman.setTotalSales(i * 150); salesman = salesmanProvider.save(salesman); salesmen.put(salesman.getId(), salesman); } return salesmen; } public Map<BigInteger, Station> createStationFixture(int minId, int count, List<Bus> buses, List<Employee> employees) { StationProvider stationProvider = getFactory().getProvider(StationProvider.class); Map<BigInteger, Station> stations = new HashMap<>(); for (int i = 0; i < count; i++) { Station station = stationProvider.findById(BigInteger.valueOf(minId + i)); if (station == null) { station = stationProvider.create(); setIdManually(station, BigInteger.valueOf(minId + i)); station = stationProvider.findById(BigInteger.valueOf(minId + i)); } station = stationProvider.pullBuses(station); station = stationProvider.pullEmployees(station); station.setLatitude(BigDecimal.valueOf(i * 10)); station.setLongitude(BigDecimal.valueOf(i * 25)); station.setName("Station " + i); station.getBuses().clear(); if (!buses.isEmpty()) { station.getBuses().addAll(buses.subList(i % buses.size(), i + 1)); } station.getEmployees().clear(); if (!employees.isEmpty()) { station.getEmployees().addAll(employees.subList(i % employees.size(), i + 1)); } station = stationProvider.save(station); stations.put(station.getId(), station); } return stations; } public Map<BigInteger, RoutePoint> createRoutePointFixture(int minId, int count, List<Station> stations) { RoutePointProvider routePointProvider = getFactory().getProvider(RoutePointProvider.class); Map<BigInteger, RoutePoint> routePoints = new HashMap<>(); for (int i = 0; i < count; i++) { RoutePoint routePoint = routePointProvider.findById(BigInteger.valueOf(minId + i)); if (routePoint == null) { routePoint = routePointProvider.create(); setIdManually(routePoint, BigInteger.valueOf(minId + i)); routePoint = routePointProvider.findById(BigInteger.valueOf(minId + i)); } routePoint.setStation(stations.isEmpty() ? null : stations.get(i % stations.size())); routePoint = routePointProvider.save(routePoint); routePoints.put(routePoint.getId(), routePoint); } return routePoints; } public Map<BigInteger, Road> createRoadFixture(int minId, int count, List<Station> stations) { RoadProvider roadProvider = getFactory().getProvider(RoadProvider.class); Map<BigInteger, Road> roads = new HashMap<>(); for (int i = 0; i < count; i++) { Road road = roadProvider.findById(BigInteger.valueOf(minId + i)); if (road == null) { road = roadProvider.create(); setIdManually(road, BigInteger.valueOf(minId + i)); road = roadProvider.findById(BigInteger.valueOf(minId + i)); } road.setAStation(stations.isEmpty() ? null : stations.get(i % stations.size())); road.setLength(i * 1000); road.setRidePrice(BigDecimal.valueOf(1000 / (i + 1))); road.setZStation(stations.isEmpty() ? null : stations.get((i + 1) % stations.size())); road = roadProvider.save(road); roads.put(road.getId(), road); } return roads; } public Map<BigInteger, RidePoint> createRidePointFixture(int minId, int count, List<RoutePoint> routePoints) { RidePointProvider ridePointProvider = getFactory().getProvider(RidePointProvider.class); Map<BigInteger, RidePoint> ridePoints = new HashMap<>(); for (int i = 0; i < count; i++) { RidePoint ridePoint = ridePointProvider.findById(BigInteger.valueOf(minId + i)); if (ridePoint == null) { ridePoint = ridePointProvider.create(); setIdManually(ridePoint, BigInteger.valueOf(minId + i)); ridePoint = ridePointProvider.findById(BigInteger.valueOf(minId + i)); } ridePoint.setArrivalTime(new DateTime(2015, i % 11 + 1, i % 29 + 1, i % 24, i % 60, 0, 0)); ridePoint.setDepartureTime(new DateTime(2015, i % 11 + 1, i % 29 + 1, (i + 2) % 24, (i + 20) % 60, 0, 0)); ridePoint.setRoutePoint(routePoints.isEmpty() ? null : routePoints.get(i % routePoints.size())); ridePoint = ridePointProvider.save(ridePoint); ridePoints.put(ridePoint.getId(), ridePoint); } return ridePoints; } public Map<BigInteger, RideRoad> createRideRoadFixture(int minId, int count, List<Driver> drivers, List<Road> roads) { RideRoadProvider rideRoadProvider = getFactory().getProvider(RideRoadProvider.class); Map<BigInteger, RideRoad> rideRoads = new HashMap<>(); for (int i = 0; i < count; i++) { RideRoad rideRoad = rideRoadProvider.findById(BigInteger.valueOf(minId + i)); if (rideRoad == null) { rideRoad = rideRoadProvider.create(); setIdManually(rideRoad, BigInteger.valueOf(minId + i)); rideRoad = rideRoadProvider.findById(BigInteger.valueOf(minId + i)); } rideRoad.setDriver(drivers.isEmpty() ? null : drivers.get(i % drivers.size())); rideRoad.setRoad(roads.isEmpty() ? null : roads.get(i % roads.size())); rideRoad = rideRoadProvider.save(rideRoad); rideRoads.put(rideRoad.getId(), rideRoad); } return rideRoads; } public Map<BigInteger, Ticket> createTicketFixture(int minId, int count, List<RidePoint> ridePoints, List<Salesman> salesmen) { TicketProvider ticketProvider = getFactory().getProvider(TicketProvider.class); Map<BigInteger, Ticket> tickets = new HashMap<>(); for (int i = 0; i < count; i++) { Ticket ticket = ticketProvider.findById(BigInteger.valueOf(minId + i)); if (ticket == null) { ticket = ticketProvider.create(); setIdManually(ticket, BigInteger.valueOf(minId + i)); ticket = ticketProvider.findById(BigInteger.valueOf(minId + i)); } ticket.setArrivalPoint(ridePoints.isEmpty() ? null : ridePoints.get(i % ridePoints.size())); ticket.setCustomerName("Customer " + i); ticket.setDeparturePoint(ridePoints.isEmpty() ? null : ridePoints.get(i % ridePoints.size())); ticket.setPrice(BigDecimal.valueOf(i * 100)); ticket.setSaleDate(new DateTime(2015, i % 11 + 1, i % 29 + 1, (i + 2) % 24, (i + 20) % 60, 0, 0)); ticket.setSalesman(salesmen.isEmpty() ? null : salesmen.get(i % salesmen.size())); ticket.setSeat(i + 5); ticket.setSold(i % 2 == 0); ticket = ticketProvider.save(ticket); tickets.put(ticket.getId(), ticket); } return tickets; } public Map<BigInteger, Ride> createRideFixture(int minId, int count, List<Bus> buses, List<RidePoint> ridePoints, List<RideRoad> rideRoads, List<Ticket> tickets) { RideProvider rideProvider = getFactory().getProvider(RideProvider.class); Map<BigInteger, Ride> rides = new HashMap<>(); for (int i = 0; i < count; i++) { Ride ride = rideProvider.findById(BigInteger.valueOf(minId + i)); if (ride == null) { ride = rideProvider.create(); setIdManually(ride, BigInteger.valueOf(minId + i)); ride = rideProvider.findById(BigInteger.valueOf(minId + i)); } ride = rideProvider.pullRidePoints(ride); ride = rideProvider.pullRideRoads(ride); ride = rideProvider.pullTickets(ride); ride.setBus(buses.isEmpty() ? null : buses.get(i % buses.size())); ride.getRidePoints().clear(); if (!ridePoints.isEmpty()) { ride.getRidePoints().addAll(ridePoints.subList(i % ridePoints.size(), i + 1)); } ride.getRideRoads().clear(); if (!rideRoads.isEmpty()) { ride.getRideRoads().addAll(rideRoads.subList(i % rideRoads.size(), i + 1)); } ride.getTickets().clear(); if (!tickets.isEmpty()) { ride.getTickets().addAll(tickets.subList(i % tickets.size(), i + 1)); } ride = rideProvider.save(ride); rides.put(ride.getId(), ride); } return rides; } }
Java
package com.anli.busstation.dal.test; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.busstation.dal.interfaces.factories.ProviderFactory; import java.math.BigInteger; public interface ModuleAccessor { ProviderFactory getProviderFactory(); FixtureCreator getFixtureCreator(); void resetCaches(); void setEntityId(BSEntity entity, BigInteger id); }
Java
package com.anli.busstation.dal.sql.idgeneration; import java.math.BigInteger; public interface IdGenerator { BigInteger generateId(); }
Java
package com.anli.busstation.dal.sql.idgeneration; import com.anli.sqlexecution.execution.SqlExecutor; import com.anli.sqlexecution.handling.ResultSetHandler; import com.anli.sqlexecution.handling.TransformingResultSet; import java.math.BigInteger; import java.sql.SQLException; import java.util.Arrays; import java.util.List; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; import javax.transaction.InvalidTransactionException; import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; import javax.transaction.Transaction; import javax.transaction.TransactionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class TableIdGenerator implements IdGenerator { private static final Logger LOG = LoggerFactory.getLogger(TableIdGenerator.class); private static final String SELECT_ID_QUERY = "select last_id from id_generation_sequences where entity = ?"; private static final String INCREMENT_ID_QUERY = "update id_generation_sequences set last_id = last_id + ? where entity = ?"; private static final String LAST_ID_COLUMN = "last_id"; private final SqlExecutor executor; private final TransactionManager manager; private final List incrementParameters; private final List selectParameters; private final IdSelector selector; public TableIdGenerator(SqlExecutor executor, TransactionManager manager, String name, int increment) { this.executor = executor; this.manager = manager; this.incrementParameters = Arrays.asList(increment, name); this.selectParameters = Arrays.asList(name); selector = new IdSelector(); } @Override public synchronized BigInteger generateId() { try { Transaction suspended = manager.suspend(); manager.begin(); BigInteger id = executor.executeSelect(SELECT_ID_QUERY, selectParameters, selector); executor.executeUpdate(INCREMENT_ID_QUERY, incrementParameters); manager.commit(); manager.resume(suspended); return id; } catch (SystemException | NotSupportedException | RollbackException | InvalidTransactionException | HeuristicMixedException | HeuristicRollbackException exception) { LOG.error("Id generation transaction exception", exception); throw new RuntimeException(exception); } } private static class IdSelector implements ResultSetHandler<BigInteger> { @Override public BigInteger handle(TransformingResultSet resultSet) throws SQLException { resultSet.next(); return resultSet.getValue(LAST_ID_COLUMN, BigInteger.class); } } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.BusRefuellingImpl; import com.anli.simpleorm.handling.EntityBuilder; public class BusRefuellingGateway extends AbstractBusServiceGateway<BusRefuellingImpl> { protected static final String BUS_REFUELLING = "BusRefuelling"; protected static final String VOLUME = "volume"; @Override public EntityBuilder<BusRefuellingImpl> getBuilder(String entityName) { if (BUS_REFUELLING.equals(entityName)) { return new BusRefuellingBuilder(); } return null; } @Override public Object extractSingle(BusRefuellingImpl entity, String entityName, String fieldName) { if (BUS_REFUELLING.equals(entityName)) { if (VOLUME.equals(fieldName)) { return entity.getVolume(); } } return super.extractSingle(entity, entityName, fieldName); } protected class BusRefuellingBuilder extends BusServiceBuilder { @Override protected BusRefuellingImpl getNewInstance() { return new BusRefuellingImpl(); } @Override protected String getEntityName() { return BUS_REFUELLING; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (BUS_REFUELLING.equals(entityName)) { if (VOLUME.equals(fieldName)) { getInstance().setVolume((Integer) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.BusRefuellingImpl; import com.anli.busstation.dal.ejb2.entities.maintenance.BusRepairmentImpl; import com.anli.busstation.dal.ejb2.entities.maintenance.BusServiceImpl; import com.anli.simpleorm.handling.EntityGateway; import com.anli.simpleorm.handling.SuperEntityGateway; import java.util.HashMap; public class BusServiceGateway extends SuperEntityGateway<BusServiceImpl> { public BusServiceGateway(BusRefuellingGateway busRefuelling, BusRepairmentGateway busRepairment) { super(new HashMap<Class<? extends BusServiceImpl>, EntityGateway<? extends BusServiceImpl>>()); mapping.put(BusRefuellingImpl.class, busRefuelling); mapping.put(BusRepairmentImpl.class, busRepairment); } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.BusServiceImpl; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.simpleorm.handling.EntityBuilder; public abstract class AbstractBusServiceGateway<Entity extends BusServiceImpl> extends AbstractTechnicalAssignmentGateway<Entity> { protected static final String BUS_SERVICE = "BusService"; protected static final String BUS = "bus"; @Override public Object extractSingle(Entity entity, String entityName, String fieldName) { if (BUS_SERVICE.equals(entityName)) { if (BUS.equals(fieldName)) { return getId(entity.getBus()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(Entity entity, String entityName, String fieldName) { if (BUS_SERVICE.equals(entityName)) { if (BUS.equals(fieldName)) { return entity.getBus(); } } return super.extractFullReference(entity, entityName, fieldName); } protected abstract class BusServiceBuilder extends TechnicalAssignmentBuilder { @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (BUS_SERVICE.equals(entityName)) { if (BUS.equals(fieldName)) { getInstance().setBus((Bus) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.BusServiceImpl; import com.anli.busstation.dal.ejb2.entities.maintenance.StationServiceImpl; import com.anli.busstation.dal.ejb2.entities.maintenance.TechnicalAssignmentImpl; import com.anli.simpleorm.handling.EntityGateway; import com.anli.simpleorm.handling.SuperEntityGateway; import java.util.HashMap; public class TechnicalAssignmentGateway extends SuperEntityGateway<TechnicalAssignmentImpl> { public TechnicalAssignmentGateway(BusServiceGateway busService, StationServiceGateway stationService) { super(new HashMap<Class<? extends TechnicalAssignmentImpl>, EntityGateway<? extends TechnicalAssignmentImpl>>()); mapping.put(BusServiceImpl.class, busService); mapping.put(StationServiceImpl.class, stationService); } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.BusRepairmentImpl; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; public class BusRepairmentGateway extends AbstractBusServiceGateway<BusRepairmentImpl> { protected static final String BUS_REPAIRMENT = "BusRepairment"; protected static final String EXPENDABLES_PRICE = "expendablesPrice"; @Override public EntityBuilder<BusRepairmentImpl> getBuilder(String entityName) { if (BUS_REPAIRMENT.equals(entityName)) { return new BusRepairmentBuilder(); } return null; } @Override public Object extractSingle(BusRepairmentImpl entity, String entityName, String fieldName) { if (BUS_REPAIRMENT.equals(entityName)) { if (EXPENDABLES_PRICE.equals(fieldName)) { return entity.getExpendablesPrice(); } } return super.extractSingle(entity, entityName, fieldName); } protected class BusRepairmentBuilder extends BusServiceBuilder { @Override protected BusRepairmentImpl getNewInstance() { return new BusRepairmentImpl(); } @Override protected String getEntityName() { return BUS_REPAIRMENT; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (BUS_REPAIRMENT.equals(entityName)) { if (EXPENDABLES_PRICE.equals(fieldName)) { getInstance().setExpendablesPrice((BigDecimal) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.TechnicalAssignmentImpl; import com.anli.busstation.dal.interfaces.entities.staff.Mechanic; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; import org.joda.time.DateTime; public abstract class AbstractTechnicalAssignmentGateway<Entity extends TechnicalAssignmentImpl> extends BSEntityGateway<Entity> { protected static final String TECHNICAL_ASSIGNMENT = "TechnicalAssignment"; protected static final String BEGIN_TIME = "beginTime"; protected static final String END_TIME = "endTime"; protected static final String MECHANIC = "mechanic"; protected static final String SERVICE_COST = "serviceCost"; @Override public Object extractSingle(Entity entity, String entityName, String fieldName) { if (TECHNICAL_ASSIGNMENT.equals(entityName)) { if (BEGIN_TIME.equals(fieldName)) { return entity.getBeginTime(); } if (END_TIME.equals(fieldName)) { return entity.getEndTime(); } if (MECHANIC.equals(fieldName)) { return getId(entity.getMechanic()); } if (SERVICE_COST.equals(fieldName)) { return entity.getServiceCost(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(Entity entity, String entityName, String fieldName) { if (TECHNICAL_ASSIGNMENT.equals(entityName)) { if (MECHANIC.equals(fieldName)) { return entity.getMechanic(); } } return super.extractFullReference(entity, entityName, fieldName); } protected abstract class TechnicalAssignmentBuilder extends BSEntityBuilder { @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (TECHNICAL_ASSIGNMENT.equals(entityName)) { if (BEGIN_TIME.equals(fieldName)) { getInstance().setBeginTime((DateTime) fieldValue); return this; } if (END_TIME.equals(fieldName)) { getInstance().setEndTime((DateTime) fieldValue); return this; } if (MECHANIC.equals(fieldName)) { getInstance().setMechanic((Mechanic) fieldValue); return this; } if (SERVICE_COST.equals(fieldName)) { getInstance().setServiceCost((BigDecimal) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.maintenance; import com.anli.busstation.dal.ejb2.entities.maintenance.StationServiceImpl; import com.anli.simpleorm.handling.EntityBuilder; public class StationServiceGateway extends AbstractTechnicalAssignmentGateway<StationServiceImpl> { protected static final String STATION_SERVICE = "StationService"; protected static final String DESCRIPTION = "description"; @Override public EntityBuilder<StationServiceImpl> getBuilder(String entityName) { if (STATION_SERVICE.equals(entityName)) { return new StationServiceBuilder(); } return null; } @Override public Object extractSingle(StationServiceImpl entity, String entityName, String fieldName) { if (STATION_SERVICE.equals(entityName)) { if (DESCRIPTION.equals(fieldName)) { return entity.getDescription(); } } return super.extractSingle(entity, entityName, fieldName); } protected class StationServiceBuilder extends TechnicalAssignmentBuilder { @Override protected StationServiceImpl getNewInstance() { return new StationServiceImpl(); } @Override protected String getEntityName() { return STATION_SERVICE; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (STATION_SERVICE.equals(entityName)) { if (DESCRIPTION.equals(fieldName)) { getInstance().setDescription((String) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways; import com.anli.busstation.dal.ejb2.entities.BSEntityImpl; import com.anli.busstation.dal.interfaces.entities.BSEntity; import com.anli.simpleorm.handling.EntityBuilder; import com.anli.simpleorm.handling.EntityGateway; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; public abstract class BSEntityGateway<Entity extends BSEntityImpl> implements EntityGateway<Entity> { protected static final String ID = "id"; @Override public abstract EntityBuilder<Entity> getBuilder(String entityName); protected BigInteger getId(BSEntity entity) { return entity != null ? entity.getId() : null; } protected Collection<BigInteger> getIdCollection(Collection<BSEntity> entities) { if (entities == null) { return null; } ArrayList<BigInteger> idList = new ArrayList<>(entities.size()); for (BSEntity entity : entities) { idList.add(entity.getId()); } return idList; } protected Collection<BSEntity> getCollectionByIds(Collection<BSEntity> entities, Collection<BigInteger> ids) { if (entities == null || ids == null) { return null; } if (ids.isEmpty()) { return Collections.emptyList(); } LinkedList<BSEntity> result = new LinkedList<>(); for (BSEntity entity : entities) { if (ids.contains(entity.getId())) { result.add(entity); } } return result; } @Override public Object extractSingle(Entity entity, String entityName, String fieldName) { if (ID.equals(fieldName)) { return entity.getId(); } return null; } @Override public Object extractFullReference(Entity entity, String entityName, String fieldName) { return null; } @Override public Collection extractCollectionKeys(Entity entity, String entityName, String fieldName) { return null; } @Override public Collection extractFullCollection(Entity entity, String entityName, String fieldName) { return null; } @Override public Collection extractCollectionByKeys(Entity entity, String entityName, String fieldName, Collection keys) { return null; } @Override public void setCollectionField(Entity entity, String entityName, String fieldName, Collection value) { } protected abstract class BSEntityBuilder implements EntityBuilder<Entity> { protected Entity instance; @Override public EntityBuilder startBuilding() { instance = getNewInstance(); return this; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (ID.equals(fieldName) && getEntityName().equals(entityName)) { getInstance().setId((BigInteger) fieldValue); return this; } return this; } @Override public Entity build() { Entity result = instance; instance = null; return result; } protected abstract Entity getNewInstance(); protected abstract String getEntityName(); protected Entity getInstance() { return instance; } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.RoutePointImpl; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class RoutePointGateway extends BSEntityGateway<RoutePointImpl> { protected static final String ROUTE_POINT = "RoutePoint"; protected static final String STATION = "station"; @Override public EntityBuilder<RoutePointImpl> getBuilder(String entityName) { if (ROUTE_POINT.equals(entityName)) { return new RoutePointBuilder(); } return null; } @Override public Object extractSingle(RoutePointImpl entity, String entityName, String fieldName) { if (ROUTE_POINT.equals(entityName)) { if (STATION.equals(fieldName)) { return getId(entity.getStation()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(RoutePointImpl entity, String entityName, String fieldName) { if (ROUTE_POINT.equals(entityName)) { if (STATION.equals(fieldName)) { return entity.getStation(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class RoutePointBuilder extends BSEntityBuilder { @Override protected RoutePointImpl getNewInstance() { return new RoutePointImpl(); } @Override protected String getEntityName() { return ROUTE_POINT; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (ROUTE_POINT.equals(entityName)) { if (STATION.equals(fieldName)) { getInstance().setStation((Station) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.RideRoadImpl; import com.anli.busstation.dal.interfaces.entities.geography.Road; import com.anli.busstation.dal.interfaces.entities.staff.Driver; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class RideRoadGateway extends BSEntityGateway<RideRoadImpl> { protected static final String RIDE_ROAD = "RideRoad"; protected static final String DRIVER = "driver"; protected static final String ROAD = "road"; @Override public EntityBuilder<RideRoadImpl> getBuilder(String entityName) { if (RIDE_ROAD.equals(entityName)) { return new RideRoadBuilder(); } return null; } @Override public Object extractSingle(RideRoadImpl entity, String entityName, String fieldName) { if (RIDE_ROAD.equals(entityName)) { if (DRIVER.equals(fieldName)) { return getId(entity.getDriver()); } if (ROAD.equals(fieldName)) { return getId(entity.getRoad()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(RideRoadImpl entity, String entityName, String fieldName) { if (RIDE_ROAD.equals(entityName)) { if (DRIVER.equals(fieldName)) { return entity.getDriver(); } if (ROAD.equals(fieldName)) { return entity.getRoad(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class RideRoadBuilder extends BSEntityBuilder { @Override protected RideRoadImpl getNewInstance() { return new RideRoadImpl(); } @Override protected String getEntityName() { return RIDE_ROAD; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (RIDE_ROAD.equals(entityName)) { if (DRIVER.equals(fieldName)) { getInstance().setDriver((Driver) fieldValue); return this; } if (ROAD.equals(fieldName)) { getInstance().setRoad((Road) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.TicketImpl; import com.anli.busstation.dal.interfaces.entities.staff.Salesman; import com.anli.busstation.dal.interfaces.entities.traffic.RidePoint; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; import org.joda.time.DateTime; public class TicketGateway extends BSEntityGateway<TicketImpl> { protected static final String TICKET = "Ticket"; protected static final String ARRIVAL_POINT = "arrivalPoint"; protected static final String CUSTOMER_NAME = "customerName"; protected static final String DEPARTURE_POINT = "departurePoint"; protected static final String PRICE = "price"; protected static final String SALE_DATE = "saleDate"; protected static final String SALESMAN = "salesman"; protected static final String SEAT = "seat"; protected static final String SOLD = "sold"; @Override public EntityBuilder<TicketImpl> getBuilder(String entityName) { if (TICKET.equals(entityName)) { return new TicketBuilder(); } return null; } @Override public Object extractSingle(TicketImpl entity, String entityName, String fieldName) { if (TICKET.equals(entityName)) { if (ARRIVAL_POINT.equals(fieldName)) { return getId(entity.getArrivalPoint()); } if (CUSTOMER_NAME.equals(fieldName)) { return entity.getCustomerName(); } if (DEPARTURE_POINT.equals(fieldName)) { return getId(entity.getDeparturePoint()); } if (PRICE.equals(fieldName)) { return entity.getPrice(); } if (SALE_DATE.equals(fieldName)) { return entity.getSaleDate(); } if (SALESMAN.equals(fieldName)) { return getId(entity.getSalesman()); } if (SEAT.equals(fieldName)) { return entity.getSeat(); } if (SOLD.equals(fieldName)) { return entity.isSold(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(TicketImpl entity, String entityName, String fieldName) { if (TICKET.equals(entityName)) { if (ARRIVAL_POINT.equals(fieldName)) { return entity.getArrivalPoint(); } if (DEPARTURE_POINT.equals(fieldName)) { return entity.getDeparturePoint(); } if (SALESMAN.equals(fieldName)) { return entity.getSalesman(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class TicketBuilder extends BSEntityBuilder { @Override protected TicketImpl getNewInstance() { return new TicketImpl(); } @Override protected String getEntityName() { return TICKET; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (TICKET.equals(entityName)) { if (ARRIVAL_POINT.equals(fieldName)) { getInstance().setArrivalPoint((RidePoint) fieldValue); return this; } if (CUSTOMER_NAME.equals(fieldName)) { getInstance().setCustomerName((String) fieldValue); return this; } if (DEPARTURE_POINT.equals(fieldName)) { getInstance().setDeparturePoint((RidePoint) fieldValue); return this; } if (PRICE.equals(fieldName)) { getInstance().setPrice((BigDecimal) fieldValue); return this; } if (SALE_DATE.equals(fieldName)) { getInstance().setSaleDate((DateTime) fieldValue); return this; } if (SALESMAN.equals(fieldName)) { getInstance().setSalesman((Salesman) fieldValue); return this; } if (SEAT.equals(fieldName)) { getInstance().setSeat((Integer) fieldValue); return this; } if (SOLD.equals(fieldName)) { getInstance().setSold((Boolean) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.RouteImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; import java.util.Collection; import java.util.List; public class RouteGateway extends BSEntityGateway<RouteImpl> { protected static final String ROUTE = "Route"; protected static final String NUM_CODE = "numCode"; protected static final String RIDES = "rides"; protected static final String ROUTE_POINTS = "routePoints"; protected static final String TICKET_PRICE = "ticketPrice"; @Override public EntityBuilder<RouteImpl> getBuilder(String entityName) { if (ROUTE.equals(entityName)) { return new RouteBuilder(); } return null; } @Override public Object extractSingle(RouteImpl entity, String entityName, String fieldName) { if (ROUTE.equals(entityName)) { if (NUM_CODE.equals(fieldName)) { return entity.getNumCode(); } if (TICKET_PRICE.equals(fieldName)) { return entity.getTicketPrice(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Collection extractCollectionKeys(RouteImpl entity, String entityName, String fieldName) { if (ROUTE.equals(entityName)) { if (RIDES.equals(fieldName)) { return getIdCollection((List) entity.getRides()); } if (ROUTE_POINTS.equals(fieldName)) { return getIdCollection((List) entity.getRoutePoints()); } } return super.extractCollectionKeys(entity, entityName, fieldName); } @Override public Collection extractCollectionByKeys(RouteImpl entity, String entityName, String fieldName, Collection keys) { if (ROUTE.equals(entityName)) { if (RIDES.equals(fieldName)) { return getCollectionByIds((List) entity.getRides(), keys); } if (ROUTE_POINTS.equals(fieldName)) { return getCollectionByIds((List) entity.getRoutePoints(), keys); } } return super.extractCollectionByKeys(entity, entityName, fieldName, keys); } @Override public Collection extractFullCollection(RouteImpl entity, String entityName, String fieldName) { if (ROUTE.equals(entityName)) { if (RIDES.equals(fieldName)) { return entity.getRides(); } if (ROUTE_POINTS.equals(fieldName)) { return entity.getRoutePoints(); } } return super.extractFullCollection(entity, entityName, fieldName); } @Override public void setCollectionField(RouteImpl entity, String entityName, String fieldName, Collection value) { if (ROUTE.equals(entityName)) { if (RIDES.equals(fieldName)) { entity.setRides((List) value); return; } if (ROUTE_POINTS.equals(fieldName)) { entity.setRoutePoints((List) value); return; } } super.setCollectionField(entity, entityName, fieldName, value); } protected class RouteBuilder extends BSEntityBuilder { @Override protected RouteImpl getNewInstance() { return new RouteImpl(); } @Override protected String getEntityName() { return ROUTE; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (ROUTE.equals(entityName)) { if (NUM_CODE.equals(fieldName)) { getInstance().setNumCode((String) fieldValue); return this; } if (TICKET_PRICE.equals(fieldName)) { getInstance().setTicketPrice((BigDecimal) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.RideImpl; import com.anli.busstation.dal.interfaces.entities.vehicles.Bus; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.util.Collection; import java.util.List; public class RideGateway extends BSEntityGateway<RideImpl> { protected static final String RIDE = "Ride"; protected static final String BUS = "bus"; protected static final String RIDE_POINTS = "ridePoints"; protected static final String RIDE_ROADS = "rideRoads"; protected static final String TICKETS = "tickets"; @Override public EntityBuilder<RideImpl> getBuilder(String entityName) { if (RIDE.equals(entityName)) { return new RideBuilder(); } return null; } @Override public Object extractSingle(RideImpl entity, String entityName, String fieldName) { if (RIDE.equals(entityName)) { if (BUS.equals(fieldName)) { return getId(entity.getBus()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(RideImpl entity, String entityName, String fieldName) { if (RIDE.equals(entityName)) { if (BUS.equals(fieldName)) { return entity.getBus(); } } return super.extractFullReference(entity, entityName, fieldName); } @Override public Collection extractFullCollection(RideImpl entity, String entityName, String fieldName) { if (RIDE.equals(entityName)) { if (RIDE_POINTS.equals(fieldName)) { return entity.getRidePoints(); } if (RIDE_ROADS.equals(fieldName)) { return entity.getRideRoads(); } if (TICKETS.equals(fieldName)) { return entity.getTickets(); } } return super.extractFullCollection(entity, entityName, fieldName); } @Override public Collection extractCollectionKeys(RideImpl entity, String entityName, String fieldName) { if (RIDE.equals(entityName)) { if (RIDE_POINTS.equals(fieldName)) { return getIdCollection((List) entity.getRidePoints()); } if (RIDE_ROADS.equals(fieldName)) { return getIdCollection((List) entity.getRideRoads()); } if (TICKETS.equals(fieldName)) { return getIdCollection((List) entity.getTickets()); } } return super.extractCollectionKeys(entity, entityName, fieldName); } @Override public Collection extractCollectionByKeys(RideImpl entity, String entityName, String fieldName, Collection keys) { if (RIDE.equals(entityName)) { if (RIDE_POINTS.equals(fieldName)) { return getCollectionByIds((List) entity.getRidePoints(), keys); } if (RIDE_ROADS.equals(fieldName)) { return getCollectionByIds((List) entity.getRideRoads(), keys); } if (TICKETS.equals(fieldName)) { return getCollectionByIds((List) entity.getTickets(), keys); } } return super.extractCollectionByKeys(entity, entityName, fieldName, keys); } @Override public void setCollectionField(RideImpl entity, String entityName, String fieldName, Collection value) { if (RIDE.equals(entityName)) { if (RIDE_POINTS.equals(fieldName)) { entity.setRidePoints((List) value); return; } if (RIDE_ROADS.equals(fieldName)) { entity.setRideRoads((List) value); return; } if (TICKETS.equals(fieldName)) { entity.setTickets((List) value); return; } } super.setCollectionField(entity, entityName, fieldName, value); } protected class RideBuilder extends BSEntityBuilder { @Override protected RideImpl getNewInstance() { return new RideImpl(); } @Override protected String getEntityName() { return RIDE; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (RIDE.equals(entityName)) { if (BUS.equals(fieldName)) { getInstance().setBus((Bus) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.traffic; import com.anli.busstation.dal.ejb2.entities.traffic.RidePointImpl; import com.anli.busstation.dal.interfaces.entities.traffic.RoutePoint; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import org.joda.time.DateTime; public class RidePointGateway extends BSEntityGateway<RidePointImpl> { protected static final String RIDE_POINT = "RidePoint"; protected static final String ARRIVAL_TIME = "arrivalTime"; protected static final String DEPARTURE_TIME = "departureTime"; protected static final String ROUTE_POINT = "routePoint"; @Override public EntityBuilder<RidePointImpl> getBuilder(String entityName) { if (RIDE_POINT.equals(entityName)) { return new RidePointBuilder(); } return null; } @Override public Object extractSingle(RidePointImpl entity, String entityName, String fieldName) { if (RIDE_POINT.equals(entityName)) { if (ARRIVAL_TIME.equals(fieldName)) { return entity.getArrivalTime(); } if (DEPARTURE_TIME.equals(fieldName)) { return entity.getDepartureTime(); } if (ROUTE_POINT.equals(fieldName)) { return getId(entity.getRoutePoint()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(RidePointImpl entity, String entityName, String fieldName) { if (RIDE_POINT.equals(entityName)) { if (ROUTE_POINT.equals(fieldName)) { return entity.getRoutePoint(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class RidePointBuilder extends BSEntityBuilder { @Override protected RidePointImpl getNewInstance() { return new RidePointImpl(); } @Override protected String getEntityName() { return RIDE_POINT; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (RIDE_POINT.equals(entityName)) { if (ARRIVAL_TIME.equals(fieldName)) { getInstance().setArrivalTime((DateTime) fieldValue); return this; } if (DEPARTURE_TIME.equals(fieldName)) { getInstance().setDepartureTime((DateTime) fieldValue); return this; } if (ROUTE_POINT.equals(fieldName)) { getInstance().setRoutePoint((RoutePoint) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.geography; import com.anli.busstation.dal.ejb2.entities.geography.RoadImpl; import com.anli.busstation.dal.interfaces.entities.geography.Station; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; public class RoadGateway extends BSEntityGateway<RoadImpl> { protected static final String ROAD = "Road"; protected static final String A_STATION = "aStation"; protected static final String LENGTH = "length"; protected static final String RIDE_PRICE = "ridePrice"; protected static final String Z_STATION = "zStation"; @Override public EntityBuilder<RoadImpl> getBuilder(String entityName) { if (ROAD.equals(entityName)) { return new RoadBuilder(); } return null; } @Override public Object extractSingle(RoadImpl entity, String entityName, String fieldName) { if (ROAD.equals(entityName)) { if (A_STATION.equals(fieldName)) { return getId(entity.getAStation()); } if (LENGTH.equals(fieldName)) { return entity.getLength(); } if (RIDE_PRICE.equals(fieldName)) { return entity.getRidePrice(); } if (Z_STATION.equals(fieldName)) { return getId(entity.getZStation()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(RoadImpl entity, String entityName, String fieldName) { if (ROAD.equals(entityName)) { if (A_STATION.equals(fieldName)) { return entity.getAStation(); } if (Z_STATION.equals(fieldName)) { return entity.getZStation(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class RoadBuilder extends BSEntityBuilder { @Override protected RoadImpl getNewInstance() { return new RoadImpl(); } @Override protected String getEntityName() { return ROAD; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (ROAD.equals(entityName)) { if (A_STATION.equals(fieldName)) { getInstance().setAStation((Station) fieldValue); return this; } if (LENGTH.equals(fieldName)) { getInstance().setLength((Integer) fieldValue); return this; } if (RIDE_PRICE.equals(fieldName)) { getInstance().setRidePrice((BigDecimal) fieldValue); return this; } if (Z_STATION.equals(fieldName)) { getInstance().setZStation((Station) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.geography; import com.anli.busstation.dal.ejb2.entities.geography.StationImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; import java.util.Collection; import java.util.List; public class StationGateway extends BSEntityGateway<StationImpl> { protected static final String STATION = "Station"; protected static final String BUSES = "buses"; protected static final String EMPLOYEES = "employees"; protected static final String LATITUDE = "latitude"; protected static final String LONGITUDE = "longitude"; protected static final String NAME = "name"; @Override public EntityBuilder<StationImpl> getBuilder(String entityName) { if (STATION.equals(entityName)) { return new StationBuilder(); } return null; } @Override public Object extractSingle(StationImpl entity, String entityName, String fieldName) { if (STATION.equals(entityName)) { if (LATITUDE.equals(fieldName)) { return entity.getLatitude(); } if (LONGITUDE.equals(fieldName)) { return entity.getLongitude(); } if (NAME.equals(fieldName)) { return entity.getName(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Collection extractCollectionByKeys(StationImpl entity, String entityName, String fieldName, Collection keys) { if (STATION.equals(entityName)) { if (BUSES.equals(fieldName)) { return getCollectionByIds((List) entity.getBuses(), keys); } if (EMPLOYEES.equals(fieldName)) { return getCollectionByIds((List) entity.getEmployees(), keys); } } return super.extractCollectionByKeys(entity, entityName, fieldName, keys); } @Override public Collection extractCollectionKeys(StationImpl entity, String entityName, String fieldName) { if (STATION.equals(entityName)) { if (BUSES.equals(fieldName)) { return getIdCollection((List) entity.getBuses()); } if (EMPLOYEES.equals(fieldName)) { return getIdCollection((List) entity.getEmployees()); } } return super.extractCollectionKeys(entity, entityName, fieldName); } @Override public Collection extractFullCollection(StationImpl entity, String entityName, String fieldName) { if (STATION.equals(entityName)) { if (BUSES.equals(fieldName)) { return entity.getBuses(); } if (EMPLOYEES.equals(fieldName)) { return entity.getEmployees(); } } return super.extractFullCollection(entity, entityName, fieldName); } @Override public void setCollectionField(StationImpl entity, String entityName, String fieldName, Collection value) { if (STATION.equals(entityName)) { if (BUSES.equals(fieldName)) { entity.setBuses((List) value); return; } if (EMPLOYEES.equals(fieldName)) { entity.setEmployees((List) value); return; } } super.setCollectionField(entity, entityName, fieldName, value); } protected class StationBuilder extends BSEntityBuilder { @Override protected StationImpl getNewInstance() { return new StationImpl(); } @Override protected String getEntityName() { return STATION; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (STATION.equals(entityName)) { if (LATITUDE.equals(fieldName)) { getInstance().setLatitude((BigDecimal) fieldValue); return this; } if (LONGITUDE.equals(fieldName)) { getInstance().setLongitude((BigDecimal) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.geography; import com.anli.busstation.dal.ejb2.entities.geography.RegionImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.util.Collection; import java.util.List; public class RegionGateway extends BSEntityGateway<RegionImpl> { protected static final String REGION = "Region"; protected static final String CODE = "code"; protected static final String NAME = "name"; protected static final String STATIONS = "stations"; @Override public EntityBuilder<RegionImpl> getBuilder(String entityName) { if (REGION.equals(entityName)) { return new RegionBuilder(); } return null; } @Override public Object extractSingle(RegionImpl entity, String entityName, String fieldName) { if (REGION.equals(entityName)) { if (CODE.equals(fieldName)) { return entity.getCode(); } if (NAME.equals(fieldName)) { return entity.getName(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Collection extractCollectionKeys(RegionImpl entity, String entityName, String fieldName) { if (REGION.equals(entityName)) { if (STATIONS.equals(fieldName)) { return getIdCollection((List) entity.getStations()); } } return super.extractCollectionKeys(entity, entityName, fieldName); } @Override public Collection extractCollectionByKeys(RegionImpl entity, String entityName, String fieldName, Collection keys) { if (REGION.equals(entityName)) { if (STATIONS.equals(fieldName)) { return getCollectionByIds((List) entity.getStations(), keys); } } return super.extractCollectionByKeys(entity, entityName, fieldName, keys); } @Override public Collection extractFullCollection(RegionImpl entity, String entityName, String fieldName) { if (REGION.equals(entityName)) { if (STATIONS.equals(fieldName)) { return entity.getStations(); } } return super.extractFullCollection(entity, entityName, fieldName); } @Override public void setCollectionField(RegionImpl entity, String entityName, String fieldName, Collection value) { if (REGION.equals(entityName)) { if (STATIONS.equals(fieldName)) { entity.setStations((List) value); return; } } super.setCollectionField(entity, entityName, fieldName, value); } protected class RegionBuilder extends BSEntityBuilder { @Override protected RegionImpl getNewInstance() { return new RegionImpl(); } @Override protected String getEntityName() { return REGION; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (REGION.equals(entityName)) { if (CODE.equals(fieldName)) { getInstance().setCode((Integer) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.DriverImpl; import com.anli.busstation.dal.interfaces.entities.staff.DriverSkill; import com.anli.simpleorm.handling.EntityBuilder; public class DriverGateway extends AbstractEmployeeGateway<DriverImpl> { protected static final String DRIVER = "Driver"; protected static final String SKILL = "skill"; @Override public EntityBuilder<DriverImpl> getBuilder(String entityName) { if (DRIVER.equals(entityName)) { return new DriverBuilder(); } return null; } @Override public Object extractSingle(DriverImpl entity, String entityName, String fieldName) { if (DRIVER.equals(entityName)) { if (SKILL.equals(fieldName)) { return getId(entity.getSkill()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(DriverImpl entity, String entityName, String fieldName) { if (DRIVER.equals(entityName)) { if (SKILL.equals(fieldName)) { return entity.getSkill(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class DriverBuilder extends EmployeeBuilder { @Override protected DriverImpl getNewInstance() { return new DriverImpl(); } @Override protected String getEntityName() { return DRIVER; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (DRIVER.equals(entityName)) { if (SKILL.equals(fieldName)) { getInstance().setSkill((DriverSkill) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.MechanicSkillImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class MechanicSkillGateway extends BSEntityGateway<MechanicSkillImpl> { protected static final String MECHANIC_SKILL = "MechanicSkill"; protected static final String MAX_DIFF_LEVEL = "maxDiffLevel"; protected static final String NAME = "name"; @Override public EntityBuilder<MechanicSkillImpl> getBuilder(String entityName) { if (MECHANIC_SKILL.equals(entityName)) { return new MechanicSkillBuilder(); } return null; } @Override public Object extractSingle(MechanicSkillImpl entity, String entityName, String fieldName) { if (MECHANIC_SKILL.equals(entityName)) { if (MAX_DIFF_LEVEL.equals(fieldName)) { return entity.getMaxDiffLevel(); } if (NAME.equals(fieldName)) { return entity.getName(); } } return super.extractSingle(entity, entityName, fieldName); } protected class MechanicSkillBuilder extends BSEntityBuilder { @Override protected MechanicSkillImpl getNewInstance() { return new MechanicSkillImpl(); } @Override protected String getEntityName() { return MECHANIC_SKILL; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (MECHANIC_SKILL.equals(entityName)) { if (MAX_DIFF_LEVEL.equals(fieldName)) { getInstance().setMaxDiffLevel((Integer) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.EmployeeImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; import org.joda.time.DateTime; public abstract class AbstractEmployeeGateway<Entity extends EmployeeImpl> extends BSEntityGateway<Entity> { protected static final String EMPLOYEE = "Employee"; protected static final String HIRING_DATE = "hiringDate"; protected static final String NAME = "name"; protected static final String SALARY = "salary"; @Override public Object extractSingle(Entity entity, String entityName, String fieldName) { if (EMPLOYEE.equals(entityName)) { if (HIRING_DATE.equals(fieldName)) { return entity.getHiringDate(); } if (NAME.equals(fieldName)) { return entity.getName(); } if (SALARY.equals(fieldName)) { return entity.getSalary(); } } return super.extractSingle(entity, entityName, fieldName); } protected abstract class EmployeeBuilder extends BSEntityBuilder { @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (EMPLOYEE.equals(entityName)) { if (HIRING_DATE.equals(fieldName)) { getInstance().setHiringDate((DateTime) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } if (SALARY.equals(fieldName)) { getInstance().setSalary((BigDecimal) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.MechanicImpl; import com.anli.busstation.dal.interfaces.entities.staff.MechanicSkill; import com.anli.simpleorm.handling.EntityBuilder; public class MechanicGateway extends AbstractEmployeeGateway<MechanicImpl> { protected static final String MECHANIC = "Mechanic"; protected static final String SKILL = "skill"; @Override public EntityBuilder<MechanicImpl> getBuilder(String entityName) { if (MECHANIC.equals(entityName)) { return new MechanicBuilder(); } return null; } @Override public Object extractSingle(MechanicImpl entity, String entityName, String fieldName) { if (MECHANIC.equals(entityName)) { if (SKILL.equals(fieldName)) { return getId(entity.getSkill()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(MechanicImpl entity, String entityName, String fieldName) { if (MECHANIC.equals(entityName)) { if (SKILL.equals(fieldName)) { return entity.getSkill(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class MechanicBuilder extends EmployeeBuilder { @Override protected MechanicImpl getNewInstance() { return new MechanicImpl(); } @Override protected String getEntityName() { return MECHANIC; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (MECHANIC.equals(entityName)) { if (SKILL.equals(fieldName)) { getInstance().setSkill((MechanicSkill) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.SalesmanImpl; import com.anli.simpleorm.handling.EntityBuilder; public class SalesmanGateway extends AbstractEmployeeGateway<SalesmanImpl> { protected static final String SALESMAN = "Salesman"; protected static final String TOTAL_SALES = "totalSales"; @Override public EntityBuilder<SalesmanImpl> getBuilder(String entityName) { if (SALESMAN.equals(entityName)) { return new SalesmanBuilder(); } return null; } @Override public Object extractSingle(SalesmanImpl entity, String entityName, String fieldName) { if (SALESMAN.equals(entityName)) { if (TOTAL_SALES.equals(fieldName)) { return entity.getTotalSales(); } } return super.extractSingle(entity, entityName, fieldName); } protected class SalesmanBuilder extends EmployeeBuilder { @Override protected SalesmanImpl getNewInstance() { return new SalesmanImpl(); } @Override protected String getEntityName() { return SALESMAN; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (SALESMAN.equals(entityName)) { if (TOTAL_SALES.equals(fieldName)) { getInstance().setTotalSales((Integer) fieldValue); } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.DriverSkillImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class DriverSkillGateway extends BSEntityGateway<DriverSkillImpl> { protected static final String DRIVER_SKILL = "DriverSkill"; protected static final String MAX_PASSENGERS = "maxPassengers"; protected static final String MAX_RIDE_LENGTH = "maxRideLength"; protected static final String NAME = "name"; @Override public EntityBuilder<DriverSkillImpl> getBuilder(String entityName) { if (DRIVER_SKILL.equals(entityName)) { return new DriverSkillBuilder(); } return null; } @Override public Object extractSingle(DriverSkillImpl entity, String entityName, String fieldName) { if (DRIVER_SKILL.equals(entityName)) { if (MAX_PASSENGERS.equals(fieldName)) { return entity.getMaxPassengers(); } if (MAX_RIDE_LENGTH.equals(fieldName)) { return entity.getMaxRideLength(); } if (NAME.equals(fieldName)) { return entity.getName(); } } return super.extractSingle(entity, entityName, fieldName); } protected class DriverSkillBuilder extends BSEntityBuilder { @Override protected DriverSkillImpl getNewInstance() { return new DriverSkillImpl(); } @Override protected String getEntityName() { return DRIVER_SKILL; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (DRIVER_SKILL.equals(entityName)) { if (MAX_PASSENGERS.equals(fieldName)) { getInstance().setMaxPassengers((Integer) fieldValue); return this; } if (MAX_RIDE_LENGTH.equals(fieldName)) { getInstance().setMaxRideLength((Integer) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.staff; import com.anli.busstation.dal.ejb2.entities.staff.DriverImpl; import com.anli.busstation.dal.ejb2.entities.staff.EmployeeImpl; import com.anli.busstation.dal.ejb2.entities.staff.MechanicImpl; import com.anli.busstation.dal.ejb2.entities.staff.SalesmanImpl; import com.anli.simpleorm.handling.EntityGateway; import com.anli.simpleorm.handling.SuperEntityGateway; import java.util.HashMap; public class EmployeeGateway extends SuperEntityGateway<EmployeeImpl> { public EmployeeGateway(MechanicGateway mechanicGateway, DriverGateway driverGateway, SalesmanGateway salesmanGateway) { super(new HashMap<Class<? extends EmployeeImpl>, EntityGateway<? extends EmployeeImpl>>()); mapping.put(MechanicImpl.class, mechanicGateway); mapping.put(DriverImpl.class, driverGateway); mapping.put(SalesmanImpl.class, salesmanGateway); } }
Java
package com.anli.busstation.dal.sql.gateways.vehicles; import com.anli.busstation.dal.ejb2.entities.vehicles.BusImpl; import com.anli.busstation.dal.interfaces.entities.vehicles.Model; import com.anli.busstation.dal.interfaces.entities.vehicles.TechnicalState; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class BusGateway extends BSEntityGateway<BusImpl> { protected static final String BUS = "Bus"; protected static final String MODEL = "model"; protected static final String PLATE = "plate"; protected static final String STATE = "state"; @Override public EntityBuilder<BusImpl> getBuilder(String entityName) { if (BUS.equals(entityName)) { return new BusBuilder(); } return null; } @Override public Object extractSingle(BusImpl entity, String entityName, String fieldName) { if (BUS.equals(entityName)) { if (MODEL.equals(fieldName)) { return getId(entity.getModel()); } if (PLATE.equals(fieldName)) { return entity.getPlate(); } if (STATE.equals(fieldName)) { return getId(entity.getState()); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(BusImpl entity, String entityName, String fieldName) { if (BUS.equals(entityName)) { if (MODEL.equals(fieldName)) { return entity.getModel(); } if (STATE.equals(fieldName)) { return entity.getState(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class BusBuilder extends BSEntityBuilder { @Override protected BusImpl getNewInstance() { return new BusImpl(); } @Override protected String getEntityName() { return BUS; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (BUS.equals(entityName)) { if (MODEL.equals(fieldName)) { getInstance().setModel((Model) fieldValue); return this; } if (PLATE.equals(fieldName)) { getInstance().setPlate((String) fieldValue); return this; } if (STATE.equals(fieldName)) { getInstance().setState((TechnicalState) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.vehicles; import com.anli.busstation.dal.ejb2.entities.vehicles.ModelImpl; import com.anli.busstation.dal.interfaces.entities.vehicles.GasLabel; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; public class ModelGateway extends BSEntityGateway<ModelImpl> { protected static final String MODEL = "Model"; protected static final String GAS_LABEL = "gasLabel"; protected static final String GAS_RATE = "gasRate"; protected static final String NAME = "name"; protected static final String SEATS_NUMBER = "seatsNumber"; protected static final String TANK_VOLUME = "tankVolume"; @Override public EntityBuilder<ModelImpl> getBuilder(String entityName) { if (MODEL.equals(entityName)) { return new ModelBuilder(); } return null; } @Override public Object extractSingle(ModelImpl entity, String entityName, String fieldName) { if (MODEL.equals(entityName)) { if (GAS_LABEL.equals(fieldName)) { return getId(entity.getGasLabel()); } if (GAS_RATE.equals(fieldName)) { return entity.getGasRate(); } if (NAME.equals(fieldName)) { return entity.getName(); } if (SEATS_NUMBER.equals(fieldName)) { return entity.getSeatsNumber(); } if (TANK_VOLUME.equals(fieldName)) { return entity.getTankVolume(); } } return super.extractSingle(entity, entityName, fieldName); } @Override public Object extractFullReference(ModelImpl entity, String entityName, String fieldName) { if (MODEL.equals(entityName)) { if (GAS_LABEL.equals(fieldName)) { return entity.getGasLabel(); } } return super.extractFullReference(entity, entityName, fieldName); } protected class ModelBuilder extends BSEntityBuilder { @Override protected ModelImpl getNewInstance() { return new ModelImpl(); } @Override protected String getEntityName() { return MODEL; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (MODEL.equals(entityName)) { if (GAS_LABEL.equals(fieldName)) { getInstance().setGasLabel((GasLabel) fieldValue); return this; } if (GAS_RATE.equals(fieldName)) { getInstance().setGasRate((BigDecimal) fieldValue); return this; } if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } if (SEATS_NUMBER.equals(fieldName)) { getInstance().setSeatsNumber((Integer) fieldValue); return this; } if (TANK_VOLUME.equals(fieldName)) { getInstance().setTankVolume((Integer) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.vehicles; import com.anli.busstation.dal.ejb2.entities.vehicles.TechnicalStateImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; public class TechnicalStateGateway extends BSEntityGateway<TechnicalStateImpl> { protected static final String TECHNICAL_STATE = "TechnicalState"; protected static final String DESCRIPTION = "description"; protected static final String DIFFICULTY_LEVEL = "difficultyLevel"; @Override public EntityBuilder<TechnicalStateImpl> getBuilder(String entityName) { if (TECHNICAL_STATE.equals(entityName)) { return new TechnicalStateBuilder(); } return null; } @Override public Object extractSingle(TechnicalStateImpl entity, String entityName, String fieldName) { if (TECHNICAL_STATE.equals(entityName)) { if (DESCRIPTION.equals(fieldName)) { return entity.getDescription(); } if (DIFFICULTY_LEVEL.equals(fieldName)) { return entity.getDifficultyLevel(); } } return super.extractSingle(entity, entityName, fieldName); } protected class TechnicalStateBuilder extends BSEntityBuilder { @Override protected TechnicalStateImpl getNewInstance() { return new TechnicalStateImpl(); } @Override protected String getEntityName() { return TECHNICAL_STATE; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (TECHNICAL_STATE.equals(entityName)) { if (DESCRIPTION.equals(fieldName)) { getInstance().setDescription((String) fieldValue); return this; } if (DIFFICULTY_LEVEL.equals(fieldName)) { getInstance().setDifficultyLevel((Integer) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.gateways.vehicles; import com.anli.busstation.dal.ejb2.entities.vehicles.GasLabelImpl; import com.anli.busstation.dal.sql.gateways.BSEntityGateway; import com.anli.simpleorm.handling.EntityBuilder; import java.math.BigDecimal; public class GasLabelGateway extends BSEntityGateway<GasLabelImpl> { protected static final String GAS_LABEL = "GasLabel"; protected static final String NAME = "name"; protected static final String PRICE = "price"; @Override public EntityBuilder<GasLabelImpl> getBuilder(String entityName) { if (GAS_LABEL.equals(entityName)) { return new GasLabelBuilder(); } return null; } @Override public Object extractSingle(GasLabelImpl entity, String entityName, String fieldName) { if (GAS_LABEL.equals(entityName)) { if (NAME.equals(fieldName)) { return entity.getName(); } if (PRICE.equals(fieldName)) { return entity.getPrice(); } } return super.extractSingle(entity, entityName, fieldName); } protected class GasLabelBuilder extends BSEntityBuilder { @Override protected GasLabelImpl getNewInstance() { return new GasLabelImpl(); } @Override protected String getEntityName() { return GAS_LABEL; } @Override public EntityBuilder setSingle(String entityName, String fieldName, Object fieldValue) { if (GAS_LABEL.equals(entityName)) { if (NAME.equals(fieldName)) { getInstance().setName((String) fieldValue); return this; } if (PRICE.equals(fieldName)) { getInstance().setPrice((BigDecimal) fieldValue); return this; } } return super.setSingle(entityName, fieldName, fieldValue); } } }
Java
package com.anli.busstation.dal.sql.configuration; import com.anli.simpleorm.definitions.EntityDefinition; import com.anli.simpleorm.handling.EntityGateway; import com.anli.simpleorm.handling.EntityHandler; import com.anli.simpleorm.handling.EntityHandlerFactory; import com.anli.simpleorm.queries.MySqlQueryBuilder; import com.anli.sqlexecution.execution.SqlExecutor; import java.util.HashMap; import java.util.Map; public class EntityHandlerConfiguration implements EntityHandlerFactory { protected final EntityDefinitionConfiguration definitionConfig; protected final EntityGatewayConfiguration gatewayConfig; protected final MySqlQueryBuilder queryBuilder; protected final SqlExecutor executor; protected final Map<String, EntityHandler> handlers; public EntityHandlerConfiguration(EntityDefinitionConfiguration definitionConfig, EntityGatewayConfiguration gatewayConfig, SqlExecutor executor) { this.definitionConfig = definitionConfig; this.gatewayConfig = gatewayConfig; this.queryBuilder = getQueryBuilder(); this.executor = executor; handlers = new HashMap<>(); } @Override public <Entity> EntityHandler<Entity> getHandler(String entityName) { EntityHandler<Entity> handler = handlers.get(entityName); if (handler != null) { return handler; } synchronized (this) { handler = handlers.get(entityName); if (handler == null) { handler = getNewEntityHandler(definitionConfig.getDefinition(entityName), queryBuilder, gatewayConfig.<Entity>getGateway(entityName), this, executor); handlers.put(entityName, handler); } } return handler; } private <Entity> EntityHandler<Entity> getNewEntityHandler(EntityDefinition definition, MySqlQueryBuilder builder, EntityGateway<Entity> gateway, EntityHandlerFactory factory, SqlExecutor executor) { return new EntityHandler<>(definition, builder, gateway, factory, executor); } private MySqlQueryBuilder getQueryBuilder() { return new MySqlQueryBuilder(); } }
Java
package com.anli.busstation.dal.sql.configuration; import com.anli.busstation.dal.ejb2.factories.DataSourceFactory; import com.anli.busstation.dal.ejb2.factories.TransactionManagerFactory; import com.anli.busstation.dal.sql.idgeneration.IdGenerator; import com.anli.busstation.dal.sql.idgeneration.TableIdGenerator; import com.anli.busstation.dal.sql.transformation.BigIntegerTransformer; import com.anli.busstation.dal.sql.transformation.BooleanTransformer; import com.anli.busstation.dal.sql.transformation.DateTimeTransformer; import com.anli.sqlexecution.execution.SqlExecutor; import com.anli.sqlexecution.transformation.MapBasedTransformerFactory; import com.anli.sqlexecution.transformation.SqlTransformer; import com.anli.sqlexecution.transformation.TransformerFactory; import java.math.BigInteger; import java.util.HashMap; import java.util.Map; import javax.sql.DataSource; import javax.transaction.TransactionManager; import org.joda.time.DateTime; public class ConfigurationHolder { private static final EntityDefinitionConfiguration definitionConfig = new EntityDefinitionConfiguration(); private static final EntityGatewayConfiguration gatewayConfig = new EntityGatewayConfiguration(); private static final SqlExecutor executor = new SqlExecutor(getDataSource(), getTransformerFactory()); private static final EntityHandlerConfiguration handlerConfig = new EntityHandlerConfiguration(definitionConfig, gatewayConfig, executor); private static final IdGenerator idGenerator = new TableIdGenerator(executor, getTransactionManager(), "bs_entity", 1); private static TransformerFactory getTransformerFactory() { Map<Class, SqlTransformer> transformers = new HashMap<>(); transformers.put(BigInteger.class, new BigIntegerTransformer()); transformers.put(Boolean.class, new BooleanTransformer()); transformers.put(DateTime.class, new DateTimeTransformer()); return new MapBasedTransformerFactory(transformers); } private static DataSource getDataSource() { return new DataSourceFactory().getDataSource(); } private static TransactionManager getTransactionManager() { return new TransactionManagerFactory().getManager(); } public static EntityHandlerConfiguration getHandlerConfiguration() { return handlerConfig; } public static IdGenerator getIdGenerator() { return idGenerator; } }
Java
package com.anli.busstation.dal.sql.configuration; import com.anli.busstation.dal.sql.definitions.EntityDefinitionBuilder; import com.anli.simpleorm.definitions.EntityDefinition; import com.anli.simpleorm.queries.named.NamedQuery; import java.util.HashMap; import java.util.Map; public class EntityDefinitionConfiguration { protected Map<String, EntityDefinition> definitions; protected boolean built; public EntityDefinitionConfiguration() { definitions = new HashMap<>(); built = false; } public EntityDefinition getDefinition(String entityName) { if (!built) { buildConfig(); built = true; } return definitions.get(entityName); } protected EntityDefinition store(EntityDefinition definition) { definitions.put(definition.getName(), definition); return definition; } protected void buildConfig() { EntityDefinition technicalState = store(getTechnicalStateDefinition()); EntityDefinition gasLabel = store(getGasLabelDefinition()); EntityDefinition model = store(getModelDefinition(gasLabel)); EntityDefinition bus = store(getBusDefinition(model, technicalState)); EntityDefinition driverSkill = store(getDriverSkillDefinition()); EntityDefinition mechanicSkill = store(getMechanicSkillDefinition()); EntityDefinition employee = store(getEmployeeDefinition()); EntityDefinition driver = store(getDriverDefinition(employee, driverSkill)); EntityDefinition mechanic = store(getMechanicDefinition(employee, mechanicSkill)); EntityDefinition salesman = store(getSalesmanDefinition(employee)); EntityDefinition technicalAssignment = store(getTechnicalAssignmentDefinition(mechanic)); store(getStationServiceDefinition(technicalAssignment)); EntityDefinition busService = store(getBusServiceDefinition(technicalAssignment, bus)); store(getBusRefuellingDefinition(busService)); store(getBusRepairmentDefinition(busService)); EntityDefinition station = store(getStationDefinition(employee, bus)); EntityDefinition road = store(getRoadDefinition(station)); store(getRegionDefinition(station)); EntityDefinition routePoint = store(getRoutePointDefinition(station)); EntityDefinition ridePoint = store(getRidePointDefinition(routePoint)); EntityDefinition rideRoad = store(getRideRoadDefinition(road, driver)); EntityDefinition ticket = store(getTicketDefinition(ridePoint, salesman)); EntityDefinition ride = store(getRideDefinition(bus, ridePoint, rideRoad, ticket)); store(getRouteDefinition(routePoint, ride)); } protected EntityDefinition getTechnicalStateDefinition() { return getBuilder().create("TechnicalState", "technical_states") .addPrimaryKey("state_id") .addStringField("description", "description") .addIntegerField("difficultyLevel", "difficulty_level").build(); } protected EntityDefinition getGasLabelDefinition() { return getBuilder().create("GasLabel", "gas_labels").addPrimaryKey("label_id") .addStringField("name", "name").addBigDecimalField("price", "price").build(); } protected EntityDefinition getModelDefinition(EntityDefinition gasLabel) { return getBuilder().create("Model", "models").addPrimaryKey("model_id") .addStringField("name", "name").addIntegerField("seatsNumber", "seats_number") .addIntegerField("tankVolume", "tank_volume") .addReferenceField("gasLabel", "gas_label", gasLabel) .addBigDecimalField("gasRate", "gas_rate").build(); } protected EntityDefinition getBusDefinition(EntityDefinition model, EntityDefinition technicalState) { return getBuilder().create("Bus", "buses").addPrimaryKey("bus_id") .addReferenceField("model", "model", model) .addReferenceField("state", "state", technicalState) .addStringField("plate", "plate").build(); } protected EntityDefinition getDriverSkillDefinition() { return getBuilder().create("DriverSkill", "driver_skills").addPrimaryKey("skill_id") .addStringField("name", "name").addIntegerField("maxRideLength", "max_ride_length") .addIntegerField("maxPassengers", "max_passengers").build(); } protected EntityDefinition getMechanicSkillDefinition() { return getBuilder().create("MechanicSkill", "mechanic_skills").addPrimaryKey("skill_id") .addStringField("name", "name").addIntegerField("maxDiffLevel", "max_diff_level").build(); } protected EntityDefinition getEmployeeDefinition() { return getBuilder().create("Employee", "employees").addPrimaryKey("employee_id") .addStringField("name", "name").addBigDecimalField("salary", "salary") .addDateTimeField("hiringDate", "hiring_date").build(); } protected EntityDefinition getDriverDefinition(EntityDefinition employee, EntityDefinition skill) { return getBuilder().create("Driver", "drivers").setParent(employee).addPrimaryKey("employee_id") .addReferenceField("skill", "skill", skill).build(); } protected EntityDefinition getMechanicDefinition(EntityDefinition employee, EntityDefinition skill) { return getBuilder().create("Mechanic", "mechanics").setParent(employee).addPrimaryKey("employee_id") .addReferenceField("skill", "skill", skill).build(); } protected EntityDefinition getSalesmanDefinition(EntityDefinition employee) { return getBuilder().create("Salesman", "salesmen").setParent(employee) .addPrimaryKey("employee_id").addIntegerField("totalSales", "total_sales").build(); } protected EntityDefinition getTechnicalAssignmentDefinition(EntityDefinition mechanic) { return getBuilder().create("TechnicalAssignment", "technical_assignments") .addPrimaryKey("assignment_id").addReferenceField("mechanic", "mechanic", mechanic) .addDateTimeField("beginTime", "begin_time").addDateTimeField("endTime", "end_time") .addBigDecimalField("serviceCost", "service_cost").build(); } protected EntityDefinition getStationServiceDefinition(EntityDefinition technicalAssignment) { return getBuilder().create("StationService", "station_services") .setParent(technicalAssignment).addPrimaryKey("assignment_id") .addStringField("description", "description").build(); } protected EntityDefinition getBusServiceDefinition(EntityDefinition technicalAssignment, EntityDefinition bus) { return getBuilder().create("BusService", "bus_services").setParent(technicalAssignment) .addPrimaryKey("assignment_id").addReferenceField("bus", "bus", bus).build(); } protected EntityDefinition getBusRefuellingDefinition(EntityDefinition busService) { return getBuilder().create("BusRefuelling", "bus_refuellings").setParent(busService) .addPrimaryKey("assignment_id").addIntegerField("volume", "gas_volume").build(); } protected EntityDefinition getBusRepairmentDefinition(EntityDefinition busService) { return getBuilder().create("BusRepairment", "bus_repairments").setParent(busService) .addPrimaryKey("assignment_id").addBigDecimalField("expendablesPrice", "expendables_price").build(); } protected EntityDefinition getStationDefinition(EntityDefinition employee, EntityDefinition bus) { return getBuilder().create("Station", "stations").addPrimaryKey("station_id") .addStringField("name", "name").addBigDecimalField("latitude", "latitude") .addBigDecimalField("longitude", "longitude") .addListField("employees", employee, "station", "station_order") .addListField("buses", bus, "station", "station_order").build(); } protected EntityDefinition getRoadDefinition(EntityDefinition station) { return getBuilder().create("Road", "roads").addPrimaryKey("road_id") .addReferenceField("aStation", "a_station", station) .addReferenceField("zStation", "z_station", station) .addIntegerField("length", "length").addBigDecimalField("ridePrice", "ride_price") .addNamedQuery("byStation", "", "where road.a_station = ? or road.z_station = ?") .addNamedQuery("byAnyStation", "", "where road.a_station in (" + NamedQuery.getListMacro() + ") or road.z_station in (" + NamedQuery.getListMacro() + ")") .addNamedQuery("byNullStation", "", "where road.a_station is null or road.z_station is null").build(); } protected EntityDefinition getRegionDefinition(EntityDefinition station) { return getBuilder().create("Region", "regions").addPrimaryKey("region_id") .addStringField("name", "name").addIntegerField("code", "num_code") .addListField("stations", station, "region", "region_order").build(); } protected EntityDefinition getRoutePointDefinition(EntityDefinition station) { return getBuilder().create("RoutePoint", "route_points").addPrimaryKey("route_point_id") .addReferenceField("station", "station", station).build(); } protected EntityDefinition getRidePointDefinition(EntityDefinition routePoint) { return getBuilder().create("RidePoint", "ride_points").addPrimaryKey("ride_point_id") .addReferenceField("routePoint", "route_point", routePoint) .addDateTimeField("arrivalTime", "arrival_time") .addDateTimeField("departureTime", "departure_time").build(); } protected EntityDefinition getRideRoadDefinition(EntityDefinition road, EntityDefinition driver) { return getBuilder().create("RideRoad", "ride_roads").addPrimaryKey("ride_road_id") .addReferenceField("road", "road", road).addReferenceField("driver", "driver", driver).build(); } protected EntityDefinition getTicketDefinition(EntityDefinition ridePoint, EntityDefinition salesman) { return getBuilder().create("Ticket", "tickets").addPrimaryKey("ticket_id") .addReferenceField("departurePoint", "departure_point", ridePoint) .addReferenceField("arrivalPoint", "arrival_point", ridePoint) .addIntegerField("seat", "seat").addReferenceField("salesman", "salesman", salesman) .addDateTimeField("saleDate", "sale_date").addStringField("customerName", "customer_name") .addBigDecimalField("price", "price").addBooleanField("sold", "is_sold").build(); } protected EntityDefinition getRideDefinition(EntityDefinition bus, EntityDefinition ridePoint, EntityDefinition rideRoad, EntityDefinition ticket) { return getBuilder().create("Ride", "rides").addPrimaryKey("ride_id") .addReferenceField("bus", "bus", bus) .addListField("ridePoints", ridePoint, "ride", "ride_order") .addListField("rideRoads", rideRoad, "ride", "ride_order") .addListField("tickets", ticket, "ride", "ride_order").build(); } protected EntityDefinition getRouteDefinition(EntityDefinition routePoint, EntityDefinition ride) { return getBuilder().create("Route", "routes").addPrimaryKey("route_id") .addStringField("numCode", "num_code").addBigDecimalField("ticketPrice", "ticket_price") .addListField("routePoints", routePoint, "route", "route_order") .addListField("rides", ride, "route", "route_order").build(); } protected EntityDefinitionBuilder getBuilder() { return new EntityDefinitionBuilder(); } }
Java
package com.anli.busstation.dal.sql.configuration; import com.anli.busstation.dal.sql.gateways.geography.RegionGateway; import com.anli.busstation.dal.sql.gateways.geography.RoadGateway; import com.anli.busstation.dal.sql.gateways.geography.StationGateway; import com.anli.busstation.dal.sql.gateways.maintenance.BusRefuellingGateway; import com.anli.busstation.dal.sql.gateways.maintenance.BusRepairmentGateway; import com.anli.busstation.dal.sql.gateways.maintenance.BusServiceGateway; import com.anli.busstation.dal.sql.gateways.maintenance.StationServiceGateway; import com.anli.busstation.dal.sql.gateways.maintenance.TechnicalAssignmentGateway; import com.anli.busstation.dal.sql.gateways.staff.DriverGateway; import com.anli.busstation.dal.sql.gateways.staff.DriverSkillGateway; import com.anli.busstation.dal.sql.gateways.staff.EmployeeGateway; import com.anli.busstation.dal.sql.gateways.staff.MechanicGateway; import com.anli.busstation.dal.sql.gateways.staff.MechanicSkillGateway; import com.anli.busstation.dal.sql.gateways.staff.SalesmanGateway; import com.anli.busstation.dal.sql.gateways.traffic.RideGateway; import com.anli.busstation.dal.sql.gateways.traffic.RidePointGateway; import com.anli.busstation.dal.sql.gateways.traffic.RideRoadGateway; import com.anli.busstation.dal.sql.gateways.traffic.RouteGateway; import com.anli.busstation.dal.sql.gateways.traffic.RoutePointGateway; import com.anli.busstation.dal.sql.gateways.traffic.TicketGateway; import com.anli.busstation.dal.sql.gateways.vehicles.BusGateway; import com.anli.busstation.dal.sql.gateways.vehicles.GasLabelGateway; import com.anli.busstation.dal.sql.gateways.vehicles.ModelGateway; import com.anli.busstation.dal.sql.gateways.vehicles.TechnicalStateGateway; import com.anli.simpleorm.handling.EntityGateway; import java.util.HashMap; import java.util.Map; public class EntityGatewayConfiguration { protected final Map<String, EntityGateway> gateways; protected boolean built; public EntityGatewayConfiguration() { this.gateways = new HashMap<>(); built = false; } protected void buildConfig() { gateways.put("Bus", new BusGateway()); gateways.put("GasLabel", new GasLabelGateway()); gateways.put("Model", new ModelGateway()); gateways.put("TechnicalState", new TechnicalStateGateway()); gateways.put("DriverSkill", new DriverSkillGateway()); gateways.put("MechanicSkill", new MechanicSkillGateway()); MechanicGateway mechanic = new MechanicGateway(); DriverGateway driver = new DriverGateway(); SalesmanGateway salesman = new SalesmanGateway(); gateways.put("Mechanic", mechanic); gateways.put("Driver", driver); gateways.put("Salesman", salesman); gateways.put("Employee", new EmployeeGateway(mechanic, driver, salesman)); gateways.put("Region", new RegionGateway()); gateways.put("Road", new RoadGateway()); gateways.put("Station", new StationGateway()); BusRepairmentGateway busRepairment = new BusRepairmentGateway(); BusRefuellingGateway busRefuelling = new BusRefuellingGateway(); BusServiceGateway busService = new BusServiceGateway(busRefuelling, busRepairment); StationServiceGateway stationService = new StationServiceGateway(); gateways.put("BusRepairment", busRepairment); gateways.put("BusRefuelling", busRefuelling); gateways.put("BusService", busService); gateways.put("StationService", stationService); gateways.put("TechnicalAssignment", new TechnicalAssignmentGateway(busService, stationService)); gateways.put("Ride", new RideGateway()); gateways.put("RidePoint", new RidePointGateway()); gateways.put("RideRoad", new RideRoadGateway()); gateways.put("Route", new RouteGateway()); gateways.put("RoutePoint", new RoutePointGateway()); gateways.put("Ticket", new TicketGateway()); } public <Entity> EntityGateway<Entity> getGateway(String entityName) { if (!built) { buildConfig(); built = true; } return gateways.get(entityName); } }
Java
package com.anli.busstation.dal.sql.transformation; import com.anli.sqlexecution.transformation.SqlTransformer; import java.sql.Timestamp; import org.joda.time.DateTime; public class DateTimeTransformer implements SqlTransformer<DateTime, Timestamp> { @Override public Timestamp toSql(DateTime source) { return source == null ? null : new Timestamp(source.getMillis()); } @Override public DateTime toJava(Timestamp source) { return source == null ? null : new DateTime(source.getTime()); } @Override public Class<? extends DateTime> getJavaClass() { return DateTime.class; } @Override public Class<? extends Timestamp> getSqlClass() { return Timestamp.class; } }
Java
package com.anli.busstation.dal.sql.transformation; import com.anli.sqlexecution.transformation.SqlTransformer; public class BooleanTransformer implements SqlTransformer<Boolean, Integer> { @Override public Integer toSql(Boolean source) { return Boolean.TRUE.equals(source) ? 1 : 0; } @Override public Boolean toJava(Integer source) { return source != null && !source.equals(0); } @Override public Class<? extends Boolean> getJavaClass() { return Boolean.class; } @Override public Class<? extends Integer> getSqlClass() { return Integer.class; } }
Java
package com.anli.busstation.dal.sql.transformation; import com.anli.sqlexecution.transformation.SqlTransformer; import java.math.BigDecimal; import java.math.BigInteger; public class BigIntegerTransformer implements SqlTransformer<BigInteger, BigDecimal> { @Override public BigDecimal toSql(BigInteger source) { return source == null ? null : new BigDecimal(source); } @Override public BigInteger toJava(BigDecimal source) { return source == null ? null : source.toBigInteger(); } @Override public Class<? extends BigInteger> getJavaClass() { return BigInteger.class; } @Override public Class<? extends BigDecimal> getSqlClass() { return BigDecimal.class; } }
Java
package com.anli.busstation.dal.sql.definitions; import com.anli.simpleorm.definitions.CollectionDefinition; import com.anli.simpleorm.definitions.EntityDefinition; import com.anli.simpleorm.definitions.FieldDefinition; import com.anli.simpleorm.definitions.ListDefinition; import com.anli.simpleorm.definitions.PrimitiveDefinition; import com.anli.simpleorm.definitions.PrimitiveType; import com.anli.simpleorm.definitions.ReferenceDefinition; import com.anli.simpleorm.queries.named.NamedQuery; import java.math.BigDecimal; import java.math.BigInteger; import org.joda.time.DateTime; public class EntityDefinitionBuilder { protected EntityDefinition definition; public EntityDefinitionBuilder() { } public EntityDefinitionBuilder create(String name, String table) { definition = new EntityDefinition(name); definition.setTable(table); return this; } public EntityDefinitionBuilder addPrimaryKey(String column) { FieldDefinition primaryKey = getId(column); definition.addSingleField(primaryKey); definition.setPrimaryKeyName(primaryKey.getName()); return this; } public EntityDefinitionBuilder setParent(EntityDefinition parent) { parent.addChildrenEntity(definition); return this; } public EntityDefinitionBuilder addIntegerField(String name, String column) { definition.addSingleField(getIntegerField(name, column)); return this; } public EntityDefinitionBuilder addBigDecimalField(String name, String column) { definition.addSingleField(getBigDecimalField(name, column)); return this; } public EntityDefinitionBuilder addDateTimeField(String name, String column) { definition.addSingleField(getDateTimeField(name, column)); return this; } public EntityDefinitionBuilder addStringField(String name, String column) { definition.addSingleField(getStringField(name, column)); return this; } public EntityDefinitionBuilder addReferenceField(String name, String column, EntityDefinition fieldDef) { definition.addSingleField(getReferenceField(name, column, fieldDef)); return this; } public EntityDefinitionBuilder addBooleanField(String name, String column) { definition.addSingleField(getBooleanField(name, column)); return this; } public EntityDefinitionBuilder addListField(String name, EntityDefinition fieldDef, String foreignKey, String orderColumn) { definition.addCollectionField(getListField(name, fieldDef, foreignKey, orderColumn)); return this; } public EntityDefinitionBuilder addNamedQuery(String name, String joins, String criteria) { definition.addNamedQuery(getNamedQuery(name, joins, criteria)); return this; } public EntityDefinition build() { return definition; } protected FieldDefinition getId(String column) { return new PrimitiveDefinition("id", BigInteger.class, column, PrimitiveType.REFERENCE); } protected FieldDefinition getIntegerField(String name, String column) { return new PrimitiveDefinition(name, Integer.class, column, PrimitiveType.NUMERIC); } protected FieldDefinition getBigDecimalField(String name, String column) { return new PrimitiveDefinition(name, BigDecimal.class, column, PrimitiveType.NUMERIC); } protected FieldDefinition getDateTimeField(String name, String column) { return new PrimitiveDefinition(name, DateTime.class, column, PrimitiveType.DATE); } protected FieldDefinition getBooleanField(String name, String column) { return new PrimitiveDefinition(name, Boolean.class, column, PrimitiveType.BOOLEAN); } protected FieldDefinition getStringField(String name, String column) { return new PrimitiveDefinition(name, String.class, column, PrimitiveType.STRING); } protected CollectionDefinition getListField(String name, EntityDefinition fieldDef, String foreignKey, String orderColumn) { return new ListDefinition(name, BigInteger.class, foreignKey, fieldDef, orderColumn); } protected ReferenceDefinition getReferenceField(String name, String column, EntityDefinition fieldDef) { return new ReferenceDefinition(name, BigInteger.class, column, fieldDef); } protected NamedQuery getNamedQuery(String name, String additionalJoins, String criteria) { return new NamedQuery(name, additionalJoins, criteria); } }
Java
package com.anli.busstation.dal.ejb2.factories; import com.anli.configuration.Configurator; import javax.transaction.TransactionManager; public class TransactionManagerFactory extends AbstractLookupFactory { public TransactionManager getManager() { return lookup(Configurator.getTransationManagerJndiName(), TransactionManager.class); } }
Java
package com.anli.busstation.dal.ejb2.factories; import com.anli.configuration.Configurator; import javax.sql.DataSource; public class DataSourceFactory extends AbstractLookupFactory { protected static final String DB_GROUP = "db"; protected static final String CONNECTION_POOL_PROPERTY = "connection_pool"; protected String dataSourceName; public DataSourceFactory() { dataSourceName = Configurator.getConfig(DB_GROUP).getProperty(CONNECTION_POOL_PROPERTY); } public DataSource getDataSource() { return lookup(dataSourceName, DataSource.class); } }
Java
package com.anli.busstation.dal.ejb2.factories; import com.anli.busstation.dal.ejb2.providers.remotes.BSEntityProviderRemote; import com.anli.busstation.dal.ejb2.proxy.EjbExceptionHandler; import com.anli.busstation.dal.exceptions.ConsistencyException; import com.anli.busstation.dal.interfaces.factories.ProviderFactory; import com.anli.busstation.dal.interfaces.providers.BSEntityProvider; import java.lang.reflect.Proxy; import java.util.Collection; import java.util.Collections; public class ProviderProxyFactory implements ProviderFactory { protected final ProviderRemoteFactory remoteFactory; protected final Collection<Class<? extends Throwable>> manageableExceptions; public ProviderProxyFactory() { this.remoteFactory = new ProviderRemoteFactory(); this.manageableExceptions = Collections .<Class<? extends Throwable>>singletonList(ConsistencyException.class); } @Override public <I extends BSEntityProvider> I getProvider(Class<I> abstraction) { return getProxy(abstraction, getRemote(abstraction)); } protected <I extends BSEntityProvider> BSEntityProviderRemote getRemote(Class<I> abstraction) { return remoteFactory.getProvider(abstraction); } protected <I extends BSEntityProvider> I getProxy(Class<I> abstraction, BSEntityProviderRemote remote) { return (I) Proxy.newProxyInstance(abstraction.getClassLoader(), new Class[]{abstraction}, new EjbExceptionHandler(remote, manageableExceptions)); } }
Java
package com.anli.busstation.dal.ejb2.factories; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class AbstractLookupFactory { private static final Logger LOG = LoggerFactory.getLogger(AbstractLookupFactory.class); protected Context getContext() throws NamingException { return new InitialContext(); } protected <T> T lookupRemote(Class<T> clazz) { Object lookedUp = lookup(clazz.getCanonicalName(), Object.class); return (T) PortableRemoteObject.narrow(lookedUp, clazz); } protected <T> T lookup(String name, Class<T> clazz) { try { Context ic = getContext(); return (T) ic.lookup(name); } catch (NamingException namingException) { LOG.error("Could not lookup resource", namingException); return null; } } protected <T> T lookup(Class<T> clazz) { return lookup(clazz.getCanonicalName(), clazz); } }
Java
package com.anli.busstation.dal.ejb2.factories; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.vehicles.BusProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.maintenance.BusRefuellingProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.maintenance.BusRepairmentProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.maintenance.BusServiceProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.DriverProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.DriverSkillProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.EmployeeProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.vehicles.GasLabelProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.MechanicProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.MechanicSkillProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.vehicles.ModelProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.geography.RegionProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.RidePointProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.RideProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.RideRoadProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.geography.RoadProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.RoutePointProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.RouteProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.staff.SalesmanProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.geography.StationProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.maintenance.StationServiceProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.maintenance.TechnicalAssignmentProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.vehicles.TechnicalStateProviderHome; import com.anli.busstation.dal.ejb2.providers.homes.traffic.TicketProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.BSEntityProviderRemote; import com.anli.busstation.dal.interfaces.providers.BSEntityProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.BusProvider; import com.anli.busstation.dal.interfaces.providers.maintenance.BusRefuellingProvider; import com.anli.busstation.dal.interfaces.providers.maintenance.BusRepairmentProvider; import com.anli.busstation.dal.interfaces.providers.maintenance.BusServiceProvider; import com.anli.busstation.dal.interfaces.providers.staff.DriverProvider; import com.anli.busstation.dal.interfaces.providers.staff.DriverSkillProvider; import com.anli.busstation.dal.interfaces.providers.staff.EmployeeProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.GasLabelProvider; import com.anli.busstation.dal.interfaces.providers.staff.MechanicProvider; import com.anli.busstation.dal.interfaces.providers.staff.MechanicSkillProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.ModelProvider; import com.anli.busstation.dal.interfaces.providers.geography.RegionProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RidePointProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RideProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RideRoadProvider; import com.anli.busstation.dal.interfaces.providers.geography.RoadProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RoutePointProvider; import com.anli.busstation.dal.interfaces.providers.traffic.RouteProvider; import com.anli.busstation.dal.interfaces.providers.staff.SalesmanProvider; import com.anli.busstation.dal.interfaces.providers.geography.StationProvider; import com.anli.busstation.dal.interfaces.providers.maintenance.StationServiceProvider; import com.anli.busstation.dal.interfaces.providers.maintenance.TechnicalAssignmentProvider; import com.anli.busstation.dal.interfaces.providers.vehicles.TechnicalStateProvider; import com.anli.busstation.dal.interfaces.providers.traffic.TicketProvider; import java.rmi.RemoteException; import java.util.HashMap; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ProviderRemoteFactory extends AbstractLookupFactory { private static final Logger LOG = LoggerFactory.getLogger(ProviderRemoteFactory.class); protected final static Map<Class<? extends BSEntityProvider>, Class<? extends BSEntityProviderHome>> implementations = new HashMap<>(); { implementations.put(BusProvider.class, BusProviderHome.class); implementations.put(BusRefuellingProvider.class, BusRefuellingProviderHome.class); implementations.put(BusRepairmentProvider.class, BusRepairmentProviderHome.class); implementations.put(BusServiceProvider.class, BusServiceProviderHome.class); implementations.put(DriverProvider.class, DriverProviderHome.class); implementations.put(DriverSkillProvider.class, DriverSkillProviderHome.class); implementations.put(EmployeeProvider.class, EmployeeProviderHome.class); implementations.put(GasLabelProvider.class, GasLabelProviderHome.class); implementations.put(MechanicProvider.class, MechanicProviderHome.class); implementations.put(MechanicSkillProvider.class, MechanicSkillProviderHome.class); implementations.put(ModelProvider.class, ModelProviderHome.class); implementations.put(RegionProvider.class, RegionProviderHome.class); implementations.put(RidePointProvider.class, RidePointProviderHome.class); implementations.put(RideProvider.class, RideProviderHome.class); implementations.put(RideRoadProvider.class, RideRoadProviderHome.class); implementations.put(RoadProvider.class, RoadProviderHome.class); implementations.put(RoutePointProvider.class, RoutePointProviderHome.class); implementations.put(RouteProvider.class, RouteProviderHome.class); implementations.put(SalesmanProvider.class, SalesmanProviderHome.class); implementations.put(StationProvider.class, StationProviderHome.class); implementations.put(StationServiceProvider.class, StationServiceProviderHome.class); implementations.put(TechnicalAssignmentProvider.class, TechnicalAssignmentProviderHome.class); implementations.put(TechnicalStateProvider.class, TechnicalStateProviderHome.class); implementations.put(TicketProvider.class, TicketProviderHome.class); } public <I> BSEntityProviderRemote<?> getProvider(Class<? extends BSEntityProvider> type) { try { Class<? extends BSEntityProviderHome> implementation = implementations.get(type); if (implementation == null) { return null; } return (BSEntityProviderRemote) lookupRemote(implementation).create(); } catch (RemoteException remoteException) { LOG.error("Could not create provider by home interface", remoteException); return null; } } }
Java
package com.anli.busstation.dal.ejb2.providers.homes.maintenance; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.maintenance.BusRepairmentProviderRemote; public interface BusRepairmentProviderHome extends BSEntityProviderHome<BusRepairmentProviderRemote> { }
Java
package com.anli.busstation.dal.ejb2.providers.homes.maintenance; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.maintenance.GenericTechnicalAssignmentProviderRemote; public interface TechnicalAssignmentProviderHome extends BSEntityProviderHome<GenericTechnicalAssignmentProviderRemote> { }
Java
package com.anli.busstation.dal.ejb2.providers.homes.maintenance; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.maintenance.StationServiceProviderRemote; public interface StationServiceProviderHome extends BSEntityProviderHome<StationServiceProviderRemote> { }
Java
package com.anli.busstation.dal.ejb2.providers.homes.maintenance; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.maintenance.BusRefuellingProviderRemote; public interface BusRefuellingProviderHome extends BSEntityProviderHome<BusRefuellingProviderRemote> { }
Java
package com.anli.busstation.dal.ejb2.providers.homes.maintenance; import com.anli.busstation.dal.ejb2.providers.homes.BSEntityProviderHome; import com.anli.busstation.dal.ejb2.providers.remotes.maintenance.GenericBusServiceProviderRemote; public interface BusServiceProviderHome extends BSEntityProviderHome<GenericBusServiceProviderRemote> { }
Java
package com.anli.busstation.dal.ejb2.providers.homes; import com.anli.busstation.dal.ejb2.providers.remotes.BSEntityProviderRemote; import java.rmi.RemoteException; import javax.ejb.EJBHome; public interface BSEntityProviderHome<P extends BSEntityProviderRemote> extends EJBHome { P create() throws RemoteException; }
Java