R
Rizwan
Hi All,
I am using DAO pattern to retrieve data.
public class Location implements Serializable {
Short locationId;
String locationName;
public Location() {
}
public Location( Short locationId, String locationName) {
this.locationId = locationId;
this.locationName = locationName
}
public Short getLocationId() {
return this.locationId;
}
public void setLocationId( Short locationId ) {
this.locationId = locationId;
}
public String getLocationName() {
return this.locationName;
}
public void setLocationName( String locationName ) {
this.locationName = locationName;
}
}
public interface LocationDAO {
public Location getLocationById( Short locationId ) throws
LocationNotFoundException;
public void optionalProcessing( Location location ) throws
OptionalProcessingFailException;
}
public class LocationDAOSqlServer implements LocationDAO {
public Location getLocationById( Short locationId ) throws
LocationNotFoundException {
Location location = null;
....
return location;
}
public void optionalProcessing( Location location ) throws
OptionalProcessingFailException {
...
}
}
Now I will be calling the getLocationById() method. In some cases, I want
this method to call optionalProcessing() method from inside and in some
cases I dont want it. This will be based on a condition. If condition is
true then call the optionalProcessing() method otherwise dont.
public Location getLocationById( Short locationId ) throws
LocationNotFoundException {
Location location = null;
....
if ( condition ) {
optionalProcessing( location );
}
return location;
}
Now I can see that the condition is a boolean. My question is where to
define the condition variable. And how to set it? I should set it before
calling the getLocationById() method.
LocationDAO aLocationDAO = myDAOFactory.getLocationDAO();
Location location = aLocationDAO.getLocationById( new Short(1) );
Thanks
Rizwan
I am using DAO pattern to retrieve data.
public class Location implements Serializable {
Short locationId;
String locationName;
public Location() {
}
public Location( Short locationId, String locationName) {
this.locationId = locationId;
this.locationName = locationName
}
public Short getLocationId() {
return this.locationId;
}
public void setLocationId( Short locationId ) {
this.locationId = locationId;
}
public String getLocationName() {
return this.locationName;
}
public void setLocationName( String locationName ) {
this.locationName = locationName;
}
}
public interface LocationDAO {
public Location getLocationById( Short locationId ) throws
LocationNotFoundException;
public void optionalProcessing( Location location ) throws
OptionalProcessingFailException;
}
public class LocationDAOSqlServer implements LocationDAO {
public Location getLocationById( Short locationId ) throws
LocationNotFoundException {
Location location = null;
....
return location;
}
public void optionalProcessing( Location location ) throws
OptionalProcessingFailException {
...
}
}
Now I will be calling the getLocationById() method. In some cases, I want
this method to call optionalProcessing() method from inside and in some
cases I dont want it. This will be based on a condition. If condition is
true then call the optionalProcessing() method otherwise dont.
public Location getLocationById( Short locationId ) throws
LocationNotFoundException {
Location location = null;
....
if ( condition ) {
optionalProcessing( location );
}
return location;
}
Now I can see that the condition is a boolean. My question is where to
define the condition variable. And how to set it? I should set it before
calling the getLocationById() method.
LocationDAO aLocationDAO = myDAOFactory.getLocationDAO();
Location location = aLocationDAO.getLocationById( new Short(1) );
Thanks
Rizwan