Derek Bright

Greenhorn
+ Follow
since Aug 28, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Derek Bright

Hi Charles, i just came out with the ejbql for the method you mentioned earlier. However, i would like to ask if the N.Recurrence is Monthly and say the date is 25th of the month, could there be a possibility that the 25th is a Monday and it happens to clash with a Weekly booking that is on a Monday also?

Currently, my understand of your method is that if N.recurrence is either a weekly or monthly i will only check for R.recurrence with weekly or monthly. Is that right?

My current flow of checking:

1) Check whether the existing bookings(R) is within the new booking(N), which includes the start date, end date, start time and end time.



2) Next, from the result set of (1), i check through the frequency with Daily.

3) If there happen to be no clash in (2), from the result set of (1), i check though frequency with Weekly or Fortnightly.

4) Again, if there happen to be no clash in(3), from the result set of (1), i check though frequency with Monthly.

According to my flow, i will go through all the conditions regardless of whether N frequency is Daily, Weekly, Fortnightly or Monthly. Did i miss out something? Please correct me if i am wrong.

Thanks~
15 years ago
hi everyone, i really appreciate all the assistance here, i guess i will try on Charles's method. It didn't struck me that sql queries could be so useful, perhaps i was so confused with the problem itself.
15 years ago
hi ritchie, you got it right there. The only thing is my system requires the ability to check for clashes whenever i input a new booking, so that they would not be any conflict of courses for the same venue at the same time.
15 years ago
hi henry, i try to clarify the thing here.

Currently, i need to write a reservation system for classrooms. The booking entity consists of the following fields: (important fields) start date, end date, recurrence type(daily, weekly, monthly, fortnightly), day of week, date of month.

Before a booking can be committed successfully, i need to validate if the booking has any clashes/conflicts with any of the existing booking for that particular classroom at the time selected for the newly made booking.

Right now, i intend to

1) use query to obtain list of bookings that use the classroom within the start and end date of the newly made booking.
2) then i use for loop to check if the existing bookings have any recurrence, if any, i need to loop again with the condition like if (the booking is weekly, fortnightly or monthly)

The question is whether i am on the right track or there could be better way in doing this?
15 years ago
thanks for the advice.

I meant to use the query for the start and end date. The problem could be i wouldn't be able to detect those activities that recurred. Even if i could do that, what if the going-to-be newly created activity also has recurrence. I don't know if i think too much...
15 years ago
hi everyone, i don't know if i have post this at the right place. Anyhow, i am facing some problems in figuring out how to approach a recurrence booking system. I am required to check if a room is available for booking. Each booking has a recurrence type: daily, weekly, fortnightly, monthly. Before i can book a venue, i need to loop through the database to see if there is any overlapping.

What is the best approach to tackle such kind of problem? Thanks~
15 years ago
just to add on to my question, is it possible to use the dtype in ejbql or are there some other alternatives?
hi, i would like to know if there is a way to create ejb query to retrieve a particular sub-class of a parent-class. Example:

abstract class test

class finalTest extends test

so is it possible to have a ejbql whereby i am able to call from the test and retrieve just the finalTest...

something like "SELECT ft FROM test t"
here goes:

this is the full code

public SubTrainingProgTemplateEntity getSubTrainingProgTemplate(Long id)
throws ExistException {

try {
Query q = em.createQuery("SELECT DISTINCT subProgT FROM SubTrainingProgTemplate subProgT " +
"LEFT JOIN FETCH subProgT.trainingActivityTemplates " +
"WHERE subProgT.id =:subProgTempId");

q.setParameter("subProgTempId", id);

SubTrainingProgTemplateEntity subProgTemp =
(SubTrainingProgTemplateEntity) q.getSingleResult();

//This code may seems redundant, but somehow
//without this line, the fetch in the sql doesn't seems to work
//Therefore, do not remove the system.out.println
//System.out.println("activity size: " + subProgTemp.getTrainingActivityTemplates().size());

return subProgTemp;

} catch (NoResultException nre) {
throw new ExistException("This template does not exist!");
}
}

** This is the code at the servlet.

remote.getSubTrainingProgTemplate(new Long(2)).getTrainingActivityTemplates().size());
Hi Reza,

Thanks for your reply, actually, i have another code exactly the same as the above and works perfectly fine, but somehow, for this entity, this problem simply persist even when i redeploy, restart computer, everything i try, but to no avail apart from adding the .getsize code which did nothing but somehow break away from the error.
Hi, i am having some problems with retrieving my entity. The error i got is:

Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.

Part of the session bean code:

Query q = em.createQuery("SELECT DISTINCT subProgT FROM SubTrainingProgTemplate subProgT " +
"LEFT JOIN FETCH subProgT.trainingActivityTemplates " +
"WHERE subProgT.id =:subProgTempId");

Well, i try to retrieve the entity in the servlet where i do this:

System.out.println("Size: " + xxx.getSubTrainingProgTemplate(new Long(xx)).getTrainingActivityTemplates().size());

Even with the use of Left Join Fetch, i still encounter the error above, which doesn't really make sense to me.

However, by adding 1 more line of code in the session bean:
xx.getTrainingActivityTemplates().size();

**The error somehow vanish, and i was able to retrieve the size value in servlet. I don't know what's happening, can anyone help me here? Thanks!
I just come across javascript to help me solve the above problem, is this the probable way or another way to ask will be is this the best way to solve the above issue?
Hi, my jsp has a button that once a user clicks, a new input field, say a textbox appears. If he clicks the button again, another new input field will appear...below is an illustration:

Add text box JSP
---------------------------
<Add New TextBox Button>

After i click the button once,
The page will become:

Add text box JSP
----------------------------
Name: ___________
<Add New TextBox Button>

After i click the button again,
The page will become:

Add text box JSP
----------------------------
Name: ___________

Name: ___________
<Add New TextBox Button>

How can this be done? And how can i retrieve such values? Thanks!
it actually only load the new image if i press refresh button. Say the image is my website banner, the 1st time i upload the image, name banner.jpg, it will immediately show after i click my save button.

However, if i change the banner with another different image, but name as banner.jpg (same as the 1st image), it will overwrite the old image in the server. The problem is, once i clicked save button, my banner is still the old image, not the newly uploaded image. Only by clicking the refresh button (F5), then it will load up the new image.

Hope i get this clear...thanks!