• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking for updated values when importing data  RSS feed

 
Ranch Hand
Posts: 39
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I continue my Java journey I keep coming across questions that don't seem to have readily available answers.   Today I'm pondering how updating serialized/loaded data would work.

For example, if I have an application that maintains a list of people along with their name, address, email address, etc.   The Person class is serialized and saved and then on each run a new data file is imported that contains new People that need to be added, and updates to the existing Person objects in the class.  (maybe updated addresses or last names)

The folks at Coderanch have explained how to override the equals and hashcode methods to check for duplicate objects, but after determining that a class object already exists how do you continue on to verify that the object variables have not changed, and if different update them?

I know I can use my getters and setters for the Person class to retrieve and set new values, but how would one check hundreds of instances of Person to see if their data has been changed?  If someone can give me a push in the right direction I would be thankful.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably time to use an in-memory SQL database, like SQLite, H2, Apache DB, or HSQLDB.  (I've used SQLite.)  You would insert the data just like any DB, but you could check for duplicates or make a column unique.
 
Josh Herron
Ranch Hand
Posts: 39
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I had been saving the serialized data locally and that works great when the data does not change, but I couldn't figure out how to update it once loaded.

I'll look for a tutorial on setting up SQLlite and reading/ writing data from that.
 
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pseudo code
 
Ranch Foreman
Posts: 919
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:It's probably time to use an in-memory SQL database

I agree 100% with this. You can use SQL to retrieve all the unique data from the database and you can use SQL to make sure that you do put duplicates in the database.

In the past I've used from of the tutorials from www.w3schools.com. They let you try things in real time online and here is their SQL tutorial:
https://www.w3schools.com/SQL/

I know that there is a lot of information related to SQL and databases. If you are just starting out then I suggest you look into:
  • simple insert operations
  • simple select operations
  • simple delete operations
  • simple update operations

  • These four operations are the building blocks for a good majority of the operations within SQL.

    Please note that not all database providers (SQLite, H2, etc) implement all of the SQL functions the same way.
     
    Josh Herron
    Ranch Hand
    Posts: 39
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you all, I am going to try to work out how to update from the text file input using Carey's pseudocode... but am certainly going to start digging into SQL functions as well because I want to know multiple ways to skin the cat.
     
    Josh Herron
    Ranch Hand
    Posts: 39
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Josh Herron wrote:Thank you all, I am going to try to work out how to update from the text file input using Carey's pseudocode... but am certainly going to start digging into SQL functions as well because I want to know multiple ways to skin the cat.


    Nevermind, just realized the pseudocode was SQL commands.   Digging into that now, thanks again all!
     
    Carey Brown
    Saloon Keeper
    Posts: 3329
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Josh Herron wrote:
    Josh Herron wrote:Thank you all, I am going to try to work out how to update from the text file input using Carey's pseudocode... but am certainly going to start digging into SQL functions as well because I want to know multiple ways to skin the cat.


    Nevermind, just realized the pseudocode was SQL commands.   Digging into that now, thanks again all!

    No, it was not SQL. Just only sort of like Java. Just to give you an idea of the flow of logic.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!