Last active
September 25, 2017 08:34
-
-
Save chongma/3191cbd0d4cd4a84c7cffb9e8bfe5373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.kissy.entities.sales.quote; | |
import java.io.Serializable; | |
public class Description implements Serializable { | |
private static final long serialVersionUID = 1L; | |
private int descriptionId; | |
private int descriptionTypeId; | |
private String body; | |
private boolean omit; | |
public int getDescriptionId() { | |
return descriptionId; | |
} | |
public void setDescriptionId(int descriptionId) { | |
this.descriptionId = descriptionId; | |
} | |
public int getDescriptionTypeId() { | |
return descriptionTypeId; | |
} | |
public void setDescriptionTypeId(int descriptionTypeId) { | |
this.descriptionTypeId = descriptionTypeId; | |
} | |
public String getBody() { | |
return body; | |
} | |
public void setBody(String body) { | |
this.body = body; | |
} | |
public boolean isOmit() { | |
return omit; | |
} | |
public void setOmit(boolean omit) { | |
this.omit = omit; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.kissy.sales.dao; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import javax.persistence.EntityManager; | |
import javax.persistence.TypedQuery; | |
import javax.persistence.criteria.CriteriaBuilder; | |
import javax.persistence.criteria.CriteriaQuery; | |
import javax.persistence.criteria.Root; | |
import org.apache.commons.lang3.StringUtils; | |
import uk.me.kissy.entities.sales.quote.Descriptions; | |
import uk.me.kissy.sales.entities.jpa.DescriptionZ; | |
import uk.me.kissy.sales.entities.jpa.DescriptionZ_; | |
@ApplicationScoped | |
public class DescriptionDao { | |
@Inject | |
private EntityManager em; | |
public List<DescriptionZ> selectDescriptions(int type) { | |
CriteriaBuilder cb = em.getCriteriaBuilder(); | |
CriteriaQuery<DescriptionZ> cq = cb.createQuery(DescriptionZ.class); | |
Root<DescriptionZ> description = cq.from(DescriptionZ.class); | |
cq.select(description); | |
if (type > -1) | |
cq.where(cb.equal(description.get(DescriptionZ_.type), type)); | |
cq.orderBy(cb.asc(description.get(DescriptionZ_.body))); | |
final TypedQuery<DescriptionZ> tq = em.createQuery(cq); | |
List<DescriptionZ> descriptionList = tq.getResultList(); | |
return descriptionList; | |
} | |
private Descriptions convert(List<DescriptionZ> descriptionList) { | |
List<uk.me.kissy.entities.sales.quote.Description> dList = new ArrayList<>(); | |
for (DescriptionZ description : descriptionList) { | |
dList.add(convert(description)); | |
} | |
Descriptions descriptions = new Descriptions(); | |
descriptions.setDescription(dList); | |
return descriptions; | |
} | |
public uk.me.kissy.entities.sales.quote.Description convert(DescriptionZ description) { | |
if (description == null) | |
return null; | |
uk.me.kissy.entities.sales.quote.Description d = new uk.me.kissy.entities.sales.quote.Description(); | |
d.setDescriptionId(description.getId()); | |
d.setDescriptionTypeId(description.getType()); | |
d.setBody(description.getBody()); | |
d.setOmit(description.isOmitvalue()); | |
return d; | |
} | |
public Descriptions selectDescriptionsOld(int type) { | |
List<DescriptionZ> descriptionList = selectDescriptions(type); | |
Descriptions descriptions = convert(descriptionList); | |
return descriptions; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.kissy.entities.sales.quote; | |
import java.io.Serializable; | |
import java.util.List; | |
import javax.xml.bind.annotation.XmlRootElement; | |
@XmlRootElement | |
public class Descriptions implements Serializable { | |
private static final long serialVersionUID = 1L; | |
private List<Description> description; | |
public List<Description> getDescription() { | |
return description; | |
} | |
public void setDescription(List<Description> description) { | |
this.description = description; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.kissy.sales.entities.jpa; | |
import java.io.Serializable; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.Lob; | |
import javax.persistence.Table; | |
import javax.persistence.Version; | |
@Entity | |
@Table(name = "description") | |
public class DescriptionZ implements Serializable { | |
private static final long serialVersionUID = 1L; | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private int id; | |
@Version | |
private Long version; | |
@Lob | |
private String body; | |
private int type; | |
private boolean omitvalue; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getBody() { | |
return body; | |
} | |
public void setBody(String body) { | |
this.body = body; | |
} | |
public int getType() { | |
return type; | |
} | |
public void setType(int type) { | |
this.type = type; | |
} | |
public boolean isOmitvalue() { | |
return omitvalue; | |
} | |
public void setOmitvalue(boolean omitvalue) { | |
this.omitvalue = omitvalue; | |
} | |
public Long getVersion() { | |
return version; | |
} | |
protected void setVersion(Long version) { | |
this.version = version; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.kissy.sales.rs; | |
import java.util.List; | |
import javax.inject.Inject; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.POST; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.QueryParam; | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Response; | |
import uk.me.kissy.entities.sales.quote.Descriptions; | |
@Path("/homeconvey") | |
@Produces(MediaType.APPLICATION_XML) | |
public class HomeConveyRS { | |
@Inject | |
private DescriptionDao descriptionDao; | |
@Path("/selectDescriptions") | |
@GET | |
public Response selectDescriptions(@QueryParam("type") int type) { | |
Descriptions descriptions = descriptionDao.selectDescriptionsOld(type); | |
return Response.ok (descriptions).build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment