• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Display info that belongs to logged in user and not all users

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a tough time finding any example that shows me how to display files that a user has uploaded.

When i log in, it shows info from all user files.

ArrayList<UploadClass> list = user1.getFiles();
for (UploadClass files: list) {
System.out.println(files);
}

What can I do to my arrayList to only show the files for the current logged in user?
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That very much depends upon how the getFiles() method is implemented.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the hibernate method for this

 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so it's just reading a list from the DB?

If so, is there no tracking of which user uploaded the file in the first place? If not, how would it be possible to know?
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my apologies I am new to this site and new to coding.

my problem is i don't know how I would be able to set the parameter username in the array list correctly
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the list contains UploadClass items. Does that class contain any information regarding the uploading user? If not, you can't just add something to it. If so, then why would you need to add anything?

How are you expecting to know which items from the DB "belong" to the user or not?
 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Your method should be declared as:



Code to interfaces, not implementations.

And remove the cast from your return statement. The fact that you needed to put that in is a clue that there's a problem.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the list is being populated with the username and the filename that was uploaded.

My question is how do I only show the files the current user has uploaded opposed to showing all of the uploaded files
 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the username is a column of the DB table, and therefore a member of class UploadClass?

In that case, you'd modify the DB query to only fetch the list of items whose username match the one you are looking for,
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand but is my query "FROM uploadClass where username = (:username)"; ?

but how would i link the parameter?
 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure myself -- it's been many years since I've used raw Hibernate (as opposed to JPA).

As this is a Hibernate rather than servlets question, I've moved it to the ORM forum where the Hibernate-savvy will have a better chance of seeing your question.
 
chris linder
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks i appreciate you taking your time
 
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the UploadClass look like?
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic