From e00befbc8799b8caf9e1ba4e0f7398b5f9c0e23b Mon Sep 17 00:00:00 2001 From: Konstantin Krivopustov Date: Mon, 8 Dec 2008 12:18:25 +0000 Subject: [PATCH] App.getInstance() added --- db/init/sql/create-db.sql | 4 ++-- modules/web-war/build.xml | 2 +- modules/web/build.xml | 2 +- modules/web/src/com/haulmont/cuba/web/App.java | 15 ++++++++++++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/db/init/sql/create-db.sql b/db/init/sql/create-db.sql index e8ca15bbf7..eb96483f91 100644 --- a/db/init/sql/create-db.sql +++ b/db/init/sql/create-db.sql @@ -101,8 +101,8 @@ values ('60885987-1b61-4247-94c7-dff348347f93', current_timestamp, 0, 'admin', ' insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, USER_ID) values ('bf83541f-f610-46f4-a268-dff348347f93', current_timestamp, 0, 'Default', '60885987-1b61-4247-94c7-dff348347f93'); -/*insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, USER_ID) -values ('cc1e0bc4-1062-4218-a09f-dff348347f93', current_timestamp, 0, 'Test', '60885987-1b61-4247-94c7-dff348347f93');*/ +insert into SEC_PROFILE (ID, CREATE_TS, VERSION, NAME, USER_ID) +values ('cc1e0bc4-1062-4218-a09f-dff348347f93', current_timestamp, 0, 'Test', '60885987-1b61-4247-94c7-dff348347f93'); insert into SEC_ROLE (ID, CREATE_TS, VERSION, NAME) values ('0c018061-b26f-4de2-a5be-dff348347f93', current_timestamp, 0, 'Administrators'); diff --git a/modules/web-war/build.xml b/modules/web-war/build.xml index 882b140d5a..7bab56208f 100644 --- a/modules/web-war/build.xml +++ b/modules/web-war/build.xml @@ -1,6 +1,6 @@ + name="cuba-web-war" default="build-module" basedir="."> diff --git a/modules/web/build.xml b/modules/web/build.xml index 5ee91d6f54..23aa47c551 100644 --- a/modules/web/build.xml +++ b/modules/web/build.xml @@ -1,6 +1,6 @@ + name="cuba-web" default="build-module" basedir="."> diff --git a/modules/web/src/com/haulmont/cuba/web/App.java b/modules/web/src/com/haulmont/cuba/web/App.java index 5b90fedd4e..033d49cfd1 100644 --- a/modules/web/src/com/haulmont/cuba/web/App.java +++ b/modules/web/src/com/haulmont/cuba/web/App.java @@ -26,6 +26,8 @@ public class App extends Application private Connection connection; + private static ThreadLocal currentApp = new ThreadLocal(); + static { SecurityAssociation.setServer(); } @@ -44,7 +46,11 @@ public class App extends Application appContext.addTransactionListener(new RequestListener()); } - protected AppWindow getAppWindow() { + public static App getInstance() { + return currentApp.get(); + } + + public AppWindow getAppWindow() { return new AppWindow(this); } @@ -59,6 +65,9 @@ public class App extends Application HttpServletRequest request = (HttpServletRequest) transactionData; log.trace("requestStart: " + request + " from " + request.getRemoteAddr()); } + if (application == App.this) { + currentApp.set((App) application); + } UserSession userSession = connection.getSession(); if (userSession != null) { SecurityAssociation.setPrincipal(new SimplePrincipal(userSession.getLogin())); @@ -67,6 +76,10 @@ public class App extends Application } public void transactionEnd(Application application, Object transactionData) { + if (application == App.this) { + currentApp.set(null); + currentApp.remove(); + } if (log.isTraceEnabled()) { log.trace("requestEnd: " + transactionData); }