• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

storing multiple attributes for one entity

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have a site that allows users to create a project, give the project a name, decription, tags, etc. I know I can create an attriute for each of those items (String name, STring description, etc), but how do I associate all those attributes to one entity? I know that ProjectID will be the primary key. But how will the other attributes linked to that aprticular project be linked together? Or is this going to be getting into DB stuff?

Sorry, Im unable to articulate my problem more clearly

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java code, you'll use objects -- i.e., instances of a class -- to represent an entity with multiple attributes. So you might have a Project class with members like name, desription, projectId, etc.

If you're storing your entities in a database -- either "by hand", or using a tool like Hibernate -- then there would be a "projects" table, with one column for each attribute. A single row would then correspond to a Project object. When it's time to update the database, the row with a given primary key will be updated; when it's time to load the objects, each row is used to construct one Project.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So lets say I have three entities - project, device, channel - each with their own attributes. Would I make those three classes under the same package, or would I use three packages, each with a class. Or does it depend?

Then is I am using httpclient, say to put a device into a list of devices, what would be the method to put all those attributes from the class into the correct element. Here is an example of the device metadata



which would need to be put into the list of devices



I have been looking at httpclient tutorials bt I am having trouble gettign a grasp on how it all works
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Three classes in one package is a good start. The real answer is always "it depends," of course.

As far as your other question goes, httpclient is used for simulating a web user: it's for scraping around other people's web sites, or testing. It's not normally part of a new solution. It sounds like you may have some development experience, but are new to both Java and developing for the Web, am I right? Let us know a little more about what you need to accomplish, and we can probably get you going in the right direction.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You hit the nail on the head. Im majoring in MIS, will be a senior next year. A company had a design challenge at my school, my proposal won, and now I am working on an actual site that the company is going to use. Chance of a lifetime, so I dont want to miss it.

So I am developng a site where customers will register, then they can create a project. Each project will have devices added to it (temp, pressure, etc), and each device will have a web channel with data points. After the user registers and creates a project with a device (the channel automatically registers to the device) he can view it on a google map or generate different charts to see the data points over time.

Im using eclipse, tomcat, and the richfaces library to develop jsp pages. I was given a rough draft of an API that provides a url for whatever a user is looking at. For instance, if a user wants to see a list of all the devices they go to www.website.com/devices or to see a single device www.website.com/devices/{deviceID}

I was also provided what get, put, post and delete will do depending on the url. I have no previous experience with http client so Ive been learning all I can. All I am wanting to do is use post to create a new device on www.website.com/devices/{deviceID}

I knew the answer to my first question from my first post already (classes), but I was so focused on httpclient I didn't allow myself to see the bigger picture. I know I will be using putMethod put = new putMethod(), but I am having trouble getting past that part. I would like to use post to add a device and its attributes to the api, and then use get to see the response body. I am making slow pogress, so any tips would be greatly appreciated.

edit - Id say I do have beginner java experience, but liek I said I was so focused on httpclient I didnt see the bigger picture. I mean that is a fundamental element of java lol, I dont know how I let that get by
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would this be the best forum to get help with my problem or should I try one of the others?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think here is fine for now, but I'm still not sure what it is you're trying to do. I could help you look at the HttpClient documentation and work up some sample code to make a POST request, but I am not sure right now whether that actually makes sense for what you're trying to do. There might be an easier way.

In the example above, you yourself are creating a website named www.website.com, correct? It sounds like you're talking about using httpclient to talk to this website. Normally, a person just uses a web browser to talk to a web site; as I said, httpclient is for when you need to write a program that is pretending to be a person with a web browser.

So this program that uses httpclient to talk to www.website.com, where does it run? Is it a desktop application that users have? Or is it something else?
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I have been told by the contacts at the company Im doing this for that I should look at SimpleXML for what I am trying to do. I must have misunderstood what httpclient is for. Here is some sample code I was given:



This will be a web based application. Users will register a device and I was under the impression I would need to use httpclient in my code to post the device that the user registers to the second web service that accesses the database. But I have now been told I need to serialize my object into a string and then post it to the web service.

I can create the UI, so basically what I'm having trouble with is what happens after a user enters in the device information and then hits submit. How exactly do I make my application take that submitted info and post it to the web service? And then when I need to display that saved info how am I going to go about rendering it?

Kind of ambiguous info still I know, I am going to be working on it today with the new info I was given and hopefully I can clarify a bit more. But any tips you think I should know from what I have posted here would be great.

edit: for starters maybe you can help me clarify this sample code I was given. Does he mean that DeviceCollection is a class and Device is a class within that class? Or are DeviceCollection and Device their own separate classes? It seems to me they are each their own class, and then the code that is below them pertains only to DeviceCollection, not for Device. I would need to change a few of the words to make that bottom chunk of code pertain to Device. Does this seem correct?

Oh and then that bottom chunk of code, DeviceCollection readXML, is that also in a class by itself, or would that be included in the DeviceCollection class?
 
Marshal
Posts: 80267
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matt Kohanek wrote:Would this be the best forum to get help with my problem or should I try one of the others?

This forum is for beginner's questions; your question is more difficult than that. It isn't going in any specialised direction (yet), so I shall move you to "intermediate."
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds to me that this is all Web Services related. The current popular paradigm is to do this via RESTful Web Service calls although it sounds like the company you are working for is expecting you to transfer data down the wire as XML, which lends itself more to the SOAP approach. I'm going to move this to the Web Services forum, where those in the know can help out (I've only just started looking at RESTful Web Services using Spring, and that's super easy).
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ive actually already got this one figured out. I just needed to separate my classes out, and then put some things in the main method to get this working. Then I was also missing the commons-codec jar. Once I got that in it was working, but I am having a different problem that Ive already posted in this forum. https://coderanch.com/t/445170/Web-Services/java/help-figuring-out-why-am
 
Paper beats rock. Scissors beats tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic