I don't have a ton of knowledge about Java, so I was wondering if someone could give me an idea about the best way to structure this application (or whether it even matters).
I have a situation where I am pulling data from a flat file and committing it to a SQL database. However, the particular prepared statement that I use depends on the file extension.
So essentially
- program checks the file extension.
- Opens file, creates buffered reader - reads string data.
- based on file extension, generates prepared statement.
- Adds prepared statement to batchlist.
- Repeats for each line in the file (there could be thousands of lines).
- Executes the prepared statements.
The way that I determine how to get from file extension to appropriate prepared statement is a Map (which calls the relevant method from a bunch that all implement the same interface).
There are two ways I could implement this.
Pass the connection and the buffered reader to the appropriate method and it will do all the work (generate thousands of prepared statements and execute them. The method returns 'void').
Pass the connection and the string for a line to the appropriate method. The method returns the prepared statement. The original application generates another string (the next line), passes it to the method which returns a prepared statement, etc...until the original application executes all of the prepared statements.
Essentially, option number 1 requires more code and option number 2 requires thousands of method calls.
Oh and it might be important to note that each method call is conditional based on using the ".equals()" method to check a string against the appropriate key in the map.
Thanks.