|
|
Re: Create additional views on session start [message #390299 is a reply to message #390295] |
Thu, 16 July 2009 14:43 |
Philipp Kursawe Messages: 135 Registered: July 2009 |
Senior Member |
|
|
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.03145 seconds