Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3978824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:05:42+00:00 2026-05-20T05:05:42+00:00

I’ve seen and worked with a lot of older, JDBC-based DAO code that usually

  • 0

I’ve seen and worked with a lot of older, JDBC-based DAO code that usually start out with CRUD methods. My question relates specifically to the retrieval methods, or ‘finders’. Typically what I find is that the DAOs start out with two methods:

  • find and return ALL
  • retrieve a specific instance based on a unique identifier

More often than not, those two finders are insufficient. I usually end up seeing a DAO class repeatedly modified to add finder methods like the following:

  • find and return ALL where {condition}

What happens is that more methods are added when a new {conditions} needs to be supported or existing methods are modified to add new parameters as flags to modify the SQL query inside the method to support the additional conditions.

It’s an ugly approach and violates the Open-Closed Principle. It has always been a peeve of mine seeing DAO classes continuously modified whenever some new retrieval condition needs to be supported. Research on this question often points me to the Repository Pattern and encapsulating conditions for retrieval as Specifications or Query objects then passing them to a finder method. But this only seems feasible if you have an in-memory collection of the entire data set or if you are using some kind of ORM (I’m working with older JDBC code)

I’ve considered a solution that lazy loads the entire data set a DAO manages as a collection in-memory and then using the Specification Pattern as queries for retrieval. I then implement some kind of observer on the collection that just updates the database when creates, updates or deletes methods are called. But obviously performance and scalability suffer significantly.

Any thoughts on this?


Thank you for the responses so far. I do have one thought — what are your opinions on the use of the Command/Policy pattern to encapsulate data access requests? Each individual Concrete Command can represent a specific kind of access and can be passed to an Invoker. I’d end up with numerous Concrete Command classes, but each one will be focused on just one kind of access and should be very testable and isolated.

    public abstract class Command<R>{
       public <R> execute();
       public void setArguments(CommandArguments args){
          //store arguments  
       }
    }

    //map based structure for storing and returning arguments
    public class CommandArguments{
         public String getAsString(String key);
         public String getAsInt(String key);
         //... others
    }

    //In some business class...
    Command command = CommandFactory.create("SearchByName");
    CommandArguments args = new CommandArguments();
    args.setValue("name", name);
    // others
    command.setArguments(args);
    List<Customer> list  = command.execute();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:05:42+00:00Added an answer on May 20, 2026 at 5:05 am

    We have used iBatis for our data layer ORM and have been able to implement what you’re proposing in one query by passing a parameter object with the various fields you might wish to use as paramaters.

    Then in your WHERE clause you can specify each field as a condition clause but only if its populated in the parameter object. If only one field in the param obj is not null then its the only one that will be used to filter the results.

    Thus if you need to add fields to your parameters you just change the SQL and the paramObj. You can then have 2 methods which return ALL or a subset based on the combo of paramters passed, or at least this approach would reduce the number of queries required.

    e.g. something along the lines of…

    SELECT * FROM MY_TABLE
    WHERE FIELD_ZERO = paramObj.field0
    <isNotNull property="paramObj.field1">AND FIELD_ONE = paramObj.field1</isNotNull>
    <isNotNull property="paramObj.field2">AND FIELD_TWO = paramObj.field2</isNotNull>
    <isNotNull property="paramObj.field3">AND FIELD_THREE = paramObj.field3</isNotNull>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.