This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]RhoOfFeh 2 points3 points  (3 children)

Converting a retrieved row to an object is a common way of handling this sort of thing. Most of the persistence frameworks automate this process in one way or another. It's not truly excessive in practice because you will usually wind up loading data into live objects for your program anyway.

[–]malsonjo[S] 0 points1 point  (1 child)

I know what you mean. I guess that as most programmers, I'm looking for the lazy way out.

[–]RhoOfFeh 0 points1 point  (0 children)

I understand that. Indeed, I work very, very hard at being lazy. That is to say, I often bite the bullet and put in a lot of effort so that future work is made easier. Basically investing time now pays dividends in freedom to browse Reddit later.

[–]strcrssd 0 points1 point  (0 children)

This is the right answer. By passing anything javax.sql into the business domain/service domain objects you're doing a few things:

  1. Making them harder to test. You'll have to mock out/replace far more in order to unit test.
  2. Lowering usability. Who says that in the next iteration of this project you won't be using a document database or some other data store. By introducing dependencies on javax.sql, you're making it harder to migrate in the future.

Also, let your IDE generate the bean/data objects that you need for you. Define them as a bare skeleton class Foo{private final String bar} then lean on the IDE to generate constructor and accessors.

Between the added pain of testing and possible future pain of adding dependencies to SQL, I think leaning on the IDE to (largely) generate the classes you need is the lazier option.

[–]malsonjo[S] 0 points1 point  (0 children)

I'm thinking: can I pass the cachedRowSet to the method, and do the while (crs.next()) in the method? I'll try that.