Author: athimel Date: 2012-05-30 18:38:41 +0200 (Wed, 30 May 2012) New Revision: 2567 Url: http://nuiton.org/repositories/revision/topia/2567 Log: Refactor exceptions Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextIllegalStateException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaImportExportException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaMisconfigurationException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaRootContextInvalidUsageException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQueryInvalidUsageException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceException.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceException.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextIllegalStateException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextIllegalStateException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextIllegalStateException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,41 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia; + +/** + * Exception that represents an illegal TopiaContext state usage. (eg. commit + * when no transaction has been opened, context closed, ...) + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaContextIllegalStateException extends TopiaException { + + private static final long serialVersionUID = -755223973024035180L; + + public TopiaContextIllegalStateException(String message) { + super(message); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaContextIllegalStateException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -28,14 +28,14 @@ /** * Main exception for ToPIA manipulation errors (entity class not found, context * unavailable, invalid state, access denied, ...). Since ToPIA 3.0, this - * exception is unchecked. + * exception is abstract and unchecked. * <p/> * Created: 23 déc. 2005 23:03:36 * * @author poussin <poussin@codelutin.com> * @version $Id$ */ -public class TopiaException extends RuntimeException { +public abstract class TopiaException extends RuntimeException { /** * Version UID Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaImportExportException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaImportExportException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaImportExportException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,47 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia; + +import org.nuiton.topia.TopiaException; + +/** + * Exception to handle any import/export failure + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + * @deprecated as import/export operations are deprecated + */ +@Deprecated +public class TopiaImportExportException extends TopiaException { + private static final long serialVersionUID = -8647343923565006463L; + + public TopiaImportExportException(String message) { + super(message); + } + + public TopiaImportExportException(String message, Throwable cause) { + super(message, cause); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaImportExportException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaMisconfigurationException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaMisconfigurationException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaMisconfigurationException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,44 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia; + +/** + * Exception that represents a configuration problem. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaMisconfigurationException extends TopiaException { + + private static final long serialVersionUID = 6659608403215001967L; + + public TopiaMisconfigurationException(String message) { + super(message); + } + + public TopiaMisconfigurationException(String message, Throwable cause) { + super(message, cause); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaMisconfigurationException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaNotFoundException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -26,25 +26,20 @@ package org.nuiton.topia; /** - * TODO-FD20100507 : Need javadoc. + * Exception that represents some missing object. Most of the time, it is + * because a given class could not be found withing the classpath. * * Created: 23 déc. 2005 23:04:28 * * @author poussin <poussin@codelutin.com> * @version $Id$ */ -public class TopiaNotFoundException extends TopiaException { +public class TopiaNotFoundException extends TopiaMisconfigurationException { /** Version UID */ - private static final long serialVersionUID = -8206486077608923797L; + private static final long serialVersionUID = -322080381055204593L; /** - * Default constructor. - */ - public TopiaNotFoundException() { - } - - /** * Constructor with {@code message}. * * @param message exception message @@ -64,12 +59,4 @@ super(message, cause); } - /** - * Constructor for a wrapped TopiaNotFoundException over a {@code cause}. - * - * @param cause exception cause - */ - public TopiaNotFoundException(Throwable cause) { - super(cause); - } } Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaRootContextInvalidUsageException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaRootContextInvalidUsageException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaRootContextInvalidUsageException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,41 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia; + +/** + * Some operations are not possible on the root context. This exception + * represents these cases. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaRootContextInvalidUsageException extends TopiaException { + + private static final long serialVersionUID = -3010531829428818338L; + + public TopiaRootContextInvalidUsageException(String message) { + super(message); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/TopiaRootContextInvalidUsageException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaContextImpl.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -41,8 +41,11 @@ import org.dom4j.io.XMLWriter; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaContextIllegalStateException; +import org.nuiton.topia.TopiaImportExportException; +import org.nuiton.topia.TopiaMisconfigurationException; import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.TopiaRootContextInvalidUsageException; import org.nuiton.topia.event.TopiaContextListener; import org.nuiton.topia.event.TopiaEntitiesVetoable; import org.nuiton.topia.event.TopiaEntityListener; @@ -54,6 +57,7 @@ import org.nuiton.topia.persistence.TopiaDAOImpl; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaIdUtil; +import org.nuiton.topia.persistence.TopiaPersistenceException; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; @@ -306,7 +310,7 @@ @Override public EntityManager getEntityManager() { if (entityManager == null) { - throw new TopiaException( + throw new TopiaContextIllegalStateException( "No EntityManager found. Please open first a new " + "transaction using 'beginTransaction()' method."); } @@ -334,7 +338,9 @@ result = getParentContext().getSpecificUtil(); } if (result == null) { - throw new TopiaException("No TopiaSpecificUtil found."); + throw new TopiaMisconfigurationException("TopiaSpecificUtil not " + + "found. Please check that you're using a " + + "topia-persistence-xxx implementation"); } return result; } @@ -479,8 +485,9 @@ throw new IllegalArgumentException(message); } if (TopiaPredicates.IS_ROOT_CONTEXT.apply(this)) { - throw new TopiaException( - "You are on root context, you MUST open a transaction to perform any database access."); + throw new TopiaRootContextInvalidUsageException( + "You are on the root context, you MUST open a transaction" + + " to perform any database access."); } Set<EntityType<?>> entities = getEntityManagerFactory().getMetamodel().getEntities(); boolean found = false; @@ -503,7 +510,7 @@ String exceptionMessage = String.format( "Entity type '%s' not managed by this context, you probably forgot to declare it.", entityClass.getName()); - throw new TopiaException(exceptionMessage); + throw new TopiaMisconfigurationException(exceptionMessage); } TopiaDAO<E> result = (TopiaDAO<E>) daoCache.get(entityClass); @@ -559,24 +566,28 @@ // maintenant, sinon lorsque l'on fait des acces a la base, une // transaction par defaut est utilisé mais elle n'est jamais vraiment // fermé ce qui pose des problemes de lock sur les tables. + boolean couldNotCreate = true; try { -// result.hibernate.beginTransaction(); result.entityManager.getTransaction().begin(); - } catch (Exception eee) { + couldNotCreate = false; + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( + "An error occurred while getting a new transaction : " + + pe.getMessage(), pe); + } finally { - // on a pas pu ouvrir la transaction, on faut donc tout fermer - // et declancher une exception - try { - result.entityManager.close(); - } catch (PersistenceException e1) { - if (log.isErrorEnabled()) { - log.error("Could not close entityManager session", e1); + if (couldNotCreate) { + // on a pas pu ouvrir la transaction, il faut donc tout fermer + // et declancher une exception + try { + result.entityManager.close(); + } catch (PersistenceException pe) { + if (log.isErrorEnabled()) { + log.error("Could not close entityManager session", pe); + } } } - throw new TopiaException( - "An error occurred while getting a new transaction : " - + eee.getMessage(), eee); } // 20081217 : add child AFTER EntityManager opening @@ -590,8 +601,8 @@ @Override public void commitTransaction() { if (TopiaPredicates.IS_ROOT_CONTEXT.apply(this)) { - String message = String.format("Operation '%s' is not permitted on root context", "commitTransaction"); - throw new TopiaException(message); + throw new TopiaRootContextInvalidUsageException("Operation " + + "'commitTransaction' is not permitted on root context"); } checkClosed("commitTransaction"); @@ -608,18 +619,22 @@ entityManager.getTransaction().begin(); - } catch (Exception eee) { - throw new TopiaException( + } catch (IllegalStateException ise) { + throw new TopiaPersistenceException( "An error occurred during commit operation : " + - eee.getMessage(), eee); + ise.getMessage(), ise); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( + "An error occurred during commit operation : " + + pe.getMessage(), pe); } } @Override public void rollbackTransaction() { if (TopiaPredicates.IS_ROOT_CONTEXT.apply(this)) { - String message = String.format("Operation '%s' is not permitted on root context", "rollbackTransaction"); - throw new TopiaException(message); + throw new TopiaRootContextInvalidUsageException("Operation " + + "'rollbackTransaction' is not permitted on root context"); } checkClosed("rollbackTransaction"); try { @@ -641,7 +656,7 @@ } } catch (PersistenceException eee) { - throw new TopiaException( + throw new TopiaPersistenceException( "An error occurred during rollback operation : " + eee.getMessage(), eee); } @@ -696,7 +711,7 @@ String message = String.format( "This context is closed, unable to perform operation '%s'", method); - throw new TopiaException(message); + throw new TopiaContextIllegalStateException(message); } } @@ -896,11 +911,11 @@ List result = query.getResultList(); result = firesSupport.fireEntitiesLoad(this, result); return result; - } catch (PersistenceException eee) { + } catch (PersistenceException pe) { String message = String.format( "An error occurred (%s) during a query operation : %s", - eee.getMessage(), jpaql); - throw new TopiaException(message, eee); + pe.getMessage(), jpaql); + throw new TopiaPersistenceException(message, pe); } } @@ -917,11 +932,11 @@ } int result = query.executeUpdate(); return result; - } catch (PersistenceException eee) { + } catch (PersistenceException pe) { String message = String.format( "An error occurred (%s) during a query operation : %s", - eee.getMessage(), jpaql); - throw new TopiaException(message, eee); + pe.getMessage(), jpaql); + throw new TopiaPersistenceException(message, pe); } } @@ -941,8 +956,8 @@ try { Query nativeQuery = getEntityManager().createNativeQuery(sqlScript); nativeQuery.executeUpdate(); - } catch (PersistenceException e) { - throw new TopiaException("Could not execute sql code", e); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException("Could not execute sql code", pe); } } @@ -967,14 +982,13 @@ } return true; } catch (ClassNotFoundException cnfe) { - throw new TopiaException( + throw new TopiaNotFoundException( "Unable to detect if schema is empty", cnfe); } } @Override - public boolean isSchemaExist(Class<?> clazz) - { + public boolean isSchemaExist(Class<?> clazz) { checkClosed("isSchemaExist"); boolean result = getSpecificUtil().isTableExists(clazz); @@ -994,10 +1008,10 @@ getFiresSupport().firePreCreateSchema(this); getSpecificUtil().createSchema(showSchema); getFiresSupport().firePostCreateSchema(this); - } catch (PersistenceException eee) { - throw new TopiaException( + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( "Schema could not be created for the following reason : " - + eee.getMessage(), eee); + + pe.getMessage(), pe); } } @@ -1005,10 +1019,10 @@ public void showCreateSchema() { try { getSpecificUtil().showCreateSchema(); - } catch (PersistenceException eee) { - throw new TopiaException( + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( "Schema creation could not be displayed for the following reason : " - + eee.getMessage(), eee); + + pe.getMessage(), pe); } } @@ -1019,10 +1033,10 @@ getFiresSupport().firePreUpdateSchema(this); getSpecificUtil().updateSchema(showSchema); getFiresSupport().firePostUpdateSchema(this); - } catch (PersistenceException eee) { - throw new TopiaException( + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( "Schema could not be updated for the following reason : " - + eee.getMessage(), eee); + + pe.getMessage(), pe); } } @@ -1193,7 +1207,7 @@ log.debug("Lecture du document terminee"); } } catch (DocumentException de) { - throw new TopiaException( + throw new TopiaImportExportException( "Could not read XML document for following reason : %s" + de.getMessage(), de); } @@ -1204,7 +1218,7 @@ getSpecificUtil().importXML(this, elements); } else { - throw new TopiaException("Empty document"); + throw new TopiaImportExportException("Empty document"); } } @@ -1235,14 +1249,14 @@ result.write(doc); result.close(); - } catch (PersistenceException eee) { - throw new TopiaException( + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( "An error occurred during export operation : %s" + - eee.getMessage(), eee); - } catch (IOException eee) { - throw new TopiaException( + pe.getMessage(), pe); + } catch (IOException ioe) { + throw new TopiaImportExportException( "An error occurred during export operation : %s" + - eee.getMessage(), eee); + ioe.getMessage(), ioe); } } @@ -1272,9 +1286,9 @@ " was sucessfully done."); } } - } catch (PersistenceException eee) { - throw new TopiaException( - "An error occurs while a replication operation : " + eee.getMessage(), eee); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( + "An error occurs while a replication operation : " + pe.getMessage(), pe); } } @@ -1337,10 +1351,10 @@ String className = entityType.getName(); try { entityAndCondition[i++] = Class.forName(className); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException cnfe) { // should never happen! - throw new TopiaException( - "class cast exception for entity " + className); + throw new TopiaNotFoundException( + "Entity class registered but not found " + className); } entityAndCondition[i++] = null; @@ -1389,9 +1403,9 @@ destinationContext.receiveReplicatedEntity(entity); } - } catch (PersistenceException eee) { - throw new TopiaException( - "An error occurs while a replication operation : " + eee.getMessage(), eee); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException( + "An error occurs while a replication operation : " + pe.getMessage(), pe); } } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaH2Util.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -54,20 +54,16 @@ */ public void backup(File file, boolean compress) throws TopiaException { context.checkClosed("backup"); - try { - String options = ""; - if (compress) { - options += " COMPRESSION GZIP"; - } - Query query = context.getEntityManager().createNativeQuery( - "SCRIPT TO '" + file.getAbsolutePath() + "'" + options); - query.getResultList(); + String options = ""; + if (compress) { + options += " COMPRESSION GZIP"; + } - } catch (Exception eee) { - throw new TopiaException( - "Unable to backup to file : " + eee.getMessage(), eee); - } + Query query = context.getEntityManager().createNativeQuery( + "SCRIPT TO '" + file.getAbsolutePath() + "'" + options); + query.getResultList(); + } /** @@ -112,7 +108,7 @@ // send event AFTER restore context.getFiresSupport().firePostRestoreSchema(context); } catch (Exception eee) { - throw new TopiaException( + throw new TopiaH2UtilException( "Unable to restore from file : " + eee.getMessage() + ". " + "SQL is " + sql, eee); } @@ -137,9 +133,21 @@ tx.closeContext(); root.finalize(); } catch (Throwable eee) { - throw new TopiaException( + throw new TopiaH2UtilException( "Unable to perform clear operation : " + eee.getMessage(), eee); } } + /** + * Exception only used within TopiaH2Util + */ + private class TopiaH2UtilException extends TopiaException { + + private static final long serialVersionUID = -7874205136201318340L; + + public TopiaH2UtilException(String message, Throwable cause) { + super(message, cause); + } + + } } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaPersistenceProvider.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -25,6 +25,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaMisconfigurationException; import javax.persistence.EntityManagerFactory; import javax.persistence.spi.PersistenceProvider; @@ -69,14 +70,14 @@ Set<Class<?>> entityClasses = (Set<Class<?>>) map.get(TOPIA_ENTITIES); if (entityClasses == null) { String message = String.format(MISSING_PROPERTY, TOPIA_ENTITIES); - throw new TopiaException(message); + throw new TopiaMisconfigurationException(message); } // Get the TopiaContextImplementor TopiaContextImplementor topiaContext = (TopiaContextImplementor)map.get(TOPIA_CONTEXT); if (topiaContext == null) { String message = String.format(MISSING_PROPERTY, TOPIA_CONTEXT); - throw new TopiaException(message); + throw new TopiaMisconfigurationException(message); } // Delegate creation to the specific JPA implementation Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -1557,7 +1557,7 @@ if (userSelects.size() > 1) { // can not count this on multiple select... - throw new TopiaException( + throw new TopiaQueryInvalidUsageException( "To count, can not have more than one select, but found " + userSelects); } @@ -1653,7 +1653,7 @@ */ protected <T extends TopiaEntity> Object loadProperty(T entity, String property) - throws TopiaException { + throws TopiaQueryInvalidUsageException { try { Object res = PropertyUtils.getProperty(entity, property); if (log.isDebugEnabled()) { @@ -1666,15 +1666,15 @@ } return res; } catch (IllegalAccessException eee) { - throw new TopiaException("Illegal access on property " + + throw new TopiaQueryInvalidUsageException("Illegal access on property " + property + " from entity " + entity.getClass().getName(), eee); } catch (InvocationTargetException eee) { - throw new TopiaException("Invocation error on entity " + + throw new TopiaQueryInvalidUsageException("Invocation error on entity " + entity.getClass().getName() + " for property " + property, eee); } catch (NoSuchMethodException eee) { - throw new TopiaException("Getter method does not exist for" + + throw new TopiaQueryInvalidUsageException("Getter method does not exist for" + " property " + property + " from entity " + entity.getClass().getName(), eee); } Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQueryInvalidUsageException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQueryInvalidUsageException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQueryInvalidUsageException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,46 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia.framework; + +import org.nuiton.topia.TopiaException; + +/** + * Exception that represents an invalid {@link TopiaQuery} usage. + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaQueryInvalidUsageException extends TopiaException { + + private static final long serialVersionUID = -9025508741037436698L; + + public TopiaQueryInvalidUsageException(String message) { + super(message); + } + + public TopiaQueryInvalidUsageException(String message, Throwable cause) { + super(message, cause); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQueryInvalidUsageException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,44 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia.framework; + +import org.nuiton.topia.TopiaException; + +import java.sql.SQLException; + +/** + * Exception that handles any {@link SQLException} for {@link TopiaSQLQuery} + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaSQLException extends TopiaException { + + private static final long serialVersionUID = -4070739964219494983L; + + public TopiaSQLException(String message, SQLException cause) { + super(message, cause); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaSQLQuery.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -26,6 +26,7 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceException; import java.sql.Connection; import java.sql.PreparedStatement; @@ -70,7 +71,7 @@ * * @param tx the transaction used to execute the query. * @return the single result or {@code null} if none found. - * @throws TopiaException for any pb + * @throws TopiaSQLException for any pb */ public O findSingleResult(TopiaContext tx) throws TopiaException { final List<O> result = new ArrayList<O>(); @@ -86,8 +87,8 @@ findSingleResult(result, set); - } catch (Exception e) { - throw new TopiaException("Could not execute query", e); + } catch (SQLException sqle) { + throw new TopiaSQLException("Could not execute query", sqle); } finally { ps.close(); } @@ -101,7 +102,7 @@ * * @param tx the transaction used to execute the query. * @return the list of results (the list is empty if non result is found). - * @throws TopiaException for any pb + * @throws TopiaSQLException for any pb */ public List<O> findMultipleResult(TopiaContext tx) throws TopiaException { final List<O> result = new ArrayList<O>(); @@ -117,8 +118,8 @@ findMultipleResult(result, set); - } catch (Exception e) { - throw new TopiaException("Could not execute query", e); + } catch (SQLException sqle) { + throw new TopiaSQLException("Could not execute query", sqle); } finally { ps.close(); } Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/DAOHelperTransformer.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -36,6 +36,7 @@ import org.nuiton.eugene.models.object.xml.ObjectModelEnumerationImpl; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; @@ -106,6 +107,7 @@ entityEnumName ); addImport(daoHelper, TopiaException.class); + addImport(daoHelper, TopiaNotFoundException.class); addImport(daoHelper, TopiaEntityEnum.class); addImport(daoHelper, EntityOperatorStore.class); addImport(daoHelper, Arrays.class); @@ -473,7 +475,7 @@ try { implementation = (Class<? extends TopiaEntity>) Class.forName(implementationFQN); } catch (ClassNotFoundException e) { - throw new TopiaException("could not find class " + implementationFQN, e); + throw new TopiaNotFoundException("Could not find class " + implementationFQN, e); } } return implementation; Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -43,6 +43,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaMisconfigurationException; import org.nuiton.topia.event.TopiaEntityListener; import org.nuiton.topia.event.TopiaEntityVetoable; import org.nuiton.topia.framework.TopiaContextImplementor; @@ -89,8 +90,7 @@ } @Override - public void init(TopiaContextImplementor context, Class<E> entityClass) - throws TopiaException { + public void init(TopiaContextImplementor context, Class<E> entityClass) { log.debug("init dao for " + entityClass.getName()); this.context = context; this.entityClass = entityClass; @@ -103,7 +103,7 @@ @SuppressWarnings("unchecked") @Override - public E newInstance() throws TopiaException { + public E newInstance() { if (log.isDebugEnabled()) { log.debug("entityClass = " + entityClass); } @@ -113,25 +113,23 @@ try { E result = implementation.newInstance(); return result; - } catch (Exception e) { - throw new TopiaException( + } catch (Exception eee) { + throw new TopiaMisconfigurationException( "Impossible de trouver ou d'instancier la classe " - + implementation); + + implementation, eee); } } @Override - public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e) - throws TopiaException { - // must be implemented by specialized dao - throw new UnsupportedOperationException(); + public <U extends TopiaEntity> List<U> findUsages(Class<U> type, E e) { + throw new UnsupportedOperationException( + "This method must be overridden in generated DAO"); } @Override - public Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E e) - throws TopiaException { - // must be implemented by specialized dao - throw new UnsupportedOperationException(); + public Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E e) { + throw new UnsupportedOperationException( + "This method must be overridden in generated DAO"); } @Override @@ -242,7 +240,7 @@ getContext().getFiresSupport().warnOnUpdateEntity(e); return e; } catch (PersistenceException eee) { - throw new TopiaException(eee); + throw new TopiaPersistenceException("Unable to perform update", eee); } } @@ -252,7 +250,7 @@ getEntityManager().remove(e); getContext().getFiresSupport().warnOnDeleteEntity(e); } catch (PersistenceException eee) { - throw new TopiaException(eee); + throw new TopiaPersistenceException("Unable to perform delete", eee); } } @@ -489,14 +487,14 @@ public Multimap<Class<? extends TopiaEntity>, TopiaEntity> getComposite( E entity) throws TopiaException { throw new UnsupportedOperationException( - "This method must be overided in generated DAO"); + "This method must be overridden in generated DAO"); } @Override public Multimap<Class<? extends TopiaEntity>, TopiaEntity> getAggregate( E entity) throws TopiaException { throw new UnsupportedOperationException( - "This method must be overided in generated DAO"); + "This method must be overridden in generated DAO"); } /** Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityAbstract.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -27,6 +27,7 @@ import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaRuntimeException; import org.nuiton.topia.framework.TopiaContextImplementor; import java.beans.PropertyChangeListener; @@ -150,13 +151,14 @@ /** * @param context The context to set. - * @throws TopiaException if any pb ? + * @throws TopiaException if trying to replace a context */ public void setTopiaContext(TopiaContext context) throws TopiaException { if (topiaContext == null) { topiaContext = context; } else { - throw new TopiaException("Remplacement du contexte interdit"); + // XXX AThimel 30/05/2012 Use deprecated TRE because this will be removed with http://nuiton.org/issues/2078 + throw new TopiaRuntimeException("Remplacement du contexte interdit"); } } Added: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceException.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceException.java (rev 0) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -0,0 +1,49 @@ +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 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% + */ +package org.nuiton.topia.persistence; + +import org.nuiton.topia.TopiaException; + +import javax.persistence.PersistenceException; +import java.sql.SQLException; + +/** + * Exception when some operation failed within the persistence provider + * + * @author Arnaud Thimel <thimel@codelutin.com> + * @since 3.0 + */ +public class TopiaPersistenceException extends TopiaException { + + private static final long serialVersionUID = 7431698657423221049L; + + public TopiaPersistenceException(String message, PersistenceException cause) { + super(message, cause); + } + + public TopiaPersistenceException(String message, IllegalStateException cause) { + super(message, cause); + } + +} Property changes on: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/persistence/util/DBMapping.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -327,14 +327,14 @@ protected BigInteger getBigInteger(TopiaContext ctxt, String sql, BigInteger defaultSize) throws TopiaException { BigInteger size = defaultSize; if (ctxt != null) { - try { +// try { Query query = ((TopiaContextImpl) ctxt).getEntityManager().createNativeQuery(sql); size = (BigInteger) query.getResultList().get(0); // } catch (SQLGrammarException e) { - } catch (Exception e) { - // could not obtain sequence - throw new TopiaException(e); - } +// } catch (Exception e) { +// // could not obtain sequence +// throw new TopiaException(e); +// } } return size; } Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceException.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceException.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/MigrationServiceException.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -25,6 +25,8 @@ package org.nuiton.topia.migration; +import org.nuiton.topia.TopiaException; + /** * TopiaMigrationServiceException.java * @@ -33,44 +35,47 @@ * @author Eon Sébastien * @author Trève Vincent * @version $Revision$ - * - * Last update : $Date$ + * <p/> + * Last update : $Date$ */ -public class MigrationServiceException extends Exception { +public class MigrationServiceException extends TopiaException { - /** - * Version - */ - private static final long serialVersionUID = -8900901171551405745L; - - /** - * Constructeur par defaut - */ - public MigrationServiceException() { - } - - /** - * Constructeur avec message - * @param message Le message d'erreur - */ - public MigrationServiceException(String message) { - super(message); - } - - /** - * Constructeur avec message et exception - * @param message Le message d'erreur - * @param exception l'exception - */ - public MigrationServiceException(String message, Throwable exception) { - super(message, exception); - } + /** + * Version + */ + private static final long serialVersionUID = -8900901171551405745L; - /** - * Constructeur avec exception - * @param exception l'exception - */ - public MigrationServiceException(Throwable exception) { - super(exception); - } + /** + * Constructeur par defaut + */ + public MigrationServiceException() { + } + + /** + * Constructeur avec message + * + * @param message Le message d'erreur + */ + public MigrationServiceException(String message) { + super(message); + } + + /** + * Constructeur avec message et exception + * + * @param message Le message d'erreur + * @param exception l'exception + */ + public MigrationServiceException(String message, Throwable exception) { + super(message, exception); + } + + /** + * Constructeur avec exception + * + * @param exception l'exception + */ + public MigrationServiceException(Throwable exception) { + super(exception); + } } Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/TopiaMigrationEngine.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -244,17 +244,12 @@ } if (migrateOnInit) { - // do automatic migration - try { - if (log.isDebugEnabled()) { - log.debug("Starts Migrate from preInit..."); - } - doMigrateSchema(); - - } catch (MigrationServiceException e) { - throw new TopiaException("Can't migrate schema for reason " + e.getMessage(), e); + if (log.isDebugEnabled()) { + log.debug("Starts Migrate from preInit..."); } + doMigrateSchema(); + } else { if (log.isDebugEnabled()) { log.debug("Service [" + this + "] skip migration on init as required"); @@ -276,7 +271,7 @@ if (log.isErrorEnabled()) { log.error("Database migration failed !"); } - throw new TopiaException("Database migration failed !"); + throw new MigrationServiceException("Database migration failed !"); } } Modified: trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java =================================================================== --- trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-30 10:35:42 UTC (rev 2566) +++ trunk/topia-service-migration/src/main/java/org/nuiton/topia/migration/mappings/TMSVersionDAO.java 2012-05-30 16:38:41 UTC (rev 2567) @@ -33,10 +33,12 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.topia.framework.TopiaSQLWork; +import org.nuiton.topia.persistence.TopiaPersistenceException; import org.nuiton.util.Version; import org.nuiton.util.VersionUtil; import javax.persistence.EntityManager; +import javax.persistence.PersistenceException; import javax.persistence.TypedQuery; import java.sql.Connection; import java.sql.PreparedStatement; @@ -97,8 +99,8 @@ // save entity session.persist(result); return result; - } catch (HibernateException e) { - throw new TopiaException("Could not create version " + version, e); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException("Could not create version " + version, pe); } } @@ -107,8 +109,8 @@ EntityManager session = ((TopiaContextImplementor) tx).getEntityManager(); session.merge(version); tx.commitTransaction(); - } catch (HibernateException e) { - throw new TopiaException("Could not update version " + version, e); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException("Could not update version " + version, pe); } } @@ -122,8 +124,8 @@ for (TMSVersion o : list) { session.remove(o); } - } catch (HibernateException e) { - throw new TopiaException("Could not delete all versions", e); + } catch (PersistenceException pe) { + throw new TopiaPersistenceException("Could not delete all versions", pe); } }