• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help for designing and grouping elements using java collection attached

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Orederid Offerid offername OfferTotal productId productName productTerm ProductDesc
1 1 Biz1 10 11 landline 1 landline
1 1 Biz1 10 22 wireless 3 wireless
1 1 Biz1 10 33 cellphone 4 cellphone
1 2 Biz2 15 44 TV 3 TV
1 2 Biz2 15 77 Cable connection 2 Cable connection
1 2 Biz2 15 22 wireless 1 wireless
1 3 Biz3 22 11 landline 3 landline
1 3 Biz3 20 33 cellphone 4 cellphone


I am getting data from database like this from one table.

Using java I want to group it based on offer ids and when I pass each offerId, I need to get lists of products[product details]

Offerid offername OfferTotal productId productName productTerm ProductDesc
1 Biz1 10 11 landline 1 landline
22 wireless 3 wireless
33 cellphone 4 cellphone

Offerid offername OfferTotal productId productName productTerm ProductDesc
2 Biz2 15 44 TV 3 TV
77 Cable connection 2 Cable connection
22 wireless 1 wireless

What would be the best design to have to have list of products in a list of offer.

offerList1[productList1,2...]
offerList2[productList1,2...]




table-details.JPG
[Thumbnail for table-details.JPG]
table
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting data from database like this from one table.
Using java I want to group it based on offer ids and when I pass each offerId, I need to get lists of products[product details]
Image was not clear I will send it again
table-to-be-grouped.JPG
[Thumbnail for table-to-be-grouped.JPG]
table
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Map<String, List<Order>>
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply , Can you please send me the sample code to do it.Does it mean Grouping offerids in MAP and Product Details in ArrayList?
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I want to get offer id to set in the some other objects.If I put offerid in MAP as key,How do I get it back?is there any method to get the key?
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I see is you haven't design your system ... you just have a batch of info retrieve from database and want it to do something on solution space ... and working this way will mess up your system to inflexibility and unmaintainable

well ... my suggestion on class design is to have 3 classes, i.e. Order , Offer , and Product.
Order one-to-many Offer
Offer one-to-may Product

so ...
in your Order class, you have a collection(e.g. ArrayList<Offer>)
in your Offer class, you have a collection(e.g. ArrayList<Product>)

normally, it is encourage to use ORM framework (e.g. Hibernate/JPA) other than JDBC

hope this will help you further research on your system
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using iBatis for persistence layer,but I can get the values in arrayList of objects.In the object,I can have details of each line as shown in the diagram.


The arraylist would be like this
List fullList = new ArrayList();
OfferProduct offerProduct1 = new OfferProduct();
offerProduct1.setOfferCatalogId("111");
offerProduct1.setOfferId("1");
offerProduct1.setOfferName("Biz1");
offerProduct1.setProductContractTerm("1");
offerProduct1.setProducAPID("1");
offerProduct1.setProductDescription("singleLine");
offerProduct1.setProductName("Phone");
OfferProduct offerProduct2 = new OfferProduct();
offerProduct2.setOfferCatalogId("112");
offerProduct2.setOfferId("2");
offerProduct2.setOfferName("Biz2");
offerProduct2.setProductContractTerm("2");
offerProduct2.setProducAPID("2");
offerProduct2.setProductDescription("singleLine2");
offerProduct2.setProductName("Phone2");
OfferProduct offerProduct3 = new OfferProduct();
offerProduct3.setOfferCatalogId("111");
offerProduct3.setOfferId("1");
offerProduct3.setOfferName("Biz1");
offerProduct3.setProductContractTerm("2");
offerProduct3.setProducAPID("3");
offerProduct3.setProductDescription("singleLine3");
offerProduct3.setProductName("Phone3");
OfferProduct offerProduct4 = new OfferProduct();
offerProduct4.setOfferCatalogId("113");
offerProduct4.setOfferId("3");
offerProduct4.setOfferName("Biz3");
offerProduct4.setProductContractTerm("2");
offerProduct4.setProducAPID("3");
offerProduct4.setProductDescription("singleLine3");
offerProduct4.setProductName("Phone3");
OfferProduct offerProduct5 = new OfferProduct();
offerProduct5.setOfferCatalogId("111");
offerProduct5.setOfferId("1");
offerProduct5.setOfferName("Biz1");
offerProduct5.setProductContractTerm("5");
offerProduct5.setProducAPID("31");
offerProduct5.setProductDescription("singleLine4");
offerProduct5.setProductName("Phone4");
OfferProduct offerProduct6 = new OfferProduct();
offerProduct6.setOfferCatalogId("112");
offerProduct6.setOfferId("2");
offerProduct6.setOfferName("Biz2");
offerProduct6.setProductContractTerm("4");
offerProduct6.setProducAPID("5");
offerProduct6.setProductDescription("singleLine4");
offerProduct6.setProductName("Phone4");

fullList.add(offerProduct1);
fullList.add(offerProduct2);
fullList.add(offerProduct3);
fullList.add(offerProduct4);
fullList.add(offerProduct5);
fullList.add(offerProduct6);


And the object is as follows
class OfferProduct{

private String offerId;
public String getOfferId() {
return offerId;
}
public void setOfferId(String offerId) {
this.offerId = offerId;
}
public String getOfferName() {
return offerName;
}
public void setOfferName(String offerName) {
this.offerName = offerName;
}
public String getOfferCatalogId() {
return offerCatalogId;
}
public void setOfferCatalogId(String offerCatalogId) {
this.offerCatalogId = offerCatalogId;
}
public String getProducAPID() {
return producAPID;
}
public void setProducAPID(String producAPID) {
this.producAPID = producAPID;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDescription() {
return productDescription;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
public String getProductContractTerm() {
return productContractTerm;
}
public void setProductContractTerm(String productContractTerm) {
this.productContractTerm = productContractTerm;
}
private String offerName;
private String offerCatalogId;
private String producAPID;
private String productName;
private String productDescription;
private String productContractTerm;


}

I think iBatis has some limitations to map to objects directly, as mentioned in the previous post,ORMapping

Your help will be greatly appreciated.
Thanks,



 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prince, please UseCodeTags. You can edit your post to add them.
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using iBatis for persistence layer,but I can get the values in arrayList of objects.In the object,I can have details of each line as shown in the diagram.


The arraylist would be like this


And the object is as follows



I think iBatis has some limitations to map to objects directly, as mentioned in the previous post,ORMapping .I do not know iBatis supports the way Hibernate supports.

Your help will be greatly appreciated.
Thanks,

 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you really telling me that you don't indent your code?
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nobody responded to my query? Is there any better solution for my problem?
 
prince davies
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to extract all offer related data in offer object and and all product related in another object and depends on number of offers,there will be n number of objects having one Offer Object maps to one List of product objects in that offer

object will have
one offer object
List of products in that offer
There will be objects like this for number of offers


but in database there is no mapping ,all data in one line of row.

like order id,offer id,offer name,product name,product id,product description ..these all values in one row
there will number of rows will be equal to number of products.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic