DraganD-Ukr / Web-Patterns-CA1

0 stars 0 forks source link

Added helper method to close resources after db operation #4

Closed DraganD-Ukr closed 1 week ago

DraganD-Ukr commented 1 month ago

I added a method that closes ResultSet, PreparedStatement and Connection objects. Since we duplicate this piece of code i want to merge it immediately, so you guys use it.

Aloy-Lockness11 commented 1 month ago

1)Is there a way of using try with resources instead of using another method in DAO just for the ResultSet and PreparedStatement?

2)If it is required then isn't it better to have the garbage collection in free connection itself rather than extrapolating it out to another method ?

public void freeConnection(Connection con){}

DraganD-Ukr commented 1 month ago

@Aloy-Lockness11

The helper method i meant: `/**

As i understood, we can try-with-resources because they implement AutoCloseable which automatically closes them at the end of the block. Basically what i did is just extracted the code that Michelle uses in here DAOs to Parent 'DAO' class.

I'm up for try-with-resources solution as it simplifies code and resource management

Just confirm it and i'm gonna implement try with resources across my part of code!

DraganD-Ukr commented 1 month ago

@Aloy-Lockness11

I assume Michelle is closing resources if they are not automatically closed. That's what that part of code does

Aloy-Lockness11 commented 1 month ago

Rogger understood

DraganD-Ukr commented 1 month ago

@Aloy-Lockness11 So, should we keep it or depend on Autoclose?

Aloy-Lockness11 commented 2 weeks ago

I have already discussed with the lecturer and she recommended us to use try with resources as it goes with standards. I have also come across this thread as well may help us decide an agreement

https://stackoverflow.com/questions/28197155/is-try-catch-more-or-less-expensive-than-try-with-resources

DraganD-Ukr commented 2 weeks ago

Than let's stick with try-with-resources

Aloy-Lockness11 commented 2 weeks ago

agreed

DraganD-Ukr commented 1 week ago

agreed on try-with-resources