Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update entity #12

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .jhipster/Cart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-many",
"relationshipName": "item",
"otherEntityName": "item",
"otherEntityRelationshipName": "cart"
},
{
"relationshipType": "one-to-one",
"relationshipName": "customer",
"otherEntityName": "customer",
"ownerSide": false,
"otherEntityRelationshipName": "cart"
}
],
"fields": [],
"changelogDate": "20171208125341",
"entityTableName": "cart",
"dto": "no",
"pagination": "no",
"service": "no",
"jpaMetamodelFiltering": false
}
8 changes: 5 additions & 3 deletions .jhipster/Customer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-many",
"relationshipName": "item",
"otherEntityName": "item",
"relationshipType": "one-to-one",
"relationshipName": "cart",
"otherEntityName": "cart",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "customer"
}
],
Expand Down
6 changes: 3 additions & 3 deletions .jhipster/Item.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"otherEntityField": "id"
},
{
"relationshipName": "customer",
"otherEntityName": "customer",
"relationshipName": "cart",
"otherEntityName": "cart",
"relationshipType": "many-to-one",
"otherEntityField": "id"
}
Expand All @@ -34,7 +34,7 @@
"changelogDate": "20171118104226",
"entityTableName": "item",
"dto": "no",
"pagination": "infinite-scroll",
"pagination": "pagination",
"service": "serviceClass",
"jpaMetamodelFiltering": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public JCacheManagerCustomizer cacheManagerCustomizer() {
cm.createCache(org.apeps.firstapp.domain.Category.class.getName() + ".items", jcacheConfiguration);
cm.createCache(org.apeps.firstapp.domain.Customer.class.getName(), jcacheConfiguration);
cm.createCache(org.apeps.firstapp.domain.Customer.class.getName() + ".items", jcacheConfiguration);
cm.createCache(org.apeps.firstapp.domain.Cart.class.getName(), jcacheConfiguration);
cm.createCache(org.apeps.firstapp.domain.Cart.class.getName() + ".items", jcacheConfiguration);
// jhipster-needle-ehcache-add-entry
};
}
Expand Down
111 changes: 111 additions & 0 deletions src/main/java/org/apeps/firstapp/domain/Cart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package org.apeps.firstapp.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
* A Cart.
*/
@Entity
@Table(name = "cart")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Cart implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;

@OneToMany(mappedBy = "cart")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Item> items = new HashSet<>();

@OneToOne(mappedBy = "cart")
@JsonIgnore
private Customer customer;

// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Set<Item> getItems() {
return items;
}

public Cart items(Set<Item> items) {
this.items = items;
return this;
}

public Cart addItem(Item item) {
this.items.add(item);
item.setCart(this);
return this;
}

public Cart removeItem(Item item) {
this.items.remove(item);
item.setCart(null);
return this;
}

public void setItems(Set<Item> items) {
this.items = items;
}

public Customer getCustomer() {
return customer;
}

public Cart customer(Customer customer) {
this.customer = customer;
return this;
}

public void setCustomer(Customer customer) {
this.customer = customer;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Cart cart = (Cart) o;
if (cart.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), cart.getId());
}

@Override
public int hashCode() {
return Objects.hashCode(getId());
}

@Override
public String toString() {
return "Cart{" +
"id=" + getId() +
"}";
}
}
34 changes: 9 additions & 25 deletions src/main/java/org/apeps/firstapp/domain/Customer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.apeps.firstapp.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
Expand Down Expand Up @@ -37,10 +34,9 @@ public class Customer implements Serializable {
@Column(name = "telephone")
private String telephone;

@OneToMany(mappedBy = "customer")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Item> items = new HashSet<>();
@OneToOne
@JoinColumn(unique = true)
private Cart cart;

// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
Expand Down Expand Up @@ -103,29 +99,17 @@ public void setTelephone(String telephone) {
this.telephone = telephone;
}

public Set<Item> getItems() {
return items;
public Cart getCart() {
return cart;
}

public Customer items(Set<Item> items) {
this.items = items;
public Customer cart(Cart cart) {
this.cart = cart;
return this;
}

public Customer addItem(Item item) {
this.items.add(item);
item.setCustomer(this);
return this;
}

public Customer removeItem(Item item) {
this.items.remove(item);
item.setCustomer(null);
return this;
}

public void setItems(Set<Item> items) {
this.items = items;
public void setCart(Cart cart) {
this.cart = cart;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/apeps/firstapp/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Item implements Serializable {
private Category category;

@ManyToOne
private Customer customer;
private Cart cart;

// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
Expand Down Expand Up @@ -100,17 +100,17 @@ public void setCategory(Category category) {
this.category = category;
}

public Customer getCustomer() {
return customer;
public Cart getCart() {
return cart;
}

public Item customer(Customer customer) {
this.customer = customer;
public Item cart(Cart cart) {
this.cart = cart;
return this;
}

public void setCustomer(Customer customer) {
this.customer = customer;
public void setCart(Cart cart) {
this.cart = cart;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/apeps/firstapp/repository/CartRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.apeps.firstapp.repository;

import org.apeps.firstapp.domain.Cart;
import org.springframework.stereotype.Repository;

import org.springframework.data.jpa.repository.*;


/**
* Spring Data JPA repository for the Cart entity.
*/
@SuppressWarnings("unused")
@Repository
public interface CartRepository extends JpaRepository<Cart, Long> {

}
Loading