DAO and Data Model Class Question

Sean Carrick sean at pekinsoft.com
Mon Mar 21 15:46:40 UTC 2022


Hey, All:

Before sending this message, I tried to find a general Java mailing
list, but was unable to find one, so I will ask this question here for
now. If you all know of a general java discussion list, please let me
know!

I am creating a program and am currently working on the data library
for it. I am creating Java Beans for the record data and am doing some
data validation in the setters, but am stumped if a certain task is
allowed, or will cause a cyclic reference. Let me explain with some
code snippets.

I have created a Java Bean called Stop, which looks like this (snipped
the setters/getters for brevity):

public class Stop {
    private long id;
    private String orderNumber;  // "foreign key" to another table
    private int stopNumber;
    // etc.

    public void setStopNumber(int stopNumber) {
        if (stopNumber <= 0) {
            throw new IllegalArgumentException("stopNumber <= 0");
        }
        // Need to verify if the stop number has already been taken
with the orderNumber.

        this.stopNumber = stopNumber;
    }
}

Now, I have a generic DAO class that takes care of non-data-specific
operations for saving/loading the data from files, and a Stops DAO
object that handles the data-specific operations for the Stop Java
Bean. All of that is no problem. What I'm not sure about is, can I
include an instance of the StopsTable DAO in my Stop Java Bean, so
that I can verify that the stopNumber specified to the setStopNumber
method has not already been used in conjunction with the order
represented by the orderNumber field? If I were to try to add a
StopsTable instance into the Stop Java Bean, would that cause a cyclic
reference? The reason that I am asking is, when I created my
StopsTable DAO, I did so like this:

public abstract class DataTable<T> {
    // Class definition.
}

public class StopsTable extends DataTable<Stop> {
    // Class definition, which implements three abstract methods that
are data-specific.
}

Because of passing the Stop Java Bean as the type parameter to the
DataTable abstract class, I believe that I am not able to add a
StopsTable instance into my Java Bean. Am I correct in this thought?

If I am correct that the StopsTable instance in the Stop Java Bean
would be cyclic reference, can anyone point me to a valid solution for
my problem of verifying that the supplied parameter to setStopNumber
has not already been used in the StopsTable with the same orderNumber?

Thank you all for your help!

-SC


More information about the jdk-dev mailing list