Skip to content

Commit

Permalink
Drop iso-country-code placeholder relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
ghacupha committed Sep 20, 2023
1 parent f171ec8 commit 7919b82
Show file tree
Hide file tree
Showing 14 changed files with 732 additions and 210 deletions.
12 changes: 12 additions & 0 deletions .jhipster/IsoCountryCode.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
{
"fieldName": "countryDescription",
"fieldType": "String"
},
{
"fieldName": "continentCode",
"fieldType": "String"
},
{
"fieldName": "continentName",
"fieldType": "String"
},
{
"fieldName": "subRegion",
"fieldType": "String"
}
],
"incrementalChangelog": false,
Expand Down
61 changes: 38 additions & 23 deletions src/main/java/io/github/erp/domain/IsoCountryCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
Expand Down Expand Up @@ -49,15 +46,14 @@ public class IsoCountryCode implements Serializable {
@Column(name = "country_description")
private String countryDescription;

@ManyToMany
@JoinTable(
name = "rel_iso_country_code__placeholder",
joinColumns = @JoinColumn(name = "iso_country_code_id"),
inverseJoinColumns = @JoinColumn(name = "placeholder_id")
)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties(value = { "containingPlaceholder" }, allowSetters = true)
private Set<Placeholder> placeholders = new HashSet<>();
@Column(name = "continent_code")
private String continentCode;

@Column(name = "continent_name")
private String continentName;

@Column(name = "sub_region")
private String subRegion;

// jhipster-needle-entity-add-field - JHipster will add fields here

Expand Down Expand Up @@ -100,29 +96,45 @@ public void setCountryDescription(String countryDescription) {
this.countryDescription = countryDescription;
}

public Set<Placeholder> getPlaceholders() {
return this.placeholders;
public String getContinentCode() {
return this.continentCode;
}

public IsoCountryCode continentCode(String continentCode) {
this.setContinentCode(continentCode);
return this;
}

public void setPlaceholders(Set<Placeholder> placeholders) {
this.placeholders = placeholders;
public void setContinentCode(String continentCode) {
this.continentCode = continentCode;
}

public IsoCountryCode placeholders(Set<Placeholder> placeholders) {
this.setPlaceholders(placeholders);
return this;
public String getContinentName() {
return this.continentName;
}

public IsoCountryCode addPlaceholder(Placeholder placeholder) {
this.placeholders.add(placeholder);
public IsoCountryCode continentName(String continentName) {
this.setContinentName(continentName);
return this;
}

public IsoCountryCode removePlaceholder(Placeholder placeholder) {
this.placeholders.remove(placeholder);
public void setContinentName(String continentName) {
this.continentName = continentName;
}

public String getSubRegion() {
return this.subRegion;
}

public IsoCountryCode subRegion(String subRegion) {
this.setSubRegion(subRegion);
return this;
}

public void setSubRegion(String subRegion) {
this.subRegion = subRegion;
}

// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

@Override
Expand All @@ -149,6 +161,9 @@ public String toString() {
"id=" + getId() +
", countryCode='" + getCountryCode() + "'" +
", countryDescription='" + getCountryDescription() + "'" +
", continentCode='" + getContinentCode() + "'" +
", continentName='" + getContinentName() + "'" +
", subRegion='" + getSubRegion() + "'" +
"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,12 @@
*/

import io.github.erp.domain.IsoCountryCode;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
* Spring Data SQL repository for the IsoCountryCode entity.
*/
@SuppressWarnings("unused")
@Repository
public interface IsoCountryCodeRepository extends JpaRepository<IsoCountryCode, Long>, JpaSpecificationExecutor<IsoCountryCode> {
@Query(
value = "select distinct isoCountryCode from IsoCountryCode isoCountryCode left join fetch isoCountryCode.placeholders",
countQuery = "select count(distinct isoCountryCode) from IsoCountryCode isoCountryCode"
)
Page<IsoCountryCode> findAllWithEagerRelationships(Pageable pageable);

@Query("select distinct isoCountryCode from IsoCountryCode isoCountryCode left join fetch isoCountryCode.placeholders")
List<IsoCountryCode> findAllWithEagerRelationships();

@Query(
"select isoCountryCode from IsoCountryCode isoCountryCode left join fetch isoCountryCode.placeholders where isoCountryCode.id =:id"
)
Optional<IsoCountryCode> findOneWithEagerRelationships(@Param("id") Long id);
}
public interface IsoCountryCodeRepository extends JpaRepository<IsoCountryCode, Long>, JpaSpecificationExecutor<IsoCountryCode> {}
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ protected Specification<IsoCountryCode> createSpecification(IsoCountryCodeCriter
specification =
specification.and(buildStringSpecification(criteria.getCountryDescription(), IsoCountryCode_.countryDescription));
}
if (criteria.getPlaceholderId() != null) {
specification =
specification.and(
buildSpecification(
criteria.getPlaceholderId(),
root -> root.join(IsoCountryCode_.placeholders, JoinType.LEFT).get(Placeholder_.id)
)
);
if (criteria.getContinentCode() != null) {
specification = specification.and(buildStringSpecification(criteria.getContinentCode(), IsoCountryCode_.continentCode));
}
if (criteria.getContinentName() != null) {
specification = specification.and(buildStringSpecification(criteria.getContinentName(), IsoCountryCode_.continentName));
}
if (criteria.getSubRegion() != null) {
specification = specification.and(buildStringSpecification(criteria.getSubRegion(), IsoCountryCode_.subRegion));
}
}
return specification;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ public interface IsoCountryCodeService {
*/
Page<IsoCountryCodeDTO> findAll(Pageable pageable);

/**
* Get all the isoCountryCodes with eager load of many-to-many relationships.
*
* @param pageable the pagination information.
* @return the list of entities.
*/
Page<IsoCountryCodeDTO> findAllWithEagerRelationships(Pageable pageable);

/**
* Get the "id" isoCountryCode.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public class IsoCountryCodeCriteria implements Serializable, Criteria {

private StringFilter countryDescription;

private LongFilter placeholderId;
private StringFilter continentCode;

private StringFilter continentName;

private StringFilter subRegion;

private Boolean distinct;

Expand All @@ -58,7 +62,9 @@ public IsoCountryCodeCriteria(IsoCountryCodeCriteria other) {
this.id = other.id == null ? null : other.id.copy();
this.countryCode = other.countryCode == null ? null : other.countryCode.copy();
this.countryDescription = other.countryDescription == null ? null : other.countryDescription.copy();
this.placeholderId = other.placeholderId == null ? null : other.placeholderId.copy();
this.continentCode = other.continentCode == null ? null : other.continentCode.copy();
this.continentName = other.continentName == null ? null : other.continentName.copy();
this.subRegion = other.subRegion == null ? null : other.subRegion.copy();
this.distinct = other.distinct;
}

Expand Down Expand Up @@ -112,19 +118,49 @@ public void setCountryDescription(StringFilter countryDescription) {
this.countryDescription = countryDescription;
}

public LongFilter getPlaceholderId() {
return placeholderId;
public StringFilter getContinentCode() {
return continentCode;
}

public StringFilter continentCode() {
if (continentCode == null) {
continentCode = new StringFilter();
}
return continentCode;
}

public void setContinentCode(StringFilter continentCode) {
this.continentCode = continentCode;
}

public StringFilter getContinentName() {
return continentName;
}

public StringFilter continentName() {
if (continentName == null) {
continentName = new StringFilter();
}
return continentName;
}

public void setContinentName(StringFilter continentName) {
this.continentName = continentName;
}

public StringFilter getSubRegion() {
return subRegion;
}

public LongFilter placeholderId() {
if (placeholderId == null) {
placeholderId = new LongFilter();
public StringFilter subRegion() {
if (subRegion == null) {
subRegion = new StringFilter();
}
return placeholderId;
return subRegion;
}

public void setPlaceholderId(LongFilter placeholderId) {
this.placeholderId = placeholderId;
public void setSubRegion(StringFilter subRegion) {
this.subRegion = subRegion;
}

public Boolean getDistinct() {
Expand All @@ -148,14 +184,16 @@ public boolean equals(Object o) {
Objects.equals(id, that.id) &&
Objects.equals(countryCode, that.countryCode) &&
Objects.equals(countryDescription, that.countryDescription) &&
Objects.equals(placeholderId, that.placeholderId) &&
Objects.equals(continentCode, that.continentCode) &&
Objects.equals(continentName, that.continentName) &&
Objects.equals(subRegion, that.subRegion) &&
Objects.equals(distinct, that.distinct)
);
}

@Override
public int hashCode() {
return Objects.hash(id, countryCode, countryDescription, placeholderId, distinct);
return Objects.hash(id, countryCode, countryDescription, continentCode, continentName, subRegion, distinct);
}

// prettier-ignore
Expand All @@ -165,7 +203,9 @@ public String toString() {
(id != null ? "id=" + id + ", " : "") +
(countryCode != null ? "countryCode=" + countryCode + ", " : "") +
(countryDescription != null ? "countryDescription=" + countryDescription + ", " : "") +
(placeholderId != null ? "placeholderId=" + placeholderId + ", " : "") +
(continentCode != null ? "continentCode=" + continentCode + ", " : "") +
(continentName != null ? "continentName=" + continentName + ", " : "") +
(subRegion != null ? "subRegion=" + subRegion + ", " : "") +
(distinct != null ? "distinct=" + distinct + ", " : "") +
"}";
}
Expand Down
36 changes: 28 additions & 8 deletions src/main/java/io/github/erp/service/dto/IsoCountryCodeDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
*/

import java.io.Serializable;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
* A DTO for the {@link io.github.erp.domain.IsoCountryCode} entity.
Expand All @@ -34,7 +32,11 @@ public class IsoCountryCodeDTO implements Serializable {

private String countryDescription;

private Set<PlaceholderDTO> placeholders = new HashSet<>();
private String continentCode;

private String continentName;

private String subRegion;

public Long getId() {
return id;
Expand All @@ -60,12 +62,28 @@ public void setCountryDescription(String countryDescription) {
this.countryDescription = countryDescription;
}

public Set<PlaceholderDTO> getPlaceholders() {
return placeholders;
public String getContinentCode() {
return continentCode;
}

public void setContinentCode(String continentCode) {
this.continentCode = continentCode;
}

public String getContinentName() {
return continentName;
}

public void setContinentName(String continentName) {
this.continentName = continentName;
}

public String getSubRegion() {
return subRegion;
}

public void setPlaceholders(Set<PlaceholderDTO> placeholders) {
this.placeholders = placeholders;
public void setSubRegion(String subRegion) {
this.subRegion = subRegion;
}

@Override
Expand Down Expand Up @@ -96,7 +114,9 @@ public String toString() {
"id=" + getId() +
", countryCode='" + getCountryCode() + "'" +
", countryDescription='" + getCountryDescription() + "'" +
", placeholders=" + getPlaceholders() +
", continentCode='" + getContinentCode() + "'" +
", continentName='" + getContinentName() + "'" +
", subRegion='" + getSubRegion() + "'" +
"}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ public Page<IsoCountryCodeDTO> findAll(Pageable pageable) {
return isoCountryCodeRepository.findAll(pageable).map(isoCountryCodeMapper::toDto);
}

public Page<IsoCountryCodeDTO> findAllWithEagerRelationships(Pageable pageable) {
return isoCountryCodeRepository.findAllWithEagerRelationships(pageable).map(isoCountryCodeMapper::toDto);
}

@Override
@Transactional(readOnly = true)
public Optional<IsoCountryCodeDTO> findOne(Long id) {
log.debug("Request to get IsoCountryCode : {}", id);
return isoCountryCodeRepository.findOneWithEagerRelationships(id).map(isoCountryCodeMapper::toDto);
return isoCountryCodeRepository.findById(id).map(isoCountryCodeMapper::toDto);
}

@Override
Expand Down
Loading

0 comments on commit 7919b82

Please sign in to comment.