Create additional views on session start [message #390287] |
Tue, 14 July 2009 16:49  |
Eclipse User |
|
|
|
Hi,
I need to create an additional view so that my Entity class can
reference that view as its table.
Where can I create views before EL tries to map the Entity classes to
database tables?
Using a SessionCustomizer and if so how would I do that?
Thats the view I would need to create:
CREATE OR REPLACE FORCE VIEW "ORDERS_PROGRESS" ("AUF_NR", "DONE",
"SHORTFALLS") AS
select
o.auf_nr as auf_nr,
100 * (select count(*) from auftrags_positionen where auf_nr=o.auf_nr
and status!=1) / count(*) as done,
100 * (select count(*) from auftrags_positionen where auf_nr=o.auf_nr
and status=6) / count(*) as shortfalls
from
auftrags_positionen p, auftraege o where p.auf_nr = o.auf_nr
group by o.auf_nr
Thanks,
Phil
|
|
|
|
Re: Create additional views on session start [message #390299 is a reply to message #390295] |
Thu, 16 July 2009 14:43  |
Eclipse User |
|
|
|
James wrote:
> You might want to create the view in a script instead of in Java, such
> as in your ant build file, as it probably does not need to be created
> every time.
>
> You can create it from Java, using a SessionCustomizer you can execute
> the DDL, either by registering a SessionEventListener with a postLogin
> event, or just call login() on the Session in the SessionCustomizer,
> then execute the DDL.
I am currently doing it like this:
public class DemoSessionCustomizer implements SessionCustomizer {
@SuppressWarnings("nls")
public void customize(final Session session) throws Exception {
try {
session.executeSQL("select count(*) from order_infos");
} catch (final Exception e) {
session
.executeSQL("CREATE OR REPLACE FORCE VIEW order_infos (auf_nr,
done_percent, shortfalls_percent, shortfalls) AS "
+ "select "
+ " o.auf_nr as auf_nr,"
+ " 100 * (select count(*) from auftrags_positionen where
auf_nr=o.auf_nr and status!=1) / count(*) as done_percent,"
+ " 100 * (select count(*) from auftrags_positionen where
auf_nr=o.auf_nr and status=6) / count(*) as shortfalls_percent,"
+ " (select count(*) from auftrags_positionen where
auf_nr=o.auf_nr and status=6) as shortfalls"
+ " from"
+ " auftrags_positionen p, auftraege o where p.auf_nr = o.auf_nr"
+ " group by o.auf_nr");
}
}
}
It seems to work, and a login is not required.
Is that ok?
Thanks,
Phil
|
|
|
Powered by
FUDForum. Page generated in 0.05620 seconds