Author: athimel Date: 2013-09-27 20:43:30 +0200 (Fri, 27 Sep 2013) New Revision: 2806 Url: http://nuiton.org/projects/topia/repository/revisions/2806 Log: refs #552 Introduce the new TopiaPersistenceContext abstract implementation and the Hibernate implementation of TopiaJpaSupport Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -0,0 +1,193 @@ +package org.nuiton.topia; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.beans.PropertyChangeListener; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.event.TopiaEntitiesVetoable; +import org.nuiton.topia.event.TopiaEntityListener; +import org.nuiton.topia.event.TopiaEntityVetoable; +import org.nuiton.topia.event.TopiaSchemaListener; +import org.nuiton.topia.event.TopiaTransactionListener; +import org.nuiton.topia.event.TopiaTransactionVetoable; +import org.nuiton.topia.framework.TopiaService; +import org.nuiton.topia.persistence.DefaultTopiaIdFactory; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +import com.google.common.base.Preconditions; + +/** + * The application context is the main class in ToPIA usage. This class is a kind of equivalent of the RootTopiaContext. + * It contains only high level methods and new contexts creation (transaction begin, ...). This class has to be extended + * by the user, even if some default one could be automatically generated. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistenceContext> implements TopiaReplicationSupport, TopiaListenableSupport, TopiaServiceSupport { + + protected TopiaIdFactory topiaIdFactory; + + public abstract K newPersistenceContext(); +// { +// // TODO AThimel 27/09/13 Instantiate project specific TopiaPersistenceContext +// return null; +// } + + public abstract Properties getConfig(); + + protected TopiaIdFactory getTopiaIdFactory() { + if (topiaIdFactory == null) { + + String topiaIdFactoryClassName = + getConfig().getProperty(TopiaContextFactory.CONFIG_PERSISTENCE_TOPIA_ID_FACTORY_CLASS_NAME, ""); + if (StringUtils.isEmpty(topiaIdFactoryClassName)) { + topiaIdFactory = new DefaultTopiaIdFactory(); + } else { + try { + Class topiaIdFactoryClass = Class.forName(topiaIdFactoryClassName); + Preconditions.checkState(TopiaIdFactory.class.isAssignableFrom(topiaIdFactoryClass), + topiaIdFactoryClassName + " is not a valid class name. The class must implements " + + TopiaIdFactory.class.getSimpleName()); + + topiaIdFactory = (TopiaIdFactory) topiaIdFactoryClass.newInstance(); + } catch (ClassNotFoundException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } catch (InstantiationException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } catch (IllegalAccessException e) { + throw new TopiaException("Unable to create user specified TopiaIdFactory", e); + } + } + + } + return topiaIdFactory; + } + + + @Override + public void addTopiaEntityListener(TopiaEntityListener listener) { + } + + @Override + public void addTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { + } + + @Override + public void removeTopiaEntityListener(TopiaEntityListener listener) { + } + + @Override + public void removeTopiaEntityListener(Class<? extends TopiaEntity> entityClass, TopiaEntityListener listener) { + } + + @Override + public void addTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + } + + @Override + public void addTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { + } + + @Override + public void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable) { + } + + @Override + public void removeTopiaEntityVetoable(Class<? extends TopiaEntity> entityClass, TopiaEntityVetoable vetoable) { + } + + @Override + public void addTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + } + + @Override + public void removeTopiaEntitiesVetoable(TopiaEntitiesVetoable vetoable) { + } + + @Override + public void addTopiaTransactionListener(TopiaTransactionListener listener) { + } + + @Override + public void removeTopiaTransactionListener(TopiaTransactionListener listener) { + } + + @Override + public void addTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + } + + @Override + public void removeTopiaTransactionVetoable(TopiaTransactionVetoable vetoable) { + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + } + + @Override + public void addTopiaSchemaListener(TopiaSchemaListener listener) { + } + + @Override + public void removeTopiaSchemaListener(TopiaSchemaListener listener) { + } + + @Override + public void replicate(TopiaContext destinationContext, Object... entityAndCondition) throws IllegalArgumentException { + } + + @Override + public <T extends TopiaEntity> void replicateEntity(TopiaContext destinationContext, T entity) throws IllegalArgumentException { + } + + @Override + public <T extends TopiaEntity> void replicateEntities(TopiaContext destinationContext, List<T> entities) throws IllegalArgumentException { + } + + @Override + public <E extends TopiaService> boolean serviceEnabled(Class<E> interfaceService) { + return false; + } + + @Override + public <E extends TopiaService> E getService(Class<E> interfaceService) throws TopiaNotFoundException { + return null; + } + + @Override + public Map<String, TopiaService> getServices() { + return null; + } +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaApplicationContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -0,0 +1,296 @@ +package org.nuiton.topia; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.HibernateException; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; +import org.nuiton.topia.framework.TopiaFiresSupport; +import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaDAOImpl; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaIdFactory; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +/** + * Abstract implementation of the TopiaPersistenceContext. This class will be extended by a generated one in order to + * generate getXxxDao methods. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public abstract class AbstractTopiaPersistenceContext implements TopiaPersistenceContext { + + private static final Log log = LogFactory.getLog(AbstractTopiaPersistenceContext.class); + + /** + * List of persistent classes + */ + protected List<Class<?>> persistenceClasses = Lists.newArrayList(); + + /** + * Already loaded DAO cache within this persistence context + */ + protected Map<Class<? extends TopiaEntity>, TopiaDAO<? extends TopiaEntity>> daoCache = Maps.newHashMap(); // TODO AThimel 27/09/13 Concurrent map ? + + // TODO AThimel 27/09/13 Javadoc + protected TopiaFiresSupport firesSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaHibernateSupport hibernateSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaJpaSupport jpaSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaSqlSupport sqlSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaListenableSupport listenableSupport; + + /** + * Used to affect a new topiaId when create is called. + * + * @since 3.0 + */ + protected TopiaIdFactory topiaIdFactory; + + /** + * Current context configuration + */ + protected Properties config; + + public AbstractTopiaPersistenceContext(TopiaHibernateSupport hibernateSupport, + TopiaSqlSupport sqlSupport, + TopiaListenableSupport listenableSupport, + TopiaIdFactory topiaIdFactory, + Properties config) { + this.hibernateSupport = hibernateSupport; + this.sqlSupport = sqlSupport; + this.listenableSupport = listenableSupport; + this.topiaIdFactory = topiaIdFactory; + this.config = config; + + this.firesSupport = new TopiaFiresSupport(); + this.jpaSupport = new HibernateTopiaJpaSupport(hibernateSupport, firesSupport); + + } + + protected void checkClosed() throws TopiaException { + // TODO AThimel 27/09/13 IS it still useful ? +// if (closed) { +// throw new TopiaException("This context is closed, it is not possible to use it anymore"); +// } + } + + protected TopiaFiresSupport getFiresSupport() { + return firesSupport; + } + + @Override + public <E extends TopiaEntity> E findByTopiaId(String topiaId) { + checkClosed(); + + Class<E> entityClass = getTopiaIdFactory().getClassName(topiaId); + TopiaDAO<E> dao = getDAO(entityClass); + E result = dao.findByTopiaId(topiaId); + return result; + } + + @Override + public void update(TopiaEntity entity) { + checkClosed(); + + String topiaId = entity.getTopiaId(); + Class<TopiaEntity> entityClass = getTopiaIdFactory().getClassName(topiaId); + TopiaDAO<TopiaEntity> dao = getDAO(entityClass); + dao.update(entity); + + } + + @Override + public TopiaIdFactory getTopiaIdFactory() { + return topiaIdFactory; + } + + @Override + public List<Class<?>> getPersistenceClasses() { + return null; // TODO AThimel 27/09/13 May be moved to TopiaHibernateSupport ? + } + + @Override + public Properties getConfig() { + return config; + } + + @Override + public <E extends TopiaEntity> TopiaDAO<E> getDAO(Class<E> entityClass) { + Preconditions.checkArgument(entityClass != null, "The method 'getDAO' requires a non null 'entityClass' parameter"); + +// if (equals(getRootContext())) { +// throw new TopiaException( +// "You are on root context, you MUST open a transaction to perform any database access."); +// } + SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory(); + if (hibernateFactory.getClassMetadata(entityClass) == null && + hibernateFactory.getClassMetadata(entityClass.getName() + "Impl") == null && + hibernateFactory.getClassMetadata(entityClass.getName() + "Abstract") == null) { + + log.info(String.format("List of supported persistence classes: %s", + hibernateFactory.getAllClassMetadata().keySet())); + throw new TopiaException( + String.format("The following entity type %s is not managed by this context, you probably forgot to declare it.", + entityClass.getName())); + } + + TopiaDAOImpl<E> result = (TopiaDAOImpl<E>) daoCache.get(entityClass); + if (result == null) { + + // Looking for specialized DAO + // This DAO is supposed to exist, as created by generation + String daoClassName = entityClass.getName() + "DAO"; + try { + Class<TopiaDAOImpl<E>> daoClass = (Class<TopiaDAOImpl<E>>) Class.forName(daoClassName); + result = daoClass.getConstructor().newInstance(); + } catch (Exception eee) { + log.fatal("specialized DAO " + daoClassName + + " not found, use default TopiaDAOHibernate"); + throw new TopiaException("Specialized DAO " + daoClassName + " not found"); + } + + // AThimel 27/09/13 "entityClass" seems not to be needed anymore in DAO init(...) method + // TODO AThimel 27/09/13 Uncomment the next line +// result.init(hibernateSupport, jpaSupport, sqlSupport, listenableSupport, topiaIdFactory, firesSupport); + daoCache.put(entityClass, result); + } + return result; + } + + @Override + public <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityClass, Class<D> daoClass) { + return (D) getDAO(entityClass); + } + + @Override + public boolean isSchemaEmpty() { + Configuration configuration = hibernateSupport.getHibernateConfiguration(); + boolean result = TopiaUtil.isSchemaEmpty(configuration); + return result; + } + + @Override + public boolean isTableExists(Class<?> clazz) { + checkClosed(); + + Configuration configuration = hibernateSupport.getHibernateConfiguration(); + boolean result = TopiaUtil.isSchemaExist(configuration, clazz.getName()); + return result; + } + + @Override + public String getSchemaName() { + // TODO AThimel 02/08/13 I absolutely don't know if it works + return getConfig().getProperty(TopiaContextFactory.CONFIG_DEFAULT_SCHEMA); + } + + @Override + public void createSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + getFiresSupport().firePreCreateSchema(this); + new SchemaExport(hibernateSupport.getHibernateConfiguration()).execute(showSchema, true, false, true); + getFiresSupport().firePostCreateSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not create schema for reason: %s", + eee.getMessage()), eee); + } + + } + + @Override + public void showCreateSchema() { + try { + new SchemaExport(hibernateSupport.getHibernateConfiguration()). + execute(true, false, false, true); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not show create schema for reason: %s", + eee.getMessage()), eee); + } + + } + + @Override + public void updateSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + getFiresSupport().firePreUpdateSchema(this); + new SchemaUpdate(hibernateSupport.getHibernateConfiguration()).execute(showSchema, + true); + getFiresSupport().firePostUpdateSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not update schema for reason: %s", + eee.getMessage()), eee); + } + } + + @Override + public void dropSchema() { + try { + boolean showSchema = false; + if (log.isDebugEnabled()) { + showSchema = true; + } + getFiresSupport().firePreDropSchema(this); + new SchemaExport(hibernateSupport.getHibernateConfiguration()).execute(showSchema, true, true, false); + getFiresSupport().firePostDropSchema(this); + } catch (HibernateException eee) { + throw new TopiaException( + String.format("Could not drop schema for reason: %s", + eee.getMessage()), eee); + } + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/AbstractTopiaPersistenceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -0,0 +1,223 @@ +package org.nuiton.topia; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2013 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Query; +import org.nuiton.topia.framework.TopiaFiresSupport; + +import com.google.common.collect.Maps; + +/** + * This class is the Hibernate implementation of TopiaJpaSupport. It realizes the bridge between the JPA specification + * and the technical choice made for its implementation : Hibernate. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class HibernateTopiaJpaSupport implements TopiaJpaSupport { + + // TODO AThimel 27/09/13 Javadoc + protected TopiaHibernateSupport hibernateSupport; + + // TODO AThimel 27/09/13 Javadoc + protected TopiaFiresSupport firesSupport; + + /** + * This flag permits to use (or not) the flush mode when doing queries. + * <p/> + * The normal usage is to says yes (that's why the default value is + * {@code true}), in that case whebn doing queries (says in method + * {@link #findAll(String, Object...)} or {@link #find(String, int, int, Object...)}) + * it will use the flush mode {@link FlushMode#AUTO}). + * <p/> + * But sometimes, when doing a lot of queries (for some imports for example), + * we do NOT want the session to be flushed each time we do a find, then you + * can set this flag to {@code false} using the method {@link #setUseFlushMode(boolean)} + * + * @since 2.5 + */ + protected boolean useFlushMode = true; + + public HibernateTopiaJpaSupport(TopiaHibernateSupport hibernateSupport, TopiaFiresSupport firesSupport) { + this.hibernateSupport = hibernateSupport; + this.firesSupport = firesSupport; + } + + protected void checkClosed() throws TopiaException { + // TODO AThimel 27/09/13 IS it still useful ? +// if (closed) { +// throw new TopiaException("This jpaSupport is closed, it is not possible to use it anymore"); +// } + } + + @Override + public void setUseFlushMode(boolean useFlushMode) { + this.useFlushMode = useFlushMode; + } + + protected Query prepareQuery(String jpaql, Map<String, Object> parameters) { + Query query = hibernateSupport.getHibernateSession().createQuery(jpaql); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + String name = entry.getKey(); + Object value = entry.getValue(); + if (value.getClass().isArray()) { + query.setParameterList(name, (Object[]) value); + } else if (value instanceof Collection<?>) { + query.setParameterList(name, (Collection<?>) value); + } else { + query.setParameter(name, value); + } + } + // tchemit 2010-11-30 reproduce the same behaviour than before with the dao legacy + if (useFlushMode) { + query.setFlushMode(FlushMode.AUTO); + } + return query; + } + + @Override + public <T> List<T> findAll(String jpaql, Map<String, Object> parameters) { + checkClosed(); + + try { + Query query = prepareQuery(jpaql, parameters); + + List result = query.list(); + result = firesSupport.fireEntitiesLoad(this, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } + } + + @Override + public <T> List<T> find(String jpaql, int startIndex, int endIndex, Map<String, Object> parameters) { + checkClosed(); + + try { + Query query = prepareQuery(jpaql, parameters); + + // Set bounds + query.setFirstResult(startIndex); + query.setMaxResults(endIndex - startIndex + 1); + + List result = query.list(); + result = firesSupport.fireEntitiesLoad(this, result); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during query operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } + } + + @Override + public <T> T findUnique(String jpaql, Map<String, Object> parameters) { + checkClosed(); + + List<T> results = find(jpaql, 0, 1, parameters); + + // If there is more than 1 result, throw an exception + if (results.size() > 1) { + String message = String.format( + "The query '%s' returns more than 1 unique result", jpaql); + // TODO AThimel 02/08/13 Throw another exception if more than 1 result is found + throw new TopiaException(message); + } + + // otherwise return the first one, or null + T result = null; + if (!results.isEmpty()) { + result = results.get(0); + } + return result; + } + + @Override + public int execute(String jpaql, Map<String, Object> parameters) { + checkClosed(); + + try { + Query query = hibernateSupport.getHibernateSession().createQuery(jpaql); + for (Map.Entry<String, Object> entry : parameters.entrySet()) { + String name = entry.getKey(); + Object value = entry.getValue(); + query.setParameter(name, value); + } + int result = query.executeUpdate(); + return result; + } catch (HibernateException eee) { + throw new TopiaException(String.format("An error occurs during execute operation: %1$s : %2$s", + jpaql, eee.getMessage()), eee); + } + } + + protected Map<String, Object> asMap(Object[] propertyNamesAndValues) { + Map<String, Object> result = Maps.newHashMap(); + if (propertyNamesAndValues != null) { + for (int j = 0; j < propertyNamesAndValues.length; j += 2) { + String name = (String) propertyNamesAndValues[j]; + Object value = propertyNamesAndValues[j + 1]; + result.put(name, value); + } + } + return result; + } + + @Override + public <T> List<T> findAll(String jpaql, Object... propertyNamesAndValues) { + Map<String, Object> parameters = asMap(propertyNamesAndValues); + List<T> result = findAll(jpaql, parameters); + return result; + } + + @Override + public <T> List<T> find(String jpaql, int startIndex, int endIndex, Object... propertyNamesAndValues) { + Map<String, Object> parameters = asMap(propertyNamesAndValues); + List<T> result = find(jpaql, startIndex, endIndex, parameters); + return result; + } + + @Override + public <T> T findUnique(String jpaql, Object... propertyNamesAndValues) { + Map<String, Object> parameters = asMap(propertyNamesAndValues); + T result = findUnique(jpaql, parameters); + return result; + } + + @Override + public int execute(String jpaql, Object... propertyNamesAndValues) { + Map<String, Object> parameters = asMap(propertyNamesAndValues); + int result = execute(jpaql, parameters); + return result; + } + +} // HibernateTopiaJpaSupport Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/HibernateTopiaJpaSupport.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-09-27 18:27:15 UTC (rev 2805) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaPersistenceContext.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -35,7 +35,6 @@ * This API provides all methods related to persistence : * <ul> * <li>Generic entity find</li> - * <li>Persistence customization</li> * <li>DAO factory</li> * <li>Schema management</li> * </ul> @@ -75,17 +74,6 @@ List<Class<?>> getPersistenceClasses(); /** - * Tells to the context if it has to use a flush mode before each query. - * <p/> - * By default, we use a flush mode, but in some case it costs to much doing - * this, that's why you can disable it setting the value to {@code false}. - * - * @param useFlushMode the new value to set - * @since 2.5 - */ - void setUseFlushMode(boolean useFlushMode); - - /** * @return Returns the config. */ Properties getConfig(); // TODO AThimel 02/08/13 Change type ? Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-09-27 18:27:15 UTC (rev 2805) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImplementor.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -119,7 +119,7 @@ * * @param useFlushMode the new value to set * @since 2.5 - * @deprecated use method from {@link org.nuiton.topia.TopiaPersistenceContext} + * @deprecated use method from {@link org.nuiton.topia.TopiaJpaSupport} */ @Deprecated void setUseFlushMode(boolean useFlushMode); Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-09-27 18:27:15 UTC (rev 2805) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaFiresSupport.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -63,6 +63,8 @@ import org.hibernate.event.spi.SaveOrUpdateEventListener; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaJpaSupport; +import org.nuiton.topia.TopiaPersistenceContext; import org.nuiton.topia.TopiaVetoException; import org.nuiton.topia.event.TopiaContextEvent; import org.nuiton.topia.event.TopiaContextListener; @@ -769,7 +771,7 @@ * * @param context topia context */ - public void firePreCreateSchema(TopiaContext context) { + public void firePreCreateSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePreCreateSchema"); } @@ -788,7 +790,7 @@ * * @param context topia context */ - public void firePostCreateSchema(TopiaContext context) { + public void firePostCreateSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePostCreateSchema"); } @@ -807,7 +809,7 @@ * * @param context topia context */ - public void firePreUpdateSchema(TopiaContext context) { + public void firePreUpdateSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePostCreateSchema"); } @@ -826,7 +828,7 @@ * * @param context topia context */ - public void firePostUpdateSchema(TopiaContext context) { + public void firePostUpdateSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePostCreateSchema"); } @@ -884,7 +886,7 @@ * @param context topia context * @since 3.0 */ - public void firePreDropSchema(TopiaContext context) { + public void firePreDropSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePreDropSchema"); } @@ -904,7 +906,7 @@ * @param context topia context * @since 3.0 */ - public void firePostDropSchema(TopiaContext context) { + public void firePostDropSchema(TopiaPersistenceContext context) { if (log.isDebugEnabled()) { log.debug("firePostDropSchema"); } @@ -928,7 +930,7 @@ * @return the list of entities loaded */ public <E extends TopiaEntity> List<E> fireEntitiesLoad( - TopiaContext context, List<E> entities) { + TopiaJpaSupport context, List<E> entities) { if (log.isDebugEnabled()) { log.debug("fireEntitiesLoad"); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-09-27 18:27:15 UTC (rev 2805) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/PersistenceContextTransformer.java 2013-09-27 18:43:30 UTC (rev 2806) @@ -34,6 +34,7 @@ import org.nuiton.eugene.models.object.ObjectModelClass; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; +import org.nuiton.topia.AbstractTopiaPersistenceContext; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaEntity; @@ -84,19 +85,19 @@ protected void generateAbstract(String packageName, String className) { -// // try to find a super class by tag-value -// String superClass = TopiaGeneratorUtil.getPersistenceContextSuperClassTagValue( -// model); -// -// if (superClass == null) { -// -// // no super-class, use default one -// superClass = AbstractTopiaPersistenceContext.class.getName(); -// } + // try to find a super class by tag-value +// String superClass = TopiaGeneratorUtil.getPersistenceContextSuperClassTagValue(model); + String superClass = null; + if (superClass == null) { + + // no super-class, use default one + superClass = AbstractTopiaPersistenceContext.class.getName(); + } + ObjectModelClass output = createAbstractClass(className, packageName); -// setSuperClass(output, superClass); + setSuperClass(output, superClass); // detect if there is a contract to set on abstract String contractName = TopiaGeneratorUtil.getPersistenceContextInterfaceName(model); @@ -151,6 +152,7 @@ addParameter(constructor, TopiaContext.class, "context"); setOperationBody(constructor, "" /*{ + super(context, context, context, context.getTopiaIdFactory(), context.getConfig()); this.context = context; }*/ );