[kune-commits] r1746 - in trunk/src: main/java/cc/kune/core/server main/java/cc/kune/core/server/content main/java/cc/kune/core/server/manager/impl main/java/cc/kune/core/server/persist main/java/cc/kune/core/server/xmpp main/java/cc/kune/gspace/client/options/general test/java/cc/kune/core/server test/java/cc/kune/core/server/integration test/java/com/google/inject/persist/jpa

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Wed Mar 7 13:19:26 CET 2012


Author: vjrj_
Date: 2012-03-07 13:19:26 +0100 (Wed, 07 Mar 2012)
New Revision: 1746

Added:
   trunk/src/main/java/cc/kune/core/server/persist/
   trunk/src/main/java/cc/kune/core/server/persist/CustomPersistFilter.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceKune.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceKuneSessionProvider.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfire.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfirePersistModule.java
   trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfireSessionProvider.java
   trunk/src/main/java/cc/kune/core/server/persist/GenericPersistenceInitializer.java
   trunk/src/main/java/cc/kune/core/server/persist/KunePersistenceService.java
   trunk/src/main/java/cc/kune/core/server/persist/KuneTransactional.java
   trunk/src/test/java/cc/kune/core/server/persist/
Removed:
   trunk/src/main/java/cc/kune/core/server/CustomPersistFilter.java
   trunk/src/main/java/cc/kune/core/server/DataSourceKune.java
   trunk/src/main/java/cc/kune/core/server/DataSourceKunePersistModule.java
   trunk/src/main/java/cc/kune/core/server/DataSourceKuneSessionProvider.java
   trunk/src/main/java/cc/kune/core/server/DataSourceOpenfire.java
   trunk/src/main/java/cc/kune/core/server/DataSourceOpenfirePersistModule.java
   trunk/src/main/java/cc/kune/core/server/DataSourceOpenfireSessionProvider.java
   trunk/src/main/java/cc/kune/core/server/GenericPersistenceInitializer.java
   trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java
   trunk/src/main/java/cc/kune/core/server/KuneTransactional.java
Modified:
   trunk/src/main/java/cc/kune/core/server/KuneContainerListener.java
   trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
   trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
   trunk/src/main/java/cc/kune/core/server/content/ContainerManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/content/ContentManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/ExtMediaDescripManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/GroupManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/I18nCountryManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/I18nLanguageManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/I18nTranslationManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/LicenseManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/RateManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/SocialNetworkManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/TagManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/TagUserContentManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/ToolConfigurationManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/xmpp/OpenfireXmppRosterProvider.java
   trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java
   trunk/src/test/java/cc/kune/core/server/PersistenceTest.java
   trunk/src/test/java/cc/kune/core/server/TestHelper.java
   trunk/src/test/java/cc/kune/core/server/integration/IntegrationTestHelper.java
   trunk/src/test/java/com/google/inject/persist/jpa/KuneJpaLocalTxnInterceptor.java
Log:
NEW - # 201: Add Openfire to the persist system so we can connect and get xmpp users info 
http://kune.ourproject.org/issues/ticket/201

Deleted: trunk/src/main/java/cc/kune/core/server/CustomPersistFilter.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/CustomPersistFilter.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/CustomPersistFilter.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,111 +0,0 @@
-/**
- * Copyright (C) 2010 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package cc.kune.core.server;
-
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.google.inject.persist.PersistService;
-import com.google.inject.persist.UnitOfWork;
-
-/**
- * Apply this filter to enable the HTTP Request unit of work and to have
- * guice-persist manage the lifecycle of active units of work. The filter
- * automatically starts and stops the relevant {@link PersistService} upon
- * {@link javax.servlet.Filter#init(javax.servlet.FilterConfig)} and
- * {@link javax.servlet.Filter#destroy()} respectively.
- * 
- * <p>
- * To be able to use the open session-in-view pattern (i.e. work per request),
- * register this filter <b>once</b> in your Guice {@code ServletModule}. It is
- * important that you register this filter before any other filter.
- * 
- * For multiple providers, you should register this filter once per provider,
- * inside a private module for each persist module installed (this must be the
- * same private module where the specific persist module is itself installed).
- * 
- * <p>
- * Example configuration:
- * 
- * <pre>
- * {
- *   &#064;code
- *   public class MyModule extends ServletModule {
- *     public void configureServlets() {
- *       filter(&quot;/*&quot;).through(PersistFilter.class);
- * 
- *       serve(&quot;/index.html&quot;).with(MyHtmlServlet.class);
- *       // Etc.
- *     }
- *   }
- * }
- * </pre>
- * <p>
- * This filter is thread safe and allows you to create injectors concurrently
- * and deploy multiple guice-persist modules within the same injector, or even
- * multiple injectors with persist modules withing the same JVM or web app.
- * <p>
- * This filter requires the Guice Servlet extension.
- * 
- * @author Dhanji R. Prasanna (dhanji at gmail.com)
- * 
- *         (Custom PersistFilter.class modified for kune needs without
- *         persistence start/stop)
- */
-
- at Singleton
-public class CustomPersistFilter implements Filter {
-  private final PersistService persistService;
-  private final UnitOfWork unitOfWork;
-
-  @Inject
-  public CustomPersistFilter(final UnitOfWork unitOfWork, final PersistService persistService) {
-    this.unitOfWork = unitOfWork;
-    this.persistService = persistService;
-  }
-
-  @Override
-  public void destroy() {
-    // Commented in kune
-    // persistService.stop();
-  }
-
-  @Override
-  public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
-      final FilterChain filterChain) throws IOException, ServletException {
-
-    unitOfWork.begin();
-    try {
-      filterChain.doFilter(servletRequest, servletResponse);
-    } finally {
-      unitOfWork.end();
-    }
-  }
-
-  @Override
-  public void init(final FilterConfig filterConfig) throws ServletException {
-    // Commented in kune
-    // persistService.start();
-  }
-}
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceKune.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceKune.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceKune.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,17 +0,0 @@
-package cc.kune.core.server;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import com.google.inject.BindingAnnotation;
-
- at Retention(RetentionPolicy.RUNTIME)
- at Target({ FIELD, PARAMETER, METHOD })
- at BindingAnnotation
-public @interface DataSourceKune {
-}
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceKunePersistModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceKunePersistModule.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceKunePersistModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,138 +0,0 @@
-package cc.kune.core.server;
-
-import java.util.Properties;
-
-import javax.persistence.EntityManager;
-
-import org.apache.commons.configuration.SystemConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hibernate.Session;
-
-import cc.kune.core.server.properties.KuneProperties;
-import cc.kune.core.server.properties.KunePropertiesDefault;
-import cc.kune.domain.finders.ContainerFinder;
-import cc.kune.domain.finders.ContentFinder;
-import cc.kune.domain.finders.ExtMediaDescripFinder;
-import cc.kune.domain.finders.GroupFinder;
-import cc.kune.domain.finders.I18nCountryFinder;
-import cc.kune.domain.finders.I18nLanguageFinder;
-import cc.kune.domain.finders.I18nTranslationFinder;
-import cc.kune.domain.finders.LicenseFinder;
-import cc.kune.domain.finders.RateFinder;
-import cc.kune.domain.finders.TagFinder;
-import cc.kune.domain.finders.TagUserContentFinder;
-import cc.kune.domain.finders.UserFinder;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Key;
-import com.google.inject.Provider;
-import com.google.inject.persist.jpa.JpaPersistModule;
-
-public class DataSourceKunePersistModule extends AbstractModule {
-  public static final Log LOG = LogFactory.getLog(DataSourceKunePersistModule.class);
-  public static final Key<CustomPersistFilter> MY_DATA_SOURCE_ONE_FILTER_KEY = Key.get(
-      CustomPersistFilter.class, DataSourceKune.class);
-  private String settedJpaUnit = null;
-  private String settedProperties = null;
-
-  public DataSourceKunePersistModule() {
-  }
-
-  /**
-   * Instantiates this module during tests
-   * 
-   * @param settedProperties
-   *          the setted properties
-   * @param settedJpaUnit
-   *          the setted jpa unit
-   */
-  public DataSourceKunePersistModule(final String settedProperties, final String settedJpaUnit) {
-    this.settedProperties = settedProperties;
-    this.settedJpaUnit = settedJpaUnit;
-  }
-
-  @Override
-  public void configure() {
-    final SystemConfiguration sysConf = new SystemConfiguration();
-    final String kuneConfig = settedProperties != null ? settedProperties
-        : sysConf.getString("kune.server.config");
-
-    final KunePropertiesDefault kuneProperties = new KunePropertiesDefault(kuneConfig);
-    bind(KuneProperties.class).toInstance(kuneProperties);
-
-    // precedence method param > properties
-    final String configuredJpaUnit = kuneProperties.get(KuneProperties.SITE_DB_PERSISTENCE_NAME);
-    final String jpaUnit = settedJpaUnit != null ? settedJpaUnit
-        : configuredJpaUnit != null ? configuredJpaUnit : "development";
-    LOG.info(String.format("Using persistence unit '%s' and properties '%s'", jpaUnit, kuneConfig));
-
-    final JpaPersistModule jpm = new JpaPersistModule(jpaUnit);
-
-    if (!jpaUnit.equals("test")) {
-      // In tests (and development) we don't override this db info)
-      final Properties dbProperties = new Properties();
-      dbProperties.setProperty("hibernate.connection.url",
-          kuneProperties.get(KuneProperties.SITE_DB_URL));
-      dbProperties.setProperty("hibernate.connection.username",
-          kuneProperties.get(KuneProperties.SITE_DB_USER));
-      dbProperties.setProperty("hibernate.connection.password",
-          kuneProperties.get(KuneProperties.SITE_DB_PASSWORD));
-      jpm.properties(dbProperties);
-    }
-
-    jpm.addFinder(ContainerFinder.class);
-    jpm.addFinder(ContentFinder.class);
-    jpm.addFinder(ExtMediaDescripFinder.class);
-    jpm.addFinder(GroupFinder.class);
-    jpm.addFinder(I18nCountryFinder.class);
-    jpm.addFinder(I18nLanguageFinder.class);
-    jpm.addFinder(I18nTranslationFinder.class);
-    jpm.addFinder(LicenseFinder.class);
-    jpm.addFinder(RateFinder.class);
-    jpm.addFinder(TagFinder.class);
-    jpm.addFinder(TagUserContentFinder.class);
-    jpm.addFinder(UserFinder.class);
-    install(jpm);
-
-    bind(Session.class).annotatedWith(DataSourceKune.class).toProvider(
-        DataSourceKuneSessionProvider.class);
-
-    // bind(UnitOfWork.class).annotatedWith(DataSourceKune.class).toProvider(
-    // DataSourceKuneUnitOfWorkProvider.class);
-    // expose(UnitOfWork.class).annotatedWith(DataSourceKune.class);
-
-    // final KuneJpaLocalTxnInterceptor transactionInterceptor = new
-    // KuneJpaLocalTxnInterceptor();
-    // requestInjection(transactionInterceptor);
-    //
-    // bindInterceptor(annotatedWith(KuneTransactional.class), any(),
-    // transactionInterceptor);
-    // bindInterceptor(any(), annotatedWith(KuneTransactional.class),
-    // transactionInterceptor);
-
-    final Provider<EntityManager> entityManagerProvider = binder().getProvider(EntityManager.class);
-    bind(EntityManager.class).annotatedWith(DataSourceKune.class).toProvider(entityManagerProvider);
-
-    bind(MY_DATA_SOURCE_ONE_FILTER_KEY).to(CustomPersistFilter.class);
-
-    // expose(EntityManager.class).annotatedWith(DataSourceKune.class);
-    // expose(Session.class).annotatedWith(DataSourceKune.class);
-    // expose(KuneProperties.class);
-    // expose(ContainerFinder.class);
-    // expose(ContentFinder.class);
-    // expose(ExtMediaDescripFinder.class);
-    // expose(GroupFinder.class);
-    // expose(I18nCountryFinder.class);
-    // expose(I18nLanguageFinder.class);
-    // expose(I18nTranslationFinder.class);
-    // expose(LicenseFinder.class);
-    // expose(RateFinder.class);
-    // expose(TagFinder.class);
-    // expose(TagUserContentFinder.class);
-    // expose(UserFinder.class);
-    // expose(MY_DATA_SOURCE_ONE_FILTER_KEY);
-
-    bind(GenericPersistenceInitializer.class).asEagerSingleton();
-  }
-}
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceKuneSessionProvider.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceKuneSessionProvider.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceKuneSessionProvider.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,26 +0,0 @@
-package cc.kune.core.server;
-
-import javax.persistence.EntityManager;
-
-import org.hibernate.Session;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-
-public class DataSourceKuneSessionProvider implements Provider<Session> {
-  /** The entity manger to retrieve the session from. */
-  @Inject
-  @DataSourceKune
-  private Provider<EntityManager> entityManagerProvider;
-
-  /**
-   * @return the Hibernate session, being the delegate of the entity manager
-   *         provided by the injected entity manager provider.
-   */
-  @Override
-  public Session get() {
-    final Session session = (Session) entityManagerProvider.get().getDelegate();
-    // configure session i.e. flush mode or filtering
-    return session;
-  }
-};
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceOpenfire.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceOpenfire.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceOpenfire.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,17 +0,0 @@
-package cc.kune.core.server;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import com.google.inject.BindingAnnotation;
-
- at Retention(RetentionPolicy.RUNTIME)
- at Target({ FIELD, PARAMETER, METHOD })
- at BindingAnnotation
-public @interface DataSourceOpenfire {
-}
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceOpenfirePersistModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceOpenfirePersistModule.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceOpenfirePersistModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,60 +0,0 @@
-package cc.kune.core.server;
-
-import java.util.Properties;
-
-import javax.persistence.EntityManager;
-
-import org.hibernate.Session;
-
-import cc.kune.core.server.xmpp.OpenfireXmppRosterFinder;
-import cc.kune.core.server.xmpp.OpenfireXmppRosterProvider;
-import cc.kune.core.server.xmpp.XmppRosterProvider;
-
-import com.google.inject.Key;
-import com.google.inject.PrivateModule;
-import com.google.inject.Provider;
-import com.google.inject.Singleton;
-import com.google.inject.persist.jpa.JpaPersistModule;
-
-public class DataSourceOpenfirePersistModule extends PrivateModule {
-  public static final Key<CustomPersistFilter> MY_DATA_SOURCE_TWO_FILTER_KEY = Key.get(
-      CustomPersistFilter.class, DataSourceOpenfire.class);
-
-  @Override
-  public void configure() {
-    final JpaPersistModule jpm = new JpaPersistModule("openfire");
-    // jpm.properties(new Properties());
-
-    final Properties dbProperties = new Properties();
-    dbProperties.setProperty(
-        "hibernate.connection.url",
-        "jdbc:mysql://localhost/openfire4?createDatabaseIfNotExist=false&amp;useUnicode=true&amp;characterEncoding=UTF-8");
-    // kuneProperties.get(KuneProperties.SITE_DB_URL));
-    dbProperties.setProperty("hibernate.connection.username", "openfire");
-    // kuneProperties.get(KuneProperties.SITE_DB_USER));
-    dbProperties.setProperty("hibernate.connection.password", "easyeasy");
-    dbProperties.setProperty("exclude-unlisted-classes", "true");
-
-    // kuneProperties.get(KuneProperties.SITE_DB_PASSWORD));
-
-    jpm.properties(dbProperties);
-    install(jpm.addFinder(OpenfireXmppRosterFinder.class));
-    expose(OpenfireXmppRosterFinder.class);
-
-    bind(XmppRosterProvider.class).to(OpenfireXmppRosterProvider.class).in(Singleton.class);
-    expose(XmppRosterProvider.class);
-
-    bind(Session.class).annotatedWith(DataSourceOpenfire.class).toProvider(
-        DataSourceOpenfireSessionProvider.class);
-    expose(Session.class).annotatedWith(DataSourceOpenfire.class);
-
-    final Provider<EntityManager> entityManagerProvider = binder().getProvider(EntityManager.class);
-    bind(EntityManager.class).annotatedWith(DataSourceOpenfire.class).toProvider(entityManagerProvider);
-    expose(EntityManager.class).annotatedWith(DataSourceOpenfire.class);
-
-    bind(MY_DATA_SOURCE_TWO_FILTER_KEY).to(CustomPersistFilter.class);
-    expose(MY_DATA_SOURCE_TWO_FILTER_KEY);
-
-    // bind(KunePersistenceInitializer.class).asEagerSingleton();
-  }
-}
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/DataSourceOpenfireSessionProvider.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/DataSourceOpenfireSessionProvider.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/DataSourceOpenfireSessionProvider.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,26 +0,0 @@
-package cc.kune.core.server;
-
-import javax.persistence.EntityManager;
-
-import org.hibernate.Session;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-
-public class DataSourceOpenfireSessionProvider implements Provider<Session> {
-  /** The entity manger to retrieve the session from. */
-  @Inject
-  @DataSourceOpenfire
-  private Provider<EntityManager> entityManagerProvider;
-
-  /**
-   * @return the Hibernate session, being the delegate of the entity manager
-   *         provided by the injected entity manager provider.
-   */
-  @Override
-  public Session get() {
-    final Session session = (Session) entityManagerProvider.get().getDelegate();
-    // configure session i.e. flush mode or filtering
-    return session;
-  }
-};
\ No newline at end of file

Deleted: trunk/src/main/java/cc/kune/core/server/GenericPersistenceInitializer.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/GenericPersistenceInitializer.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/GenericPersistenceInitializer.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,12 +0,0 @@
-package cc.kune.core.server;
-
-import com.google.inject.Inject;
-import com.google.inject.persist.PersistService;
-
-public class GenericPersistenceInitializer {
-  @Inject
-  GenericPersistenceInitializer(final PersistService service) {
-    service.start();
-    // At this point JPA is started and ready.
-  }
-}
\ No newline at end of file

Modified: trunk/src/main/java/cc/kune/core/server/KuneContainerListener.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KuneContainerListener.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/KuneContainerListener.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -31,6 +31,7 @@
 
 import org.apache.log4j.PropertyConfigurator;
 
+import cc.kune.core.server.persist.KunePersistenceService;
 import cc.kune.core.server.rack.ContainerListener;
 
 import com.google.inject.Inject;

Deleted: trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,41 +0,0 @@
-/*
- *
- * Copyright (C) 2007-2011 The kune development team (see CREDITS for details)
- * This file is part of kune.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package cc.kune.core.server;
-
-import cc.kune.core.server.error.ServerException;
-import cc.kune.core.server.init.DatabaseInitializer;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-
- at Singleton
-public class KunePersistenceService {
-  @Inject
-  DatabaseInitializer databaseInitializer;
-
-  public void start() {
-    try {
-      databaseInitializer.initConditional();
-    } catch (final Exception e) {
-      throw new ServerException("Error starting persistence service", e);
-    }
-  }
-
-}

Modified: trunk/src/main/java/cc/kune/core/server/KuneRackModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/KuneRackModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -40,6 +40,7 @@
 import cc.kune.core.server.manager.file.FileUploadManager;
 import cc.kune.core.server.manager.file.UserLogoDownloadManager;
 import cc.kune.core.server.manager.impl.GroupServerUtils;
+import cc.kune.core.server.persist.DataSourceKunePersistModule;
 import cc.kune.core.server.rack.RackBuilder;
 import cc.kune.core.server.rack.RackModule;
 import cc.kune.core.server.rack.filters.ForwardFilter;

Deleted: trunk/src/main/java/cc/kune/core/server/KuneTransactional.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KuneTransactional.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/KuneTransactional.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -1,29 +0,0 @@
-package cc.kune.core.server;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
- at Target({ ElementType.METHOD, ElementType.TYPE })
- at Retention(RetentionPolicy.RUNTIME)
- at Inherited
-public @interface KuneTransactional {
-
-  /**
-   * A list of exceptions to <b>not<b> rollback on. A caveat to the rollbackOn
-   * clause. The disjunction of rollbackOn and ignore represents the list of
-   * exceptions that will trigger a rollback. The complement of rollbackOn and
-   * the universal set plus any exceptions in the ignore set represents the list
-   * of exceptions that will trigger a commit. Note that ignore exceptions take
-   * precedence over rollbackOn, but with subtype granularity.
-   */
-  Class<? extends Exception>[] ignore() default {};
-
-  /**
-   * A list of exceptions to rollback on, if thrown by the transactional method.
-   * These exceptions are propagated correctly after a rollback.
-   */
-  Class<? extends Exception>[] rollbackOn() default RuntimeException.class;
-}
\ No newline at end of file

Modified: trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -91,6 +91,7 @@
 import cc.kune.core.server.notifier.NotificationSenderDefault;
 import cc.kune.core.server.notifier.PendingNotificationSender;
 import cc.kune.core.server.notifier.UsersOnline;
+import cc.kune.core.server.persist.KunePersistenceService;
 import cc.kune.core.server.rpc.ContentRPC;
 import cc.kune.core.server.rpc.GroupRPC;
 import cc.kune.core.server.rpc.I18nRPC;

Modified: trunk/src/main/java/cc/kune/core/server/content/ContainerManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/content/ContainerManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/content/ContainerManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -30,11 +30,11 @@
 import cc.kune.core.client.errors.DefaultException;
 import cc.kune.core.client.errors.MoveOnSameContainerException;
 import cc.kune.core.client.errors.NameInUseException;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.SearchResult;
 import cc.kune.core.server.manager.file.FileUtils;
 import cc.kune.core.server.manager.impl.DefaultManager;
 import cc.kune.core.server.manager.impl.ServerManagerException;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.server.utils.FilenameUtils;
 import cc.kune.domain.AccessLists;
 import cc.kune.domain.Container;

Modified: trunk/src/main/java/cc/kune/core/server/content/ContentManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/content/ContentManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/content/ContentManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -46,7 +46,6 @@
 import cc.kune.core.client.errors.MoveOnSameContainerException;
 import cc.kune.core.client.errors.NameInUseException;
 import cc.kune.core.client.errors.UserNotFoundException;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.access.FinderService;
 import cc.kune.core.server.manager.SearchResult;
 import cc.kune.core.server.manager.TagUserContentManager;
@@ -54,6 +53,7 @@
 import cc.kune.core.server.manager.impl.DefaultManager;
 import cc.kune.core.server.manager.impl.GroupServerUtils;
 import cc.kune.core.server.manager.impl.ServerManagerException;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.server.tool.ServerTool;
 import cc.kune.core.server.tool.ServerToolRegistry;
 import cc.kune.core.server.utils.FilenameUtils;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/ExtMediaDescripManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/ExtMediaDescripManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/ExtMediaDescripManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -23,8 +23,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.ExtMediaDescripManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.ExtMediaDescrip;
 import cc.kune.domain.finders.ExtMediaDescripFinder;
 

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/GroupManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/GroupManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/GroupManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -39,12 +39,12 @@
 import cc.kune.core.client.errors.GroupLongNameInUseException;
 import cc.kune.core.client.errors.GroupShortNameInUseException;
 import cc.kune.core.client.errors.UserMustBeLoggedException;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.FileManager;
 import cc.kune.core.server.manager.GroupManager;
 import cc.kune.core.server.manager.LicenseManager;
 import cc.kune.core.server.manager.SearchResult;
 import cc.kune.core.server.manager.file.FileUtils;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.server.properties.KuneBasicProperties;
 import cc.kune.core.server.properties.KuneProperties;
 import cc.kune.core.server.tool.ServerTool;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/I18nCountryManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/I18nCountryManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/I18nCountryManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -23,8 +23,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.I18nCountryManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.I18nCountry;
 import cc.kune.domain.finders.I18nCountryFinder;
 

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/I18nLanguageManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/I18nLanguageManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/I18nLanguageManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -23,8 +23,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.I18nLanguageManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.I18nLanguage;
 import cc.kune.domain.finders.I18nLanguageFinder;
 

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/I18nTranslationManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/I18nTranslationManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/I18nTranslationManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -27,9 +27,9 @@
 
 import cc.kune.common.shared.utils.TextUtils;
 import cc.kune.core.client.errors.DefaultException;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.I18nLanguageManager;
 import cc.kune.core.server.manager.I18nTranslationManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.shared.dto.I18nTranslationDTO;
 import cc.kune.core.shared.dto.SearchResultDTO;
 import cc.kune.domain.I18nLanguage;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/LicenseManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/LicenseManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/LicenseManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -23,8 +23,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.LicenseManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.server.properties.KuneBasicProperties;
 import cc.kune.domain.License;
 import cc.kune.domain.finders.LicenseFinder;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/RateManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/RateManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/RateManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -22,8 +22,8 @@
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.RateManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.Content;
 import cc.kune.domain.Rate;
 import cc.kune.domain.User;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/SocialNetworkManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/SocialNetworkManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/SocialNetworkManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -30,11 +30,11 @@
 import cc.kune.core.client.errors.InvalidSNOperationException;
 import cc.kune.core.client.errors.LastAdminInGroupException;
 import cc.kune.core.client.errors.UserMustBeLoggedException;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.access.AccessRightsService;
 import cc.kune.core.server.error.ServerException;
 import cc.kune.core.server.manager.SocialNetworkManager;
 import cc.kune.core.server.manager.UserManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.shared.domain.AdmissionType;
 import cc.kune.core.shared.domain.GroupListMode;
 import cc.kune.core.shared.domain.SocialNetworkVisibility;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/TagManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/TagManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/TagManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -21,8 +21,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.TagManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.Tag;
 import cc.kune.domain.finders.TagFinder;
 

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/TagUserContentManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/TagUserContentManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/TagUserContentManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -26,9 +26,9 @@
 import javax.persistence.NoResultException;
 
 import cc.kune.common.shared.utils.TextUtils;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.TagManager;
 import cc.kune.core.server.manager.TagUserContentManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.shared.domain.TagCloudResult;
 import cc.kune.core.shared.domain.TagCount;
 import cc.kune.domain.Content;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/ToolConfigurationManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/ToolConfigurationManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/ToolConfigurationManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -21,8 +21,8 @@
 
 import javax.persistence.EntityManager;
 
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.manager.ToolConfigurationManager;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.domain.ToolConfiguration;
 
 import com.google.inject.Inject;

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -58,7 +58,6 @@
 import cc.kune.core.client.errors.WrongCurrentPasswordException;
 import cc.kune.core.client.state.SiteTokens;
 import cc.kune.core.client.state.TokenUtils;
-import cc.kune.core.server.DataSourceKune;
 import cc.kune.core.server.i18n.I18nTranslationServiceMultiLang;
 import cc.kune.core.server.manager.GroupManager;
 import cc.kune.core.server.manager.I18nCountryManager;
@@ -66,6 +65,7 @@
 import cc.kune.core.server.manager.SearchResult;
 import cc.kune.core.server.manager.UserManager;
 import cc.kune.core.server.notifier.NotificationService;
+import cc.kune.core.server.persist.DataSourceKune;
 import cc.kune.core.server.properties.ChatProperties;
 import cc.kune.core.server.properties.KuneBasicProperties;
 import cc.kune.core.server.xmpp.ChatConnection;

Copied: trunk/src/main/java/cc/kune/core/server/persist/CustomPersistFilter.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/CustomPersistFilter.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/CustomPersistFilter.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/CustomPersistFilter.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,111 @@
+/**
+ * Copyright (C) 2010 Google, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cc.kune.core.server.persist;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.persist.PersistService;
+import com.google.inject.persist.UnitOfWork;
+
+/**
+ * Apply this filter to enable the HTTP Request unit of work and to have
+ * guice-persist manage the lifecycle of active units of work. The filter
+ * automatically starts and stops the relevant {@link PersistService} upon
+ * {@link javax.servlet.Filter#init(javax.servlet.FilterConfig)} and
+ * {@link javax.servlet.Filter#destroy()} respectively.
+ * 
+ * <p>
+ * To be able to use the open session-in-view pattern (i.e. work per request),
+ * register this filter <b>once</b> in your Guice {@code ServletModule}. It is
+ * important that you register this filter before any other filter.
+ * 
+ * For multiple providers, you should register this filter once per provider,
+ * inside a private module for each persist module installed (this must be the
+ * same private module where the specific persist module is itself installed).
+ * 
+ * <p>
+ * Example configuration:
+ * 
+ * <pre>
+ * {
+ *   &#064;code
+ *   public class MyModule extends ServletModule {
+ *     public void configureServlets() {
+ *       filter(&quot;/*&quot;).through(PersistFilter.class);
+ * 
+ *       serve(&quot;/index.html&quot;).with(MyHtmlServlet.class);
+ *       // Etc.
+ *     }
+ *   }
+ * }
+ * </pre>
+ * <p>
+ * This filter is thread safe and allows you to create injectors concurrently
+ * and deploy multiple guice-persist modules within the same injector, or even
+ * multiple injectors with persist modules withing the same JVM or web app.
+ * <p>
+ * This filter requires the Guice Servlet extension.
+ * 
+ * @author Dhanji R. Prasanna (dhanji at gmail.com)
+ * 
+ *         (Custom PersistFilter.class modified for kune needs without
+ *         persistence start/stop)
+ */
+
+ at Singleton
+public class CustomPersistFilter implements Filter {
+  private final PersistService persistService;
+  private final UnitOfWork unitOfWork;
+
+  @Inject
+  public CustomPersistFilter(final UnitOfWork unitOfWork, final PersistService persistService) {
+    this.unitOfWork = unitOfWork;
+    this.persistService = persistService;
+  }
+
+  @Override
+  public void destroy() {
+    // Commented in kune
+    // persistService.stop();
+  }
+
+  @Override
+  public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
+      final FilterChain filterChain) throws IOException, ServletException {
+
+    unitOfWork.begin();
+    try {
+      filterChain.doFilter(servletRequest, servletResponse);
+    } finally {
+      unitOfWork.end();
+    }
+  }
+
+  @Override
+  public void init(final FilterConfig filterConfig) throws ServletException {
+    // Commented in kune (because if not this is started twice)
+    // persistService.start();
+  }
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceKune.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/DataSourceKune.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceKune.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceKune.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,17 @@
+package cc.kune.core.server.persist;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ FIELD, PARAMETER, METHOD })
+ at BindingAnnotation
+public @interface DataSourceKune {
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java (from rev 1744, trunk/src/main/java/cc/kune/core/server/DataSourceKunePersistModule.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,144 @@
+package cc.kune.core.server.persist;
+
+import java.util.Properties;
+
+import javax.persistence.EntityManager;
+
+import org.apache.commons.configuration.SystemConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hibernate.Session;
+
+import cc.kune.core.server.properties.KuneProperties;
+import cc.kune.core.server.properties.KunePropertiesDefault;
+import cc.kune.domain.finders.ContainerFinder;
+import cc.kune.domain.finders.ContentFinder;
+import cc.kune.domain.finders.ExtMediaDescripFinder;
+import cc.kune.domain.finders.GroupFinder;
+import cc.kune.domain.finders.I18nCountryFinder;
+import cc.kune.domain.finders.I18nLanguageFinder;
+import cc.kune.domain.finders.I18nTranslationFinder;
+import cc.kune.domain.finders.LicenseFinder;
+import cc.kune.domain.finders.RateFinder;
+import cc.kune.domain.finders.TagFinder;
+import cc.kune.domain.finders.TagUserContentFinder;
+import cc.kune.domain.finders.UserFinder;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Key;
+import com.google.inject.Provider;
+import com.google.inject.persist.jpa.JpaPersistModule;
+
+public class DataSourceKunePersistModule extends AbstractModule {
+  // FIXME Trying to make this PrivateModule so we can have two Persist sources
+  // http://code.google.com/p/google-guice/wiki/GuicePersistMultiModules
+
+  public static final Log LOG = LogFactory.getLog(DataSourceKunePersistModule.class);
+  public static final Key<CustomPersistFilter> MY_DATA_SOURCE_ONE_FILTER_KEY = Key.get(
+      CustomPersistFilter.class, DataSourceKune.class);
+  private String settedJpaUnit = null;
+  private String settedProperties = null;
+
+  /**
+   * Instantiates this module (main constructor)
+   */
+  public DataSourceKunePersistModule() {
+  }
+
+  /**
+   * Instantiates this module only during tests
+   * 
+   * @param settedProperties
+   *          the setted properties
+   * @param settedJpaUnit
+   *          the setted jpa unit
+   */
+  public DataSourceKunePersistModule(final String settedProperties, final String settedJpaUnit) {
+    this.settedProperties = settedProperties;
+    this.settedJpaUnit = settedJpaUnit;
+  }
+
+  @Override
+  public void configure() {
+    final SystemConfiguration sysConf = new SystemConfiguration();
+    final String kuneConfig = settedProperties != null ? settedProperties
+        : sysConf.getString("kune.server.config");
+
+    final KunePropertiesDefault kuneProperties = new KunePropertiesDefault(kuneConfig);
+    bind(KuneProperties.class).toInstance(kuneProperties);
+
+    // precedence method param > properties
+    final String configuredJpaUnit = kuneProperties.get(KuneProperties.SITE_DB_PERSISTENCE_NAME);
+    final String jpaUnit = settedJpaUnit != null ? settedJpaUnit
+        : configuredJpaUnit != null ? configuredJpaUnit : "development";
+    LOG.info(String.format("Using persistence unit '%s' and properties '%s'", jpaUnit, kuneConfig));
+
+    final JpaPersistModule jpm = new JpaPersistModule(jpaUnit);
+
+    if (!jpaUnit.equals("test")) {
+      // In tests (and development) we don't override this db info)
+      final Properties dbProperties = new Properties();
+      dbProperties.setProperty("hibernate.connection.url",
+          kuneProperties.get(KuneProperties.SITE_DB_URL));
+      dbProperties.setProperty("hibernate.connection.username",
+          kuneProperties.get(KuneProperties.SITE_DB_USER));
+      dbProperties.setProperty("hibernate.connection.password",
+          kuneProperties.get(KuneProperties.SITE_DB_PASSWORD));
+      jpm.properties(dbProperties);
+    }
+
+    jpm.addFinder(ContainerFinder.class);
+    jpm.addFinder(ContentFinder.class);
+    jpm.addFinder(ExtMediaDescripFinder.class);
+    jpm.addFinder(GroupFinder.class);
+    jpm.addFinder(I18nCountryFinder.class);
+    jpm.addFinder(I18nLanguageFinder.class);
+    jpm.addFinder(I18nTranslationFinder.class);
+    jpm.addFinder(LicenseFinder.class);
+    jpm.addFinder(RateFinder.class);
+    jpm.addFinder(TagFinder.class);
+    jpm.addFinder(TagUserContentFinder.class);
+    jpm.addFinder(UserFinder.class);
+    install(jpm);
+
+    bind(Session.class).annotatedWith(DataSourceKune.class).toProvider(
+        DataSourceKuneSessionProvider.class);
+
+    // FIXME: Trying to use a custom JpaLocalTxnInterceptor because when this
+    // module is private the objects are not persisted with the guice-persist
+    // @Transactional
+
+    // final KuneJpaLocalTxnInterceptor transactionInterceptor = new
+    // KuneJpaLocalTxnInterceptor();
+    // requestInjection(transactionInterceptor);
+    //
+    // bindInterceptor(annotatedWith(KuneTransactional.class), any(),
+    // transactionInterceptor);
+    // bindInterceptor(any(), annotatedWith(KuneTransactional.class),
+    // transactionInterceptor);
+
+    final Provider<EntityManager> entityManagerProvider = binder().getProvider(EntityManager.class);
+    bind(EntityManager.class).annotatedWith(DataSourceKune.class).toProvider(entityManagerProvider);
+
+    bind(MY_DATA_SOURCE_ONE_FILTER_KEY).to(CustomPersistFilter.class);
+
+    // expose(EntityManager.class).annotatedWith(DataSourceKune.class);
+    // expose(Session.class).annotatedWith(DataSourceKune.class);
+    // expose(KuneProperties.class);
+    // expose(ContainerFinder.class);
+    // expose(ContentFinder.class);
+    // expose(ExtMediaDescripFinder.class);
+    // expose(GroupFinder.class);
+    // expose(I18nCountryFinder.class);
+    // expose(I18nLanguageFinder.class);
+    // expose(I18nTranslationFinder.class);
+    // expose(LicenseFinder.class);
+    // expose(RateFinder.class);
+    // expose(TagFinder.class);
+    // expose(TagUserContentFinder.class);
+    // expose(UserFinder.class);
+    // expose(MY_DATA_SOURCE_ONE_FILTER_KEY);
+
+    bind(GenericPersistenceInitializer.class).asEagerSingleton();
+  }
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceKuneSessionProvider.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/DataSourceKuneSessionProvider.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceKuneSessionProvider.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceKuneSessionProvider.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,26 @@
+package cc.kune.core.server.persist;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.Session;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+public class DataSourceKuneSessionProvider implements Provider<Session> {
+  /** The entity manger to retrieve the session from. */
+  @Inject
+  @DataSourceKune
+  private Provider<EntityManager> entityManagerProvider;
+
+  /**
+   * @return the Hibernate session, being the delegate of the entity manager
+   *         provided by the injected entity manager provider.
+   */
+  @Override
+  public Session get() {
+    final Session session = (Session) entityManagerProvider.get().getDelegate();
+    // configure session i.e. flush mode or filtering
+    return session;
+  }
+};
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfire.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/DataSourceOpenfire.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfire.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfire.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,17 @@
+package cc.kune.core.server.persist;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ FIELD, PARAMETER, METHOD })
+ at BindingAnnotation
+public @interface DataSourceOpenfire {
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfirePersistModule.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/DataSourceOpenfirePersistModule.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfirePersistModule.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfirePersistModule.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,60 @@
+package cc.kune.core.server.persist;
+
+import java.util.Properties;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.Session;
+
+import cc.kune.core.server.xmpp.OpenfireXmppRosterFinder;
+import cc.kune.core.server.xmpp.OpenfireXmppRosterProvider;
+import cc.kune.core.server.xmpp.XmppRosterProvider;
+
+import com.google.inject.Key;
+import com.google.inject.PrivateModule;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.jpa.JpaPersistModule;
+
+public class DataSourceOpenfirePersistModule extends PrivateModule {
+  public static final Key<CustomPersistFilter> MY_DATA_SOURCE_TWO_FILTER_KEY = Key.get(
+      CustomPersistFilter.class, DataSourceOpenfire.class);
+
+  @Override
+  public void configure() {
+    final JpaPersistModule jpm = new JpaPersistModule("openfire");
+    // jpm.properties(new Properties());
+
+    final Properties dbProperties = new Properties();
+    dbProperties.setProperty(
+        "hibernate.connection.url",
+        "jdbc:mysql://localhost/openfire4?createDatabaseIfNotExist=false&amp;useUnicode=true&amp;characterEncoding=UTF-8");
+    // kuneProperties.get(KuneProperties.SITE_DB_URL));
+    dbProperties.setProperty("hibernate.connection.username", "openfire");
+    // kuneProperties.get(KuneProperties.SITE_DB_USER));
+    dbProperties.setProperty("hibernate.connection.password", "easyeasy");
+    dbProperties.setProperty("exclude-unlisted-classes", "true");
+
+    // kuneProperties.get(KuneProperties.SITE_DB_PASSWORD));
+
+    jpm.properties(dbProperties);
+    install(jpm.addFinder(OpenfireXmppRosterFinder.class));
+    expose(OpenfireXmppRosterFinder.class);
+
+    bind(XmppRosterProvider.class).to(OpenfireXmppRosterProvider.class).in(Singleton.class);
+    expose(XmppRosterProvider.class);
+
+    bind(Session.class).annotatedWith(DataSourceOpenfire.class).toProvider(
+        DataSourceOpenfireSessionProvider.class);
+    expose(Session.class).annotatedWith(DataSourceOpenfire.class);
+
+    final Provider<EntityManager> entityManagerProvider = binder().getProvider(EntityManager.class);
+    bind(EntityManager.class).annotatedWith(DataSourceOpenfire.class).toProvider(entityManagerProvider);
+    expose(EntityManager.class).annotatedWith(DataSourceOpenfire.class);
+
+    bind(MY_DATA_SOURCE_TWO_FILTER_KEY).to(CustomPersistFilter.class);
+    expose(MY_DATA_SOURCE_TWO_FILTER_KEY);
+
+    // bind(KunePersistenceInitializer.class).asEagerSingleton();
+  }
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfireSessionProvider.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/DataSourceOpenfireSessionProvider.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfireSessionProvider.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/DataSourceOpenfireSessionProvider.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,26 @@
+package cc.kune.core.server.persist;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.Session;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+public class DataSourceOpenfireSessionProvider implements Provider<Session> {
+  /** The entity manger to retrieve the session from. */
+  @Inject
+  @DataSourceOpenfire
+  private Provider<EntityManager> entityManagerProvider;
+
+  /**
+   * @return the Hibernate session, being the delegate of the entity manager
+   *         provided by the injected entity manager provider.
+   */
+  @Override
+  public Session get() {
+    final Session session = (Session) entityManagerProvider.get().getDelegate();
+    // configure session i.e. flush mode or filtering
+    return session;
+  }
+};
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/GenericPersistenceInitializer.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/GenericPersistenceInitializer.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/GenericPersistenceInitializer.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/GenericPersistenceInitializer.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,12 @@
+package cc.kune.core.server.persist;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.PersistService;
+
+public class GenericPersistenceInitializer {
+  @Inject
+  GenericPersistenceInitializer(final PersistService service) {
+    service.start();
+    // At this point JPA is started and ready.
+  }
+}
\ No newline at end of file

Copied: trunk/src/main/java/cc/kune/core/server/persist/KunePersistenceService.java (from rev 1742, trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/KunePersistenceService.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/KunePersistenceService.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,41 @@
+/*
+ *
+ * Copyright (C) 2007-2011 The kune development team (see CREDITS for details)
+ * This file is part of kune.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+package cc.kune.core.server.persist;
+
+import cc.kune.core.server.error.ServerException;
+import cc.kune.core.server.init.DatabaseInitializer;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+ at Singleton
+public class KunePersistenceService {
+  @Inject
+  DatabaseInitializer databaseInitializer;
+
+  public void start() {
+    try {
+      databaseInitializer.initConditional();
+    } catch (final Exception e) {
+      throw new ServerException("Error starting persistence service", e);
+    }
+  }
+
+}

Copied: trunk/src/main/java/cc/kune/core/server/persist/KuneTransactional.java (from rev 1744, trunk/src/main/java/cc/kune/core/server/KuneTransactional.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/persist/KuneTransactional.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/persist/KuneTransactional.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -0,0 +1,29 @@
+package cc.kune.core.server.persist;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+ at Target({ ElementType.METHOD, ElementType.TYPE })
+ at Retention(RetentionPolicy.RUNTIME)
+ at Inherited
+public @interface KuneTransactional {
+
+  /**
+   * A list of exceptions to <b>not<b> rollback on. A caveat to the rollbackOn
+   * clause. The disjunction of rollbackOn and ignore represents the list of
+   * exceptions that will trigger a rollback. The complement of rollbackOn and
+   * the universal set plus any exceptions in the ignore set represents the list
+   * of exceptions that will trigger a commit. Note that ignore exceptions take
+   * precedence over rollbackOn, but with subtype granularity.
+   */
+  Class<? extends Exception>[] ignore() default {};
+
+  /**
+   * A list of exceptions to rollback on, if thrown by the transactional method.
+   * These exceptions are propagated correctly after a rollback.
+   */
+  Class<? extends Exception>[] rollbackOn() default RuntimeException.class;
+}
\ No newline at end of file

Modified: trunk/src/main/java/cc/kune/core/server/xmpp/OpenfireXmppRosterProvider.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/xmpp/OpenfireXmppRosterProvider.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/core/server/xmpp/OpenfireXmppRosterProvider.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -5,8 +5,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import cc.kune.core.server.DataSourceOpenfire;
 import cc.kune.core.server.manager.impl.DefaultManager;
+import cc.kune.core.server.persist.DataSourceOpenfire;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;

Modified: trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/main/java/cc/kune/gspace/client/options/general/UserOptGeneralPresenter.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -43,7 +43,7 @@
 
 public class UserOptGeneralPresenter extends EntityOptGeneralPresenter implements UserOptGeneral {
 
-  private boolean changeLanguage = true;
+  private boolean askChangeLanguage = true;
   private final Provider<UserServiceAsync> userService;
 
   private final UserOptGeneralView userView;
@@ -128,8 +128,8 @@
             @Override
             public void onSuccess(final StateAbstractDTO result) {
               NotifyUser.hideProgress();
-              if (changeLanguage) {
-                i18n.changeToLanguageIfNecessary(lang.getCode(), lang.getEnglishName(), true,
+              if (askChangeLanguage) {
+                i18n.changeToLanguageIfNecessary(lang.getCode(), i18n.t(lang.getEnglishName()), true,
                     new I18nLanguageChangeNeeded() {
                       @Override
                       public void onChangeNeeded() {
@@ -137,7 +137,7 @@
 
                       @Override
                       public void onChangeNotNeeded() {
-                        changeLanguage = false;
+                        askChangeLanguage = false;
                         stateManager.setRetrievedStateAndGo(result);
                         sendChangeEntityEvent();
                       }

Modified: trunk/src/test/java/cc/kune/core/server/PersistenceTest.java
===================================================================
--- trunk/src/test/java/cc/kune/core/server/PersistenceTest.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/test/java/cc/kune/core/server/PersistenceTest.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -24,6 +24,8 @@
 
 import org.junit.Before;
 
+import cc.kune.core.server.persist.DataSourceKune;
+
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.Provider;

Modified: trunk/src/test/java/cc/kune/core/server/TestHelper.java
===================================================================
--- trunk/src/test/java/cc/kune/core/server/TestHelper.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/test/java/cc/kune/core/server/TestHelper.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -34,6 +34,7 @@
 import org.waveprotocol.wave.federation.noop.NoOpFederationModule;
 
 import cc.kune.core.server.integration.HttpServletRequestMocked;
+import cc.kune.core.server.persist.DataSourceKunePersistModule;
 import cc.kune.wave.server.CustomSettingsBinder;
 
 import com.google.inject.Binder;

Modified: trunk/src/test/java/cc/kune/core/server/integration/IntegrationTestHelper.java
===================================================================
--- trunk/src/test/java/cc/kune/core/server/integration/IntegrationTestHelper.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/test/java/cc/kune/core/server/integration/IntegrationTestHelper.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -32,10 +32,10 @@
 
 import cc.kune.barters.server.BarterServerModule;
 import cc.kune.chat.server.ChatServerModule;
-import cc.kune.core.server.KunePersistenceService;
-import cc.kune.core.server.DataSourceKunePersistModule;
 import cc.kune.core.server.PlatformServerModule;
 import cc.kune.core.server.TestConstants;
+import cc.kune.core.server.persist.DataSourceKunePersistModule;
+import cc.kune.core.server.persist.KunePersistenceService;
 import cc.kune.docs.server.DocumentServerModule;
 import cc.kune.events.server.EventsServerModule;
 import cc.kune.lists.server.ListsServerModule;

Modified: trunk/src/test/java/com/google/inject/persist/jpa/KuneJpaLocalTxnInterceptor.java
===================================================================
--- trunk/src/test/java/com/google/inject/persist/jpa/KuneJpaLocalTxnInterceptor.java	2012-03-07 04:59:48 UTC (rev 1745)
+++ trunk/src/test/java/com/google/inject/persist/jpa/KuneJpaLocalTxnInterceptor.java	2012-03-07 12:19:26 UTC (rev 1746)
@@ -24,7 +24,7 @@
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
 
-import cc.kune.core.server.KuneTransactional;
+import cc.kune.core.server.persist.KuneTransactional;
 
 import com.google.inject.Inject;
 import com.google.inject.persist.UnitOfWork;




More information about the kune-commits mailing list