[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Re: Create additional views on session start

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