Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Create additional views on session start
Create additional views on session start [message #390287] Tue, 14 July 2009 12:49 Go to next message
Philipp Kursawe is currently offline Philipp Kursawe
Messages: 135
Registered: July 2009
Senior Member
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 #390295 is a reply to message #390287] Thu, 16 July 2009 10:10 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: Create additional views on session start [message #390299 is a reply to message #390295] Thu, 16 July 2009 10:43 Go to previous message
Philipp Kursawe is currently offline 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
Previous Topic:Calculations of field values using other tables
Next Topic:@OneToOne and @PrimaryKeyJoinColumn do not fetch the object on H2/HSQL database
Goto Forum:
  


Current Time: Mon Jul 28 06:22:44 EDT 2014

Powered by FUDForum. Page generated in 0.02156 seconds