Good Evening;
I have constructed a Treatment Pojo using appgen. But I would like behavior
a little different from the usually CRUD.
Each time the bean is created the following must happen:
1. Select a row from a table using a where clause containing a value passed
in from the user.
2. Set the state of the object based on values from the selected row.
3. Update a value in the row, ensuring it will not be selected again.
Is there a way I can do this by defining specific select logic in the
Treatment.hbm.xml?
How about a stored procedure to do this.
I was thinking of:
1. Define the stored proc in the mySQL DB (selectTreatment) that will select
the column and then update the value to ensure this row is not selected
again.
2. In the Treatment.hbm.xml I will do something like this:
<sql-query name="selectTreatment" callable="true">
<return alias="pt" class="Treatment">
<return-property name="treatmentId" column="treatmentId"/>
<return-property name="patientCode" column="patientCode"/>
</return>
{ ? = call selectPatient(countryCode) }
</sql-query>
3. In my TreatmentDaoHibernate I would have:
public Treatment getTreatment(String countryCode) {
Treatment t = //somehow call procedure here?
if (patient == null) {
throw new ObjectRetrievalFailureException(Patient.class, countryCode);
}
return t;
}
4. Then my FormController can just do something like this:
treatment = treatmentManager.getTreatment(countryCode);
Does the above make any sense at all? Is there an easier way to do this?
If the stored proc idea looks ok, how do I call it (maybe if some code point
to an example of using a stored proc in a Appfuse generated spring project)?
Thanks,
Luke
On 3/7/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
Within an Appfuse project is there an easy way to get a hibernate
session and execute an HQL query and update?
Sorry if this is an obvious spring beginner question, still trying to
figure out everything going on here.
I'm doing this in my onSubmit method of one of my form controlers to
inject some data into a newly created object.
I was thinking of doing this in the formBackingObject but the else
block where the new object is created gets called twice (not sure
why).
Thanks,
Luke
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
String patientId = request.getParameter("patientId");
Patient patient = null;
if (!StringUtils.isEmpty(patientId)) {
patient = patientManager.getPatient(patientId);
} else {
//this gets called twice
patient = new Patient();
}
return patient;
}
On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> Hi Matt;
>
> I may be able to achieve my goal by calling a stored procedure using
> hibernate. The last part of chapter 7 of your book has me thinking
> this will work.
>
> I am going to give this a try tomorrow.
>
> Luke
>
> On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > Ah, I know the feeling. Thanks for getting back to me though :-)
> >
> > I am reading your chapter in Spring Live on Hibernate (Chapter 7). I'm
> > hoping to figure out a better way to do this from that.
> >
> > BTW: This is a great book!
> >
> > Luke
> >
> > On 3/6/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > > Nope, I'm just swamped with work right now and couldn't think of an
> > > easy answer. ;-)
> > >
> > > Matt
> > >
> > > On 3/6/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > Hi Matt;
> > > >
> > > > Am I totally missing the point with the code I sent?
> > > >
> > > > Thanks,
> > > >
> > > > Luke
> > > >
> > > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > BTW:
> > > > >
> > > > > PatientData is an inner class of the
PatientFormController class
> > > > > (just in case it wasn't clear).
> > > > >
> > > > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > > Hi Matt;
> > > > > >
> > > > > > Actually I am going to do something like below. The data I'm
getting
> > > > > > this from is a seperate DB table than the ones I have
generated using
> > > > > > appfuse (I have created my own ETL process to build it). Is
this the
> > > > > > hard way to do it? I am still learning hibernate and spring so
I am
> > > > > > not totally comfortable with the framework.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Luke
> > > > > >
> > > > > > public ModelAndView onSubmit(HttpServletRequest request,
> > > > > > HttpServletResponse response,
Object command,
> > > > > > BindException errors)
> > > > > > throws Exception {
> > > > > > if (log.isDebugEnabled()) {
> > > > > > log.debug("entering 'onSubmit' method...");
> > > > > > }
> > > > > >
> > > > > > Patient patient = (Patient) command;
> > > > > > boolean isNew = (patient.getPatientId() == null);
> > > > > > Locale locale = request.getLocale();
> > > > > >
> > > > > > if (request.getParameter("delete") != null) {
> > > > > > patientManager.removePatient(patient.getPatientId
().toString());
> > > > > >
> > > > > > saveMessage(request, getText("patient.deleted",
locale));
> > > > > > } else {
> > > > > > String countryId = request.getParameter("countryId");
> > > > > > String doctorId = request.getParameter
("doctorId");
> > > > > > PatientData p_data = new PatientData(countryId);
> > > > > > patient.setPatientTag(p_data.getTag());
> > > > > > patient.setTreatmentarm(p_data.getTreatmentArm());
> > > > > > patient.setDoctorId(new Long(doctorId));//this is
going to
> > > > > > come from the request
> > > > > > patientManager.savePatient(patient);
> > > > > >
> > > > > > String key = (isNew) ? "patient.added" : "
patient.updated";
> > > > > > saveMessage(request, getText(key, locale));
> > > > > >
> > > > > > if (!isNew) {
> > > > > > return new ModelAndView("redirect:
editPatient.html",
> > > > > > "patientId", patient.getPatientId());
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > return new ModelAndView(getSuccessView());
> > > > > > }
> > > > > > public class PatientData {
> > > > > > private String tag;
> > > > > > private int treatmentArm;
> > > > > > PatientData(String countryId) {
> > > > > > //connect to the DB to get the next available
values for the countryId
> > > > > > this.tag = "value from DB";
> > > > > > this.treatmentArm = 0;//value from the DB
> > > > > > //update the assignment date so these values
will not be selected again
> > > > > > }
> > > > > > /**
> > > > > > * @return the tag
> > > > > > */
> > > > > > public String getTag() {
> > > > > > return tag;
> > > > > > }
> > > > > > /**
> > > > > > * @param tag the tag to set
> > > > > > */
> > > > > > public void setTag(String tag) {
> > > > > > this.tag = tag;
> > > > > > }
> > > > > > /**
> > > > > > * @return the treatmentArm
> > > > > > */
> > > > > > public int getTreatmentArm() {
> > > > > > return treatmentArm;
> > > > > > }
> > > > > > /**
> > > > > > * @param treatmentArm the treatmentArm to set
> > > > > > */
> > > > > > public void setTreatmentArm(int treatmentArm)
{
> > > > > > this.treatmentArm = treatmentArm;
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 3/5/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > > > > > > The method of how data is retrieved from the database should
already
> > > > > > > be setup for you - with Managers, DAOs, etc. Showing us
pseudo code
> > > > > > > for what you're trying to do with make it much easier to
help.
> > > > > > >
> > > > > > > Matt
> > > > > > >
> > > > > > > On 3/5/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > > > > Thanks Mat, formBackingObject() seems to be the way to go.
Do you see
> > > > > > > > any problem using the Jakarta-Commons DB connection pool
to obtain the
> > > > > > > > data from the DB? Or is there a better approach to this?
> > > > > > > >
> > > > > > > > On 3/4/07, Matt Raible <[EMAIL PROTECTED]> wrote:
> > > > > > > > > You could do this in your DAO where you originally fetch
everything. Also,
> > > > > > > > > there's logic in your FormController's
formBackingObject() that gets your
> > > > > > > > > object from the database before populating it from
request parameters. This
> > > > > > > > > means you don't have to store these fields in hidden
fields. If this
> > > > > > > > > doesn't work, you might try storing the non-editable
fields in hidden fields
> > > > > > > > > or read-only fields.
> > > > > > > > >
> > > > > > > > > Matt
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > On 3/4/07, Luke Shannon <[EMAIL PROTECTED]> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi;
> > > > > > > > > >
> > > > > > > > > > This may be a more of a Spring question, although I am
hoping there is
> > > > > > > > > > something within the Appfuse tools to assist with
this.
> > > > > > > > > >
> > > > > > > > > > I have a Pojo I have created in my application and I
have used Appgen
> > > > > > > > > > to create everything I need for the CRUD operations.
> > > > > > > > > >
> > > > > > > > > > What I would like to do now is modify the application
so specific
> > > > > > > > > > fields in the Pojo are set using data from a DB and
not from user
> > > > > > > > > > input from the web tier.
> > > > > > > > > >
> > > > > > > > > > Working within the Struts framework (Appfuse 1.9.4)
where is the best
> > > > > > > > > > place to implement such a change? Is there a best
practise for
> > > > > > > > > > something like this?
> > > > > > > > > >
> > > > > > > > > > Thanks,
> > > > > > > > > >
> > > > > > > > > > Luke
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
---------------------------------------------------------------------
> > > > > > > > > > To unsubscribe, e-mail:
> > > > > > > > > [EMAIL PROTECTED]
> > > > > > > > > > For additional commands, e-mail:
[EMAIL PROTECTED]
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > > http://raibledesigns.com
> > > > > > > >
> > > > > > > >
---------------------------------------------------------------------
> > > > > > > > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > > > > > > For additional commands, e-mail:
[EMAIL PROTECTED]
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > http://raibledesigns.com
> > > > > > >
> > > > > > >
---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > > > > > For additional commands, e-mail:
[EMAIL PROTECTED]
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > > >
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > >
> > > --
> > > http://raibledesigns.com
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
>