Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- 4806 discussions
r2641 - in branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence: . csv/in
by tchemit@users.nuiton.org 22 Aug '12
by tchemit@users.nuiton.org 22 Aug '12
22 Aug '12
Author: tchemit
Date: 2012-08-22 18:04:01 +0200 (Wed, 22 Aug 2012)
New Revision: 2641
Url: http://nuiton.org/repositories/revision/topia/2641
Log:
fixes 2266: Add some api about import / export in csv format (add some doc and fix api)
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/AbstractImportModel.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java 2012-08-22 10:47:37 UTC (rev 2640)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java 2012-08-22 16:04:01 UTC (rev 2641)
@@ -38,4 +38,6 @@
<E extends TopiaEntity> TopiaDAO<E> getDAO(TopiaContext tx, Class<E> type);
+ <E extends TopiaEntity> TopiaDAO<E> getDAO(TopiaContext tx, T type);
+
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/AbstractImportModel.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/AbstractImportModel.java 2012-08-22 10:47:37 UTC (rev 2640)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/AbstractImportModel.java 2012-08-22 16:04:01 UTC (rev 2641)
@@ -30,6 +30,13 @@
import java.util.List;
import java.util.Map;
+/**
+ * Abstract import model which add the useful methdo about importing foreign keys.
+ *
+ * @param <E> type of entity to import
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.12
+ */
public abstract class AbstractImportModel<E> extends org.nuiton.util.csv.ext.AbstractImportModel<E> {
public AbstractImportModel(char separator) {
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java 2012-08-22 10:47:37 UTC (rev 2640)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java 2012-08-22 16:04:01 UTC (rev 2641)
@@ -32,7 +32,7 @@
import java.util.Map;
/**
- * A model to import associations of entities into csv files.
+ * A model to import associations of entities from csv files.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.6.12
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2012-08-22 10:47:37 UTC (rev 2640)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2012-08-22 16:04:01 UTC (rev 2641)
@@ -11,7 +11,11 @@
import java.io.Reader;
/**
- * TODO
+ * Strategy to import some stuff.
+ * <p/>
+ * Implements it and then you can use it with helper methods
+ * {@link TopiaCsvImports#importTable(Reader, ImportStrategy, TableMeta, CsvImportResult)},
+ * {@link TopiaCsvImports#importAssociation(Reader, ImportStrategy, AssociationMeta, CsvImportResult)}.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.6.12
@@ -20,17 +24,14 @@
ImportModelFactory<T> getModelFactory();
- <E extends TopiaEntity> void importTableFile(Import<E> importer,
- TableMeta<T> meta,
- Reader reader,
- CsvImportResult<T> csvResult) throws TopiaException;
+ <E extends TopiaEntity> void importTable(Import<E> importer,
+ TableMeta<T> meta,
+ Reader reader,
+ CsvImportResult<T> csvResult) throws TopiaException;
- <T extends TopiaEntityEnum> void importAssociationFile(AssociationMeta<T> meta,
- ImportToMap importer,
- CsvImportResult<T> csvResult) throws TopiaException;
+ void importAssociation(AssociationMeta<T> meta,
+ ImportToMap importer,
+ CsvImportResult<T> csvResult) throws TopiaException;
- void importNMAssociationFile(AssociationMeta<T> meta,
- ImportToMap importer,
- CsvImportResult<T> csvResult) throws TopiaException;
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-22 10:47:37 UTC (rev 2640)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-22 16:04:01 UTC (rev 2641)
@@ -29,7 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.persistence.metadata.AssociationMeta;
@@ -43,6 +43,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Reader;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
@@ -59,10 +60,95 @@
/** Logger. */
private static final Log log = LogFactory.getLog(TopiaCsvImports.class);
+ protected static final String UPDATE_ASSOCIATION =
+ "UPDATE %s SET %s = '%%s' WHERE topiaId ='%%s';";
+
+ protected static final String INSERT_ASSOCIATION =
+ "INSERT INTO %s (%s,%s) VALUES('%%s','%%s');";
+
protected TopiaCsvImports() {
// no instance of this helper
}
+ /**
+ * Discover all files that can be imported (as a table or an association) from a zipfile.
+ *
+ * @param entryPrefix prefix where to find files in the zip
+ * @param possibleMetas list of possible meta to be imported
+ * @param zipFile zip file where to seek for csv files to import
+ * @param missingEntries to fill missing files
+ * @param <T> type of topia entity enum
+ * @param <M> type of data to import (table or association)
+ * @return the map of found files indexed by his meta
+ */
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, ZipEntry> discoverEntries(
+ String entryPrefix,
+ Iterable<M> possibleMetas,
+ ZipFile zipFile,
+ List<String> missingEntries) {
+
+ Map<M, ZipEntry> result = Maps.newLinkedHashMap();
+
+ // check that all mandatories
+ for (M entry : possibleMetas) {
+ String filename = entry.getFilename();
+ ZipEntry zipEntry = zipFile.getEntry(entryPrefix + filename);
+
+ if (zipEntry == null) {
+ missingEntries.add(filename);
+ } else {
+ result.put(entry, zipEntry);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Discover all files that can be imported (as a table or an association) from a directory.
+ *
+ * @param possibleMetas list of possible meta to be imported
+ * @param directory directory where to seek for csv files to import
+ * @param missingEntries to fill missing files
+ * @param <T> type of topia entity enum
+ * @param <M> type of data to import (table or association)
+ * @return the map of found files indexed by his meta
+ */
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, File> discoverEntries(
+ Iterable<M> possibleMetas,
+ File directory,
+ List<String> missingEntries) {
+
+ Map<M, File> result = Maps.newLinkedHashMap();
+
+ // check that all mandatories
+ for (M entry : possibleMetas) {
+ String filename = entry.getFilename();
+ File zipEntry = new File(directory, filename);
+
+ if (zipEntry.exists()) {
+ result.put(entry, zipEntry);
+ } else {
+ missingEntries.add(filename);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * To import a table (given by his {@code meta}) from a reader and a strategy.
+ * <p/>
+ * Result of import can be stored in an optional csv result.
+ *
+ * @param reader where to read csv data
+ * @param importStrategy import strategy used to store csv data
+ * @param meta meta of the data
+ * @param csvResult optional csv result
+ * @param <T> type of entity enum
+ * @param <E> type of data
+ * @throws TopiaException if any db problem while storing datas
+ * @throws IOException if any pb while reading csv data
+ * @see ImportStrategy#importTable(Import, TableMeta, Reader, CsvImportResult)
+ */
public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importTable(Reader reader,
ImportStrategy<T> importStrategy,
TableMeta<T> meta,
@@ -75,20 +161,38 @@
ImportModel<E> model = importStrategy.getModelFactory().buildForImport(meta);
Import<E> importer = Import.newImport(model, reader);
-
- importStrategy.importTableFile(importer,
+ try {
+ importStrategy.importTable(importer,
meta,
reader,
csvResult);
-
-
+ } finally {
+ importer.close();
+ }
}
- public static <T extends TopiaEntityEnum> void importAssociationFile(Reader reader,
- ImportStrategy<T> importStrategy,
- AssociationMeta<T> meta,
- CsvImportResult<T> csvResult) throws IOException, TopiaException {
+ /**
+ * To import a association (given by his {@code meta}) from a reader and a strategy.
+ * <p/>
+ * Result of import can be stored in an optional csv result.
+ *
+ * @param reader where to read csv data
+ * @param importStrategy import strategy used to store csv data
+ * @param meta meta of the data
+ * @param csvResult optional csv result
+ * @param <T> type of entity enum
+ * @throws TopiaException if any db problem while storing datas
+ * @throws IOException if any pb while reading csv data
+ * @see ImportStrategy#importTable(Import, TableMeta, Reader, CsvImportResult)
+ */
+ public static <T extends TopiaEntityEnum> void importAssociation(Reader reader,
+ ImportStrategy<T> importStrategy,
+ AssociationMeta<T> meta,
+ CsvImportResult<T> csvResult) throws IOException, TopiaException {
+ if (log.isInfoEnabled()) {
+ log.info("Will import " + meta);
+ }
// load a association input
ImportModelFactory<T> modelFactory = importStrategy.getModelFactory();
@@ -97,121 +201,80 @@
ImportToMap importer = ImportToMap.newImportToMap(model, reader, false);
try {
- if (modelFactory.isNMAssociationMeta(meta)) {
- importStrategy.importAssociationFile(meta, importer, csvResult);
- } else {
- importStrategy.importNMAssociationFile(meta, importer, csvResult);
- }
+ importStrategy.importAssociation(meta, importer, csvResult);
+
} finally {
importer.close();
}
}
-// public static <T extends TopiaEntityEnum> void importTableFile(TopiaContextImplementor tx,
-// ImportModelFactory<T> modelFactory,
-// TableMeta<T> meta,
-// Reader reader,
-// CsvImportResult<T> csvResult) throws IOException, TopiaException {
-//
-// ImportModel<TopiaEntity> model = modelFactory.buildForImport(meta);
-// Import<TopiaEntity> importer = Import.newImport(model, reader);
-//
-// try {
-// TopiaDAO<TopiaEntity> dao = (TopiaDAO<TopiaEntity>) tx.getDAO(meta.getSource().getContract());
-// importEntityFile(dao, meta, importer, csvResult);
-// } finally {
-// importer.close();
-// }
-// }
+ public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importAllEntities(TopiaDAO<E> dao,
+ TableMeta<T> meta,
+ Import<E> importer,
+ CsvImportResult<T> csvResult) throws TopiaException {
- public static <T extends TopiaEntityEnum> void importAssociationFile(TopiaContextImplementor tx,
- ImportModelFactory<T> modelFactory,
- AssociationMeta<T> meta,
- Reader reader,
- CsvImportResult<T> csvResult) throws IOException, TopiaException {
+ for (TopiaEntity entity : importer) {
+ Map<String, Object> properties = meta.prepareCreate(
+ entity, entity.getTopiaId());
+ E entityToSave = dao.create(properties);
- // load a association input
- ImportModel<Map<String, Object>> model =
- modelFactory.buildForImport(meta);
- ImportToMap importer = ImportToMap.newImportToMap(model, reader, false);
+ meta.copy(entity, entityToSave);
- try {
- if (modelFactory.isNMAssociationMeta(meta)) {
- importNMAssociationFile(tx, meta, importer, csvResult, 1000);
- } else {
- importAssociationFile(tx, meta, importer, csvResult, 1000);
+ if (csvResult != null) {
+ csvResult.incrementsNumberUpdated();
}
- } finally {
- importer.close();
}
}
- public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, ZipEntry> discoverEntries(
- String entryPrefix,
- Iterable<M> entries,
- ZipFile zipFile,
- List<String> missingEntries) {
+ public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importNotExistingEntities(TopiaDAO<E> dao,
+ TableMeta<T> meta,
+ Map<String, TopiaEntity> universe,
+ Import<E> importer,
+ CsvImportResult<T> csvResult) throws TopiaException {
- Map<M, ZipEntry> result = Maps.newLinkedHashMap();
+ for (TopiaEntity entity : importer) {
- // check that all mandatories
- for (M entry : entries) {
- String filename = entry.getFilename();
- ZipEntry zipEntry = zipFile.getEntry(entryPrefix + filename);
+ String topiaId = entity.getTopiaId();
- if (zipEntry == null) {
- missingEntries.add(filename);
- } else {
- result.put(entry, zipEntry);
- }
- }
- return result;
- }
+ Map<String, Object> properties = meta.prepareCreate(entity, null);
+ E existingEntity = dao.findByProperties(properties);
+ if (existingEntity == null) {
- public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, File> discoverEntries(
- Iterable<M> entries,
- File zipFile,
- List<String> missingEntries) {
+ // new entity to create
+ E entityToSave = dao.create(properties);
+ String newTopiaId = entityToSave.getTopiaId();
+ Date topiaCreateDate = entityToSave.getTopiaCreateDate();
+ meta.copy(entity, entityToSave);
+ entityToSave.setTopiaId(newTopiaId);
+ entityToSave.setTopiaCreateDate(topiaCreateDate);
- Map<M, File> result = Maps.newLinkedHashMap();
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Create entity [%s becomes %s] with naturalId %s", topiaId, newTopiaId, properties));
+ }
+ universe.put(topiaId, entityToSave);
- // check that all mandatories
- for (M entry : entries) {
- String filename = entry.getFilename();
- File zipEntry = new File(zipFile, filename);
+ if (csvResult != null) {
+ csvResult.incrementsNumberCreated();
+ }
+ } else {
+ // existing entity, nothing to create
+ // just add a ref into universe to make translation possible by foreign keys
- if (zipEntry.exists()) {
- result.put(entry, zipEntry);
- } else {
- missingEntries.add(filename);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Existing entity [%s] with naturalId %s, do not create anything", topiaId, properties));
+ }
+
+ universe.put(topiaId, existingEntity);
}
}
- return result;
}
-// public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importEntityFile(TopiaDAO<E> dao,
-// TableMeta<T> meta,
-// Import<E> importer,
-// CsvImportResult<T> csvResult) throws TopiaException {
-//
-// for (TopiaEntity entity : importer) {
-//
-// Map<String, Object> properties = meta.prepareCreate(
-// entity, entity.getTopiaId());
-// E entityToSave = dao.create(properties);
-//
-// meta.copy(entity, entityToSave);
-//
-// csvResult.incrementsNumberUpdated();
-// }
-// }
+ public static <T extends TopiaEntityEnum> void importAssociation(TopiaContext tx, AssociationMeta<T> meta,
+ ImportToMap importer,
+ CsvImportResult<T> csvResult,
+ int nbRowBuffer) throws TopiaException {
- public static <T extends TopiaEntityEnum> void importAssociationFile(TopiaContext tx, AssociationMeta<T> meta,
- ImportToMap importer,
- CsvImportResult<T> csvResult,
- int nbRowBuffer) throws TopiaException {
-
T source = meta.getSource();
T target = meta.getTarget();
@@ -221,7 +284,7 @@
String sourceTableName = source.getContract().getSimpleName();
String table = targetTableName;
- String updateString = String.format("UPDATE %s SET %s = '%%s' WHERE topiaId ='%%s';", table, sourceTableName);
+ String updateString = String.format(UPDATE_ASSOCIATION, table, sourceTableName);
if (log.isDebugEnabled()) {
log.debug("Will apply " + updateString);
@@ -241,18 +304,20 @@
}
}
}
- csvResult.incrementsNumberUpdated();
+ if (csvResult != null) {
+ csvResult.incrementsNumberUpdated();
+ }
}
if (builder.length() > 0) {
tx.executeSQL(builder.toString());
}
}
- public static <T extends TopiaEntityEnum> void importNMAssociationFile(TopiaContext tx,
- AssociationMeta<T> meta,
- ImportToMap importer,
- CsvImportResult<T> csvResult,
- int nbRowBuffer) throws TopiaException {
+ public static <T extends TopiaEntityEnum> void importNMAssociation(TopiaContext tx,
+ AssociationMeta<T> meta,
+ ImportToMap importer,
+ CsvImportResult<T> csvResult,
+ int nbRowBuffer) throws TopiaException {
T source = meta.getSource();
T target = meta.getTarget();
@@ -267,7 +332,7 @@
String table = TopiaEntityHelper.getNormalizedAssociationTableName(
sourceTableName, targetTableName);
- String updateString = String.format("INSERT INTO %s (%s,%s) VALUES('%%s','%%s');", table, sourceTableName, targetTableName);
+ String updateString = String.format(INSERT_ASSOCIATION, table, sourceTableName, targetTableName);
if (log.isDebugEnabled()) {
log.debug("Will apply " + updateString);
@@ -287,7 +352,9 @@
}
}
}
- csvResult.incrementsNumberUpdated();
+ if (csvResult != null) {
+ csvResult.incrementsNumberUpdated();
+ }
}
if (builder.length() > 0) {
tx.executeSQL(builder.toString());
1
0
r2640 - in branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv: in out
by tchemit@users.nuiton.org 22 Aug '12
by tchemit@users.nuiton.org 22 Aug '12
22 Aug '12
Author: tchemit
Date: 2012-08-22 12:47:37 +0200 (Wed, 22 Aug 2012)
New Revision: 2640
Url: http://nuiton.org/repositories/revision/topia/2640
Log:
refs #2266: Add some api about import / export in csv format
Added:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/CsvFileImportResult.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/CsvFileImportResult.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/CsvFileImportResult.java 2012-08-22 10:47:23 UTC (rev 2639)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/CsvFileImportResult.java 2012-08-22 10:47:37 UTC (rev 2640)
@@ -35,8 +35,8 @@
/**
* To keep result of the import of a file.
*
+ * @author tchemit <chemit(a)codelutin.com>
* @since 2.6.12
- * @author tchemit <chemit(a)codelutin.com>
*/
public class CsvFileImportResult<T extends TopiaEntityEnum> implements Serializable {
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java 2012-08-22 10:47:23 UTC (rev 2639)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/EntityAssociationImportModel.java 2012-08-22 10:47:37 UTC (rev 2640)
@@ -24,8 +24,9 @@
*/
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topia.persistence.csv.TopiaCsvCommons;
import org.nuiton.topia.persistence.metadata.AssociationMeta;
-import org.nuiton.topia.persistence.csv.TopiaCsvCommons;
import org.nuiton.util.csv.ImportModel;
import java.util.Map;
@@ -36,14 +37,13 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.6.12
*/
-public class EntityAssociationImportModel extends AbstractImportModel<Map<String, Object>> {
+public class EntityAssociationImportModel<T extends TopiaEntityEnum> extends AbstractImportModel<Map<String, Object>> {
protected final AssociationMeta meta;
- public static ImportModel<Map<String, Object>> newImportModel(char separator,
- AssociationMeta meta
- ) {
- EntityAssociationImportModel model = new EntityAssociationImportModel(
+ public static <T extends TopiaEntityEnum> ImportModel<Map<String, Object>> newImportModel(char separator,
+ AssociationMeta<T> meta) {
+ EntityAssociationImportModel<T> model = new EntityAssociationImportModel<T>(
separator, meta);
// topiaId <-> topiaId
@@ -67,7 +67,7 @@
return null;
}
- public EntityAssociationImportModel(char separator, AssociationMeta meta) {
+ public EntityAssociationImportModel(char separator, AssociationMeta<T> meta) {
super(separator);
this.meta = meta;
}
Added: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java (rev 0)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2012-08-22 10:47:37 UTC (rev 2640)
@@ -0,0 +1,36 @@
+package org.nuiton.topia.persistence.csv.in;
+
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topia.persistence.metadata.AssociationMeta;
+import org.nuiton.topia.persistence.metadata.TableMeta;
+import org.nuiton.util.csv.Import;
+import org.nuiton.util.csv.ImportToMap;
+
+import java.io.Reader;
+
+/**
+ * TODO
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.12
+ */
+public interface ImportStrategy<T extends TopiaEntityEnum> {
+
+ ImportModelFactory<T> getModelFactory();
+
+ <E extends TopiaEntity> void importTableFile(Import<E> importer,
+ TableMeta<T> meta,
+ Reader reader,
+ CsvImportResult<T> csvResult) throws TopiaException;
+
+ <T extends TopiaEntityEnum> void importAssociationFile(AssociationMeta<T> meta,
+ ImportToMap importer,
+ CsvImportResult<T> csvResult) throws TopiaException;
+
+ void importNMAssociationFile(AssociationMeta<T> meta,
+ ImportToMap importer,
+ CsvImportResult<T> csvResult) throws TopiaException;
+
+}
Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-22 10:47:23 UTC (rev 2639)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-22 10:47:37 UTC (rev 2640)
@@ -30,7 +30,6 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.persistence.metadata.AssociationMeta;
@@ -64,57 +63,100 @@
// no instance of this helper
}
- public static <T extends TopiaEntityEnum> void importFile(TopiaContextImplementor tx,
- ImportModelFactory<T> modelFactory,
- MetaFilenameAware<T> entry,
- Reader reader,
- CsvImportResult<T> csvResult) throws IOException, TopiaException {
+ public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importTable(Reader reader,
+ ImportStrategy<T> importStrategy,
+ TableMeta<T> meta,
+ CsvImportResult<T> csvResult) throws TopiaException, IOException {
- if (entry instanceof AssociationMeta) {
- // load a association input
- AssociationMeta<T> meta = (AssociationMeta<T>) entry;
- ImportModel<Map<String, Object>> model =
- modelFactory.buildForImport(meta);
- ImportToMap importer = ImportToMap.newImportToMap(model, reader, false);
+ if (log.isInfoEnabled()) {
+ log.info("Will import " + meta);
+ }
- try {
- if (modelFactory.isNMAssociationMeta(meta)) {
- importNMAssociationFile(tx, meta, importer, csvResult, 1000);
- } else {
- importAssociationFile(tx, meta, importer, csvResult, 1000);
- }
- } finally {
- importer.close();
+ ImportModel<E> model = importStrategy.getModelFactory().buildForImport(meta);
+ Import<E> importer = Import.newImport(model, reader);
+
+ importStrategy.importTableFile(importer,
+ meta,
+ reader,
+ csvResult);
+
+
+ }
+
+ public static <T extends TopiaEntityEnum> void importAssociationFile(Reader reader,
+ ImportStrategy<T> importStrategy,
+ AssociationMeta<T> meta,
+ CsvImportResult<T> csvResult) throws IOException, TopiaException {
+
+
+ // load a association input
+ ImportModelFactory<T> modelFactory = importStrategy.getModelFactory();
+ ImportModel<Map<String, Object>> model =
+ modelFactory.buildForImport(meta);
+ ImportToMap importer = ImportToMap.newImportToMap(model, reader, false);
+
+ try {
+ if (modelFactory.isNMAssociationMeta(meta)) {
+ importStrategy.importAssociationFile(meta, importer, csvResult);
+ } else {
+ importStrategy.importNMAssociationFile(meta, importer, csvResult);
}
+ } finally {
+ importer.close();
+ }
+ }
- } else {
+// public static <T extends TopiaEntityEnum> void importTableFile(TopiaContextImplementor tx,
+// ImportModelFactory<T> modelFactory,
+// TableMeta<T> meta,
+// Reader reader,
+// CsvImportResult<T> csvResult) throws IOException, TopiaException {
+//
+// ImportModel<TopiaEntity> model = modelFactory.buildForImport(meta);
+// Import<TopiaEntity> importer = Import.newImport(model, reader);
+//
+// try {
+// TopiaDAO<TopiaEntity> dao = (TopiaDAO<TopiaEntity>) tx.getDAO(meta.getSource().getContract());
+// importEntityFile(dao, meta, importer, csvResult);
+// } finally {
+// importer.close();
+// }
+// }
- // normal entity table import
- TableMeta<T> meta = (TableMeta<T>) entry;
- ImportModel<TopiaEntity> model = modelFactory.buildForImport(meta);
- Import<TopiaEntity> importer = Import.newImport(model, reader);
+ public static <T extends TopiaEntityEnum> void importAssociationFile(TopiaContextImplementor tx,
+ ImportModelFactory<T> modelFactory,
+ AssociationMeta<T> meta,
+ Reader reader,
+ CsvImportResult<T> csvResult) throws IOException, TopiaException {
- try {
- TopiaDAO<TopiaEntity> dao = (TopiaDAO<TopiaEntity>) tx.getDAO(meta.getSource().getContract());
- importEntityFile(dao, meta, importer, csvResult);
- } finally {
- importer.close();
+
+ // load a association input
+ ImportModel<Map<String, Object>> model =
+ modelFactory.buildForImport(meta);
+ ImportToMap importer = ImportToMap.newImportToMap(model, reader, false);
+
+ try {
+ if (modelFactory.isNMAssociationMeta(meta)) {
+ importNMAssociationFile(tx, meta, importer, csvResult, 1000);
+ } else {
+ importAssociationFile(tx, meta, importer, csvResult, 1000);
}
+ } finally {
+ importer.close();
}
-
}
- public static <T extends TopiaEntityEnum> Map<MetaFilenameAware<T>, ZipEntry> discoverEntries(
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, ZipEntry> discoverEntries(
String entryPrefix,
- MetaFilenameAware<T>[] entries,
+ Iterable<M> entries,
ZipFile zipFile,
List<String> missingEntries) {
- Map<MetaFilenameAware<T>, ZipEntry> result = Maps.newLinkedHashMap();
+ Map<M, ZipEntry> result = Maps.newLinkedHashMap();
// check that all mandatories
- for (MetaFilenameAware<T> entry : entries) {
+ for (M entry : entries) {
String filename = entry.getFilename();
ZipEntry zipEntry = zipFile.getEntry(entryPrefix + filename);
@@ -127,15 +169,15 @@
return result;
}
- public static <T extends TopiaEntityEnum> Map<MetaFilenameAware<T>, File> discoverEntries(
- MetaFilenameAware<T>[] entries,
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<M, File> discoverEntries(
+ Iterable<M> entries,
File zipFile,
List<String> missingEntries) {
- Map<MetaFilenameAware<T>, File> result = Maps.newLinkedHashMap();
+ Map<M, File> result = Maps.newLinkedHashMap();
// check that all mandatories
- for (MetaFilenameAware<T> entry : entries) {
+ for (M entry : entries) {
String filename = entry.getFilename();
File zipEntry = new File(zipFile, filename);
@@ -148,23 +190,23 @@
return result;
}
- public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importEntityFile(TopiaDAO<E> dao,
- TableMeta<T> meta,
- Import<E> importer,
- CsvImportResult<T> csvResult) throws TopiaException {
+// public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importEntityFile(TopiaDAO<E> dao,
+// TableMeta<T> meta,
+// Import<E> importer,
+// CsvImportResult<T> csvResult) throws TopiaException {
+//
+// for (TopiaEntity entity : importer) {
+//
+// Map<String, Object> properties = meta.prepareCreate(
+// entity, entity.getTopiaId());
+// E entityToSave = dao.create(properties);
+//
+// meta.copy(entity, entityToSave);
+//
+// csvResult.incrementsNumberUpdated();
+// }
+// }
- for (TopiaEntity entity : importer) {
-
- Map<String, Object> properties = meta.prepareCreate(
- entity, entity.getTopiaId());
- E entityToSave = dao.create(properties);
-
- meta.copy(entity, entityToSave);
-
- csvResult.incrementsNumberUpdated();
- }
- }
-
public static <T extends TopiaEntityEnum> void importAssociationFile(TopiaContext tx, AssociationMeta<T> meta,
ImportToMap importer,
CsvImportResult<T> csvResult,
@@ -206,7 +248,8 @@
}
}
- public static <T extends TopiaEntityEnum> void importNMAssociationFile(TopiaContext tx, AssociationMeta<T> meta,
+ public static <T extends TopiaEntityEnum> void importNMAssociationFile(TopiaContext tx,
+ AssociationMeta<T> meta,
ImportToMap importer,
CsvImportResult<T> csvResult,
int nbRowBuffer) throws TopiaException {
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java 2012-08-22 10:47:23 UTC (rev 2639)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/TopiaCsvExports.java 2012-08-22 10:47:37 UTC (rev 2640)
@@ -37,6 +37,7 @@
import org.nuiton.topia.persistence.TopiaEntityEnum;
import org.nuiton.topia.persistence.metadata.AssociationMeta;
import org.nuiton.topia.persistence.metadata.MetaFilenameAware;
+import org.nuiton.topia.persistence.metadata.Metadatas;
import org.nuiton.topia.persistence.metadata.TableMeta;
import org.nuiton.util.TimeLog;
import org.nuiton.util.csv.Export;
@@ -191,6 +192,44 @@
}
+ public static <T extends TopiaEntityEnum> Map<T, EntityExportContext<T>> createReplicateEntityVisitorContexts(ExportModelFactory<T> modelFactory,
+ Iterable<TableMeta<T>> entityMetas,
+ Iterable<AssociationMeta<T>> associationMetas,
+ File container) {
+
+ Preconditions.checkNotNull(modelFactory);
+ Preconditions.checkNotNull(entityMetas);
+ Preconditions.checkNotNull(associationMetas);
+ Preconditions.checkNotNull(container);
+
+ Multimap<T, AssociationMeta<T>> associations = Metadatas.split(associationMetas);
+ Map<T, EntityExportContext<T>> contexts = Maps.newHashMap();
+
+ for (TableMeta<T> meta : entityMetas) {
+
+ ExportModel<TopiaEntity> model = modelFactory.buildForExport(meta);
+
+ EntityExportContext<T> exportContext = EntityExportContext.newExportContext(
+ model,
+ meta,
+ container);
+
+ T source = meta.getSource();
+
+ contexts.put(source, exportContext);
+
+ for (AssociationMeta<T> associationMeta : associations.get(source)) {
+
+ ExportModel<TopiaEntity> associationModel =
+ modelFactory.buildForExport(associationMeta);
+ exportContext.addAssociationExportContext(associationMeta,
+ associationModel,
+ container);
+ }
+ }
+ return contexts;
+ }
+
/**
* to export entity as csv files.
*
1
0
r2639 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata
by tchemit@users.nuiton.org 22 Aug '12
by tchemit@users.nuiton.org 22 Aug '12
22 Aug '12
Author: tchemit
Date: 2012-08-22 12:47:23 +0200 (Wed, 22 Aug 2012)
New Revision: 2639
Url: http://nuiton.org/repositories/revision/topia/2639
Log:
refs #2260: Add a metadata package in persistence
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java 2012-08-21 16:09:15 UTC (rev 2638)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java 2012-08-22 10:47:23 UTC (rev 2639)
@@ -57,6 +57,28 @@
return new DbMeta<T>(typeProvider, universe, nonEditables);
}
+ public void addTables(List<TableMeta<T>> entities,
+ Iterable<T> types) {
+ for (T type : types) {
+
+ TableMeta<T> tableMeta = getTable(type);
+ if (entities != null) {
+ entities.add(tableMeta);
+ }
+ }
+ }
+
+ public void addAssociations(List<AssociationMeta<T>> associations,
+ Iterable<T> types) {
+ for (T type : types) {
+
+ TableMeta<T> tableMeta = getTable(type);
+ if (associations != null) {
+ associations.addAll(tableMeta.getAssociations());
+ }
+ }
+ }
+
public List<String> getTableNames() {
List<String> result = Lists.newArrayList();
for (TableMeta tableMeta : getTables()) {
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java 2012-08-21 16:09:15 UTC (rev 2638)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java 2012-08-22 10:47:23 UTC (rev 2639)
@@ -29,7 +29,6 @@
import com.google.common.collect.Multimaps;
import org.nuiton.topia.persistence.TopiaEntityEnum;
-import java.util.List;
import java.util.Map;
/**
@@ -40,39 +39,23 @@
*/
public class Metadatas {
- public static <T extends TopiaEntityEnum> void addEntries(DbMeta<T> dbMeta,
- List<MetaFilenameAware<T>> entities,
- List<MetaFilenameAware<T>> associations,
- T... types) {
- for (T type : types) {
-
- TableMeta<T> tableMeta = dbMeta.getTable(type);
- if (entities != null) {
- entities.add(tableMeta);
- }
- if (associations != null) {
- associations.addAll(tableMeta.getAssociations());
- }
- }
- }
-
- public static <T extends TopiaEntityEnum> Multimap<T, MetaFilenameAware<T>> split(List<MetaFilenameAware<T>> metas) {
- Function<MetaFilenameAware<T>, T> function = newMetaBySourcefunction();
- Multimap<T, MetaFilenameAware<T>> associationsBySource = Multimaps.index(metas, function);
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Multimap<T, M> split(Iterable<M> metas) {
+ Function<M, T> function = newMetaBySourcefunction();
+ Multimap<T, M> associationsBySource = Multimaps.index(metas, function);
return associationsBySource;
}
- public static <T extends TopiaEntityEnum> Map<T, MetaFilenameAware<T>> uniqueIndex(List<MetaFilenameAware<T>> metas) {
- Function<MetaFilenameAware<T>, T> function = newMetaBySourcefunction();
- Map<T, MetaFilenameAware<T>> associationsBySource = Maps.uniqueIndex(metas, function);
+ public static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Map<T, M> uniqueIndex(Iterable<M> metas) {
+ Function<M, T> function = newMetaBySourcefunction();
+ Map<T, M> associationsBySource = Maps.uniqueIndex(metas, function);
return associationsBySource;
}
- protected static <T extends TopiaEntityEnum> Function<MetaFilenameAware<T>, T> newMetaBySourcefunction() {
- return new Function<MetaFilenameAware<T>, T>() {
+ protected static <T extends TopiaEntityEnum, M extends MetaFilenameAware<T>> Function<M, T> newMetaBySourcefunction() {
+ return new Function<M, T>() {
@Override
- public T apply(MetaFilenameAware<T> input) {
+ public T apply(M input) {
return input.getSource();
}
};
1
0
r2638 - in branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence: csv csv/in csv/out metadata
by tchemit@users.nuiton.org 21 Aug '12
by tchemit@users.nuiton.org 21 Aug '12
21 Aug '12
Author: tchemit
Date: 2012-08-21 18:09:15 +0200 (Tue, 21 Aug 2012)
New Revision: 2638
Url: http://nuiton.org/repositories/revision/topia/2638
Log:
refs #2266: Add some api about import / export in csv format (improve import api)
Removed:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaEntityEnumProvider.java
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/EntityCsvModel.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -140,6 +140,16 @@
);
}
+ public <E extends TopiaEntity> void addForeignKeyForImport(String propertyName,
+ Class<E> entityType,
+ Map<String, E> universe) {
+
+ newMandatoryColumn(propertyName,
+ TopiaCsvCommons.newForeignKeyValue(entityType,
+ propertyName,
+ universe)
+ );
+ }
public void addDefaultColumn(String propertyName, Class<?> type) {
addDefaultColumn(propertyName, propertyName, type);
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -41,6 +41,7 @@
import org.nuiton.util.csv.ImportModel;
import org.nuiton.util.csv.ImportToMap;
+import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.List;
@@ -126,6 +127,27 @@
return result;
}
+ public static <T extends TopiaEntityEnum> Map<MetaFilenameAware<T>, File> discoverEntries(
+ MetaFilenameAware<T>[] entries,
+ File zipFile,
+ List<String> missingEntries) {
+
+ Map<MetaFilenameAware<T>, File> result = Maps.newLinkedHashMap();
+
+ // check that all mandatories
+ for (MetaFilenameAware<T> entry : entries) {
+ String filename = entry.getFilename();
+ File zipEntry = new File(zipFile, filename);
+
+ if (zipEntry.exists()) {
+ result.put(entry, zipEntry);
+ } else {
+ missingEntries.add(filename);
+ }
+ }
+ return result;
+ }
+
public static <T extends TopiaEntityEnum, E extends TopiaEntity> void importEntityFile(TopiaDAO<E> dao,
TableMeta<T> meta,
Import<E> importer,
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -32,7 +32,7 @@
import org.nuiton.topia.persistence.EntityVisitor;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
-import org.nuiton.topia.persistence.metadata.TopiaEntityEnumProvider;
+import org.nuiton.topia.persistence.TopiaPersistenceHelper;
import org.nuiton.util.TimeLog;
import java.io.Closeable;
@@ -57,20 +57,20 @@
/** Export for simple entity. */
protected final Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters;
- protected final TopiaEntityEnumProvider<T> entityEnumProvider;
+ protected final TopiaPersistenceHelper<T> persistenceHelper;
public static <T extends TopiaEntityEnum> ExportEntityVisitor<T> newVisitor(
- TopiaEntityEnumProvider<T> entityEnumProvider,
+ TopiaPersistenceHelper<T> persistenceHelper,
Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters) {
return new ExportEntityVisitor<T>(
- entityEnumProvider,
+ persistenceHelper,
entityExporters
);
}
- public ExportEntityVisitor(TopiaEntityEnumProvider<T> entityEnumProvider,
+ public ExportEntityVisitor(TopiaPersistenceHelper<T> persistenceHelper,
Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters) {
- this.entityEnumProvider = entityEnumProvider;
+ this.persistenceHelper = persistenceHelper;
this.entityExporters = entityExporters;
}
@@ -150,7 +150,7 @@
Object value) {
if (TopiaEntity.class.isAssignableFrom(type) &&
- getEntityContext(type) != null) {
+ getEntityContext((Class<? extends TopiaEntity>) type) != null) {
Collection<?> cValue = (Collection<?>) value;
if (CollectionUtils.isNotEmpty(cValue)) {
@@ -203,8 +203,8 @@
// prefer use the close api
}
- protected TopiaCsvExports.EntityExportContext getEntityContext(Class<?> entityType) {
- T entityEnum = entityEnumProvider.getEntityEnum(entityType);
+ protected TopiaCsvExports.EntityExportContext getEntityContext(Class<? extends TopiaEntity> entityType) {
+ T entityEnum = persistenceHelper.getEntityEnum(entityType);
return entityEnum == null ? null : entityExporters.get(entityEnum);
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/DbMeta.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -28,6 +28,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topia.persistence.TopiaPersistenceHelper;
import java.util.Iterator;
import java.util.List;
@@ -47,10 +48,10 @@
/** All types non editables. */
protected final Set<T> nonEditableTypes;
- protected final TopiaEntityEnumProvider<T> entityEnumProvider;
+ protected final TopiaPersistenceHelper<T> persistenceHelper;
public static <T extends TopiaEntityEnum> DbMeta<T> newDbMeta(
- TopiaEntityEnumProvider<T> typeProvider,
+ TopiaPersistenceHelper<T> typeProvider,
T[] universe,
T... nonEditables) {
return new DbMeta<T>(typeProvider, universe, nonEditables);
@@ -85,14 +86,14 @@
return getTables().iterator();
}
- protected DbMeta(TopiaEntityEnumProvider<T> entityEnumProvider,
+ protected DbMeta(TopiaPersistenceHelper<T> persistenceHelper,
T[] entityTypes,
T... nonEditableTypes) {
- this.entityEnumProvider = entityEnumProvider;
+ this.persistenceHelper = persistenceHelper;
this.nonEditableTypes = Sets.newHashSet(nonEditableTypes);
tables = Lists.newArrayList();
for (T entityEnum : entityTypes) {
- TableMeta<T> tableMeta = TableMeta.newMeta(entityEnum, entityEnumProvider);
+ TableMeta<T> tableMeta = TableMeta.newMeta(entityEnum, persistenceHelper);
tables.add(tableMeta);
}
}
@@ -101,7 +102,7 @@
return !nonEditableTypes.contains(meta.getSource());
}
- public TopiaEntityEnumProvider<T> getEntityEnumProvider() {
- return entityEnumProvider;
+ public TopiaPersistenceHelper<T> getPersistenceHelper() {
+ return persistenceHelper;
}
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/Metadatas.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -24,11 +24,13 @@
*/
import com.google.common.base.Function;
+import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.nuiton.topia.persistence.TopiaEntityEnum;
import java.util.List;
+import java.util.Map;
/**
* Useful methods around metadatas.
@@ -58,7 +60,12 @@
Function<MetaFilenameAware<T>, T> function = newMetaBySourcefunction();
Multimap<T, MetaFilenameAware<T>> associationsBySource = Multimaps.index(metas, function);
return associationsBySource;
+ }
+ public static <T extends TopiaEntityEnum> Map<T, MetaFilenameAware<T>> uniqueIndex(List<MetaFilenameAware<T>> metas) {
+ Function<MetaFilenameAware<T>, T> function = newMetaBySourcefunction();
+ Map<T, MetaFilenameAware<T>> associationsBySource = Maps.uniqueIndex(metas, function);
+ return associationsBySource;
}
protected static <T extends TopiaEntityEnum> Function<MetaFilenameAware<T>, T> newMetaBySourcefunction() {
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TableMeta.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -30,6 +30,7 @@
import org.nuiton.topia.TopiaRuntimeException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topia.persistence.TopiaPersistenceHelper;
import org.nuiton.topia.persistence.util.EntityOperator;
import org.nuiton.topia.persistence.util.EntityOperatorStore;
import org.nuiton.util.ObjectUtil;
@@ -58,7 +59,7 @@
private static final long serialVersionUID = 1L;
public static <T extends TopiaEntityEnum> TableMeta<T> newMeta(T entityEnum,
- TopiaEntityEnumProvider<T> typeProvider) {
+ TopiaPersistenceHelper<T> typeProvider) {
return new TableMeta<T>(entityEnum, typeProvider);
}
@@ -204,7 +205,7 @@
return binder;
}
- protected TableMeta(T source, TopiaEntityEnumProvider<T> typeProvider) {
+ protected TableMeta(T source, TopiaPersistenceHelper<T> typeProvider) {
Preconditions.checkNotNull(source);
this.source = source;
@@ -219,7 +220,7 @@
if (TopiaEntity.class.isAssignableFrom(propertyType)) {
// only use it for entity
- T targetEnum = typeProvider.getEntityEnum(propertyType);
+ T targetEnum = typeProvider.getEntityEnum((Class<TopiaEntity>) propertyType);
AssociationMeta<T> meta = AssociationMeta.newMeta(source,
targetEnum,
@@ -237,7 +238,7 @@
ColumnMeta meta = ColumnMeta.newMeta(property, propertyType);
columns.add(meta);
if (meta.isFK()) {
- T dependency = typeProvider.getEntityEnum(propertyType);
+ T dependency = typeProvider.getEntityEnum((Class<TopiaEntity>) propertyType);
deps.add(dependency);
}
}
Deleted: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaEntityEnumProvider.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaEntityEnumProvider.java 2012-08-21 16:08:41 UTC (rev 2637)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaEntityEnumProvider.java 2012-08-21 16:09:15 UTC (rev 2638)
@@ -1,38 +0,0 @@
-package org.nuiton.topia.persistence.metadata;
-/*
- * #%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%
- */
-
-import org.nuiton.topia.persistence.TopiaEntityEnum;
-
-/**
- * Provider of {@link TopiaEntityEnum}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 2.6.12
- */
-public interface TopiaEntityEnumProvider<T extends TopiaEntityEnum> {
-
- <E> T getEntityEnum(Class<E> type);
-
-}
1
0
r2637 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 21 Aug '12
by tchemit@users.nuiton.org 21 Aug '12
21 Aug '12
Author: tchemit
Date: 2012-08-21 18:08:41 +0200 (Tue, 21 Aug 2012)
New Revision: 2637
Url: http://nuiton.org/repositories/revision/topia/2637
Log:
fixes #2278: Introduce a TopiaPersistenceHelper
Added:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java
Copied: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java (from rev 2636, branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaEntityEnumProvider.java)
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java (rev 0)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java 2012-08-21 16:08:41 UTC (rev 2637)
@@ -0,0 +1,41 @@
+package org.nuiton.topia.persistence;
+/*
+ * #%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%
+ */
+
+import org.nuiton.topia.TopiaContext;
+
+/**
+ * Object which helps to wrap some static generated code
+ * (dao helper, entityEnum).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.12
+ */
+public interface TopiaPersistenceHelper<T extends TopiaEntityEnum> {
+
+ <E extends TopiaEntity> T getEntityEnum(Class<E> type);
+
+ <E extends TopiaEntity> TopiaDAO<E> getDAO(TopiaContext tx, Class<E> type);
+
+}
Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaPersistenceHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r2636 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence
by tchemit@users.nuiton.org 19 Aug '12
by tchemit@users.nuiton.org 19 Aug '12
19 Aug '12
Author: tchemit
Date: 2012-08-19 17:11:52 +0200 (Sun, 19 Aug 2012)
New Revision: 2636
Url: http://nuiton.org/repositories/revision/topia/2636
Log:
fixes #2276: Add deleteAll method on TopiaDAO
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 14:34:44 UTC (rev 2635)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 15:11:52 UTC (rev 2636)
@@ -133,6 +133,14 @@
*/
void delete(E e) throws TopiaException;
+ /**
+ * Permet de supprimer des entités.
+ *
+ * @param entities les entités à supprimer
+ * @throws TopiaException if any pb while deleting datas
+ */
+ void deleteAll(Iterable<E> entities) throws TopiaException;
+
//------------------------------------------------------------------------//
//-- findByXXX methods ---------------------------------------------------//
//------------------------------------------------------------------------//
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 14:34:44 UTC (rev 2635)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 15:11:52 UTC (rev 2636)
@@ -325,6 +325,13 @@
}
@Override
+ public void deleteAll(Iterable<E> entities) throws TopiaException {
+ for (E entity : entities) {
+ delete(entity);
+ }
+ }
+
+ @Override
public TopiaQuery createQuery() {
return new TopiaQuery(getEntityClass());
}
1
0
r2635 - in branches/topia-2.6.x/topia-persistence/src: license main/resources/i18n
by tchemit@users.nuiton.org 19 Aug '12
by tchemit@users.nuiton.org 19 Aug '12
19 Aug '12
Author: tchemit
Date: 2012-08-19 16:34:44 +0200 (Sun, 19 Aug 2012)
New Revision: 2635
Url: http://nuiton.org/repositories/revision/topia/2635
Log:
fix i18n + optimize third-parties
Modified:
branches/topia-2.6.x/topia-persistence/src/license/THIRD-PARTY.properties
branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties
branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties
Modified: branches/topia-2.6.x/topia-persistence/src/license/THIRD-PARTY.properties
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/license/THIRD-PARTY.properties 2012-08-19 11:11:48 UTC (rev 2634)
+++ branches/topia-2.6.x/topia-persistence/src/license/THIRD-PARTY.properties 2012-08-19 14:34:44 UTC (rev 2635)
@@ -5,6 +5,7 @@
# - BSD style
# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
# - Common Public License Version 1.0
+# - GNU Library or Lesser General Public License
# - Indiana University Extreme! Lab Software License, vesion 1.1.1
# - Lesser General Public License (LGPL) v 3.0
# - Lesser General Public License (LPGL)
@@ -14,16 +15,17 @@
# - Mozilla Public License Version 1.0
# - The Apache Software License, Version 2.0
# - The H2 License, Version 1.0
-# - http://jaxen.codehaus.org/license.html
+# - The SAX License
+# - The W3C License
+# - The Werken Company License
# - license.txt
#-------------------------------------------------------------------------------
# Please fill the missing licenses for dependencies :
#
#
-#Thu Jan 12 16:55:28 CET 2012
+#Sun Aug 19 16:33:57 CEST 2012
antlr--antlr--2.7.6=BSD License
commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0
dom4j--dom4j--1.6.1=BSD License
javax.transaction--jta--1.1=COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
-jaxen--jaxen--1.1.1=http\://jaxen.codehaus.org/license.html
jdom--jdom--1.0=The Apache Software License, Version 2.0
Modified: branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties 2012-08-19 11:11:48 UTC (rev 2634)
+++ branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_en_GB.properties 2012-08-19 14:34:44 UTC (rev 2635)
@@ -5,7 +5,7 @@
topia.persistence.error.empty.doc=Empty document
topia.persistence.error.no.hibernate.session=No hinernate session found, you must at first, open a new transaction via 'beaginTransaction' method.
topia.persistence.error.null.param=The method '%1$s' requires a non null parameter '%2$s'.
-topia.persistence.error.on.clear=
+topia.persistence.error.on.clear=Error %s on clear operation
topia.persistence.error.on.commit=An error occurs while commit operation \: %1$s
topia.persistence.error.on.export=An error occurs while export operation \: %1$s
topia.persistence.error.on.loding.xml.doc=Could not read xml document for following reason \: %1$s
@@ -21,7 +21,7 @@
topia.persistence.error.service.unknown=The service %1$s of type %2$s was not found.
topia.persistence.error.unsupported.class=The following entity type %1$s is not managed by this context, you probably forgot to declare it.
topia.persistence.error.unsupported.operation.on.closed.context=This context is closed, it is not possible to release the operation '%1$s'
-topia.persistence.error.unsupported.operation.on.root.context=
+topia.persistence.error.unsupported.operation.on.root.context=Unsupported operation %s on root context
topia.persistence.error.update.schema=Schema could not be updated for following reason \: %1$s
topia.persistence.service.loaded=Service '%1$s' loaded (implementation %2$s)
topia.persistence.supported.classes.for.context=List of supported persistence classes \: %1$s
Modified: branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties 2012-08-19 11:11:48 UTC (rev 2634)
+++ branches/topia-2.6.x/topia-persistence/src/main/resources/i18n/topia-persistence_fr_FR.properties 2012-08-19 14:34:44 UTC (rev 2635)
@@ -5,7 +5,7 @@
topia.persistence.error.empty.doc=Document vide
topia.persistence.error.no.hibernate.session=Aucune session hibernate trouvée, vous devez démarré une transaction avec la méthode 'beginTransaction'
topia.persistence.error.null.param=La méthode '%1$s' requière un paramètre '%2$s' non null.
-topia.persistence.error.on.clear=
+topia.persistence.error.on.clear=Une erreur est apparue pendant le clear \: %s
topia.persistence.error.on.commit=Une erreur est apparue pendant le commit \: %1$s
topia.persistence.error.on.export=Une erreur est apparue pendant l'export \: %1$s
topia.persistence.error.on.loding.xml.doc=Lecture du document impossible pour la raison suivante \: %1$s
@@ -21,7 +21,7 @@
topia.persistence.error.service.unknown=Le service '%1$s' ayant pour classe '%2$s' n'est pas connu
topia.persistence.error.unsupported.class=La classe %1$s n'est pas supportée par ce TopiaContext, vous avez sans doute oublié d'ajouter son mapping
topia.persistence.error.unsupported.operation.on.closed.context=Ce contexte a été fermé, impossible de réaliser l'opération %1$s
-topia.persistence.error.unsupported.operation.on.root.context=
+topia.persistence.error.unsupported.operation.on.root.context=Opération interdite %s sur le rootContext
topia.persistence.error.update.schema=Le schéma n'a pas pu être mis à jour pour la raison suivante \: %2$s
topia.persistence.service.loaded=Service '%1$s' chargé par '%2$s'
topia.persistence.supported.classes.for.context=Classes supportées par ce TopiaContext \: %1$s
1
0
r2634 - in branches/topia-2.6.x/topia-persistence/src: main/java/org/nuiton/topia main/java/org/nuiton/topia/framework main/java/org/nuiton/topia/persistence test/java/org/nuiton/topia/test/ano1991
by tchemit@users.nuiton.org 19 Aug '12
by tchemit@users.nuiton.org 19 Aug '12
19 Aug '12
Author: tchemit
Date: 2012-08-19 13:11:48 +0200 (Sun, 19 Aug 2012)
New Revision: 2634
Url: http://nuiton.org/repositories/revision/topia/2634
Log:
fixes #2271: Deprecate TopiaQuery
refs #2274: Improve TopiaDAO javadoc
refs #2272: Add new methods to TopiaDAO to do search without using TopiaQuery
Added:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java
branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/TopiaContext.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -182,7 +182,9 @@
* @param query TopiaQuery to execute
* @return a List of results as hibernate give us
* @throws TopiaException
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
List findByQuery(TopiaQuery query) throws TopiaException;
/**
@@ -192,7 +194,9 @@
* @param alias alias of the entity in the Query
* @return a new TopiaQuery
* @see TopiaQuery
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
TopiaQuery createQuery(Class<?> entityClass, String alias);
/**
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -62,39 +62,39 @@
* addGroup, ...
* - execution of the query, using executeToEntityList, executeToEntity,
* executeToInteger, ...
- * <p/>
+ *
* Construction
* ============
- * <p/>
+ *
* This class make easier the way to construct a HQL query.
- * <p/>
+ *
* Example 1 :
* -----------
- * <p/>
+ *
* SQL :
* "SELECT * FROM PersonImpl WHERE firstName LIKE 'M%' AND year > 1980"
- * <p/>
+ *
* HQL using {@link TopiaContext#findAll(String, Object...) } :
* TopiaContext context = rootContext.beginTransaction();
* context.find("FROM " + Person.class.getName() + " WHERE firstName LIKE
* :firstName AND year > :year",
* "firstName", "M%", year, 1980);
- * <p/>
+ *
* TopiaQuery :
* TopiaQuery query = TopiaQuery.createQuery(Person.class).add(
* Person.FIRST_NAME, Op.LIKE, "M%").add(Person.YEAR, Op.GT, 1980);
- * <p/>
+ *
* But the real advantage is when you have some parameters to test before
* adding
* them to the query. With the older method, it was tidious to construct
* and add parameters to finally use the find method from TopiaContext.
- * <p/>
+ *
* Example 2 :
* -----------
- * <p/>
+ *
* HQL using {@link TopiaContext#findAll(String, Object...) } :
* TopiaContext context = rootContext.beginTransaction();
- * <p/>
+ *
* String query = "FROM " + Person.class.getName();
* List<Object> params = new ArrayList<Object>();
* String separator = " WHERE ";
@@ -105,7 +105,7 @@
* params.add(company);
* separator = " AND ";
* }
- * <p/>
+ *
* // contact paramater can be null
* if (contact != null) {
* query += separator + "contact = :contact";
@@ -113,33 +113,33 @@
* params.add(contact);
* separator = " AND ";
* }
- * <p/>
+ *
* context.findAll(query, params.toArray());
- * <p/>
+ *
* Here we have only two non obligatory params, but imagine if we must have
* almost 6 or 7 parameters like this !
- * <p/>
+ *
* TopiaQuery :
* TopiaQuery query = TopiaQuery.createQuery(Person.class);
- * <p/>
+ *
* if (company != null) {
* query.add(Person.COMPANY, company);
* }
- * <p/>
+ *
* if (contact != null) {
* query.add(Person.CONTACT, contact);
* }
- * <p/>
+ *
* Many ways to create the same query :
* ------------------------------------
- * <p/>
+ *
* You can use multiple different manners to create a query, it depends on the
* complexicity. More complex is the query, more easier is to construct it.
- * <p/>
+ *
* HQL : "FROM PersonImpl AS P WHERE (P.company IS NULL OR P.company =
* :company)
* AND P.firstName LIKE :firstName"
- * <p/>
+ *
* Using TopiaQuery and an Alias (these different queries are equivalent) :
* query = TopiaQuery.createQuery(Person.class, "P");
* 1- query.add("(P.company IS NULL OR P.company = :company") AND P.firstName
@@ -153,72 +153,72 @@
* .addParam("company", company);
* 4- query.addNullOr("P.company", Op.EQ, company).
* add("P.firstName", Op.LIKE, firstName + "%");
- * <p/>
+ *
* You can use TopiaQuery to create a subquery in an other TopiaQuery, you have
* to use the method {@link #fullQuery() } to get the full query in HQL and
* give
* it as a string in the other TopiaQuery.
- * <p/>
+ *
* Execution
* =========
- * <p/>
+ *
* After construction, you can execute the query in different ways.
- * <p/>
+ *
* Default method :
* ----------------
- * <p/>
+ *
* - execute : as the same result as
* {@link TopiaContext#findAll(String, Object...) }
- * <p/>
+ *
* Depends on entity type ;
* ------------------------
- * <p/>
+ *
* - executeToEntity : only one result, the first one
* - executeToEntityList : all results returned in a List
* - executeToEntityMap : all results returned in a Map with key defined by
* user
* or topiaId by default
- * <p/>
+ *
* For aggregate :
* ---------------
- * <p/>
+ *
* These methods have in argument the SELECT to execute the query. The previous
* SELECT (if defined) will not be deleted, but temporarly not used.
- * <p/>
+ *
* - executeToInteger : for example for "SUM", "COUNT"
* - executeToString : for example for "MAX"
* - executeCount : directly a "count(*)"
* - executeToObject : for other type of possible result (Long, Boolean,
* Double,
* ...)
- * <p/>
+ *
* Property loading
* ================
- * <p/>
+ *
* When using Hibernate, some times, Entities linked to the main one will be
* lazy initialized, but you want them directly when the query will be executed
* to avoid problems when closing context. You can use the method
* {@link #addLoad(String...) } to tell the TopiaQuery to load some
* properties when executing the query. After that, you don't need to call them
* for loading them in Hibernate.
- * <p/>
+ *
* The syntax is the same as a property in HQL query using delegation :
* "person.company" where person and company are entities.
- * <p/>
+ *
* Note : loading only available on collection or entities but not property
* on a collection of entities which must be made manually.
- * <p/>
+ *
* For a Contact which is linked to a person (entity) and the person linked to
* company (entity) you can add to a TopiaQuery<Contact> :
* query.addLoad("person.company")
- * <p/>
+ *
* For a list of addresses (entity) in the contact you can do :
* query.addLoad("addresses")
- * <p/>
+ *
* But it's not possible to do for example with meeting (entity) linked to the
* contact and responsible (entity) linked to a meeting :
* query.addLoad("meetings.responsible")
- * <p/>
+ *
* </pre>
* <p/>
* Created: 21 déc. 2009
@@ -227,9 +227,6 @@
* @version $Revision$
* @since 2.3.0
* @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
- * <p/>
- * Mise a jour: $Date$ par
- * : $Author$
*/
@Deprecated
public class TopiaQuery {
@@ -250,7 +247,7 @@
/**
* To keep SELECT part of the query filled by user.
- *
+ *
* @since 2.6.7
*/
protected List<String> userSelects;
@@ -279,6 +276,7 @@
protected boolean distinct;
//TODO tchemit-2012-02-01 Remove this (see Evol #1931)
+
/** From part of the query. */
protected StringBuilder from;
@@ -411,7 +409,7 @@
* @param str the element to add
* @return the TopiaQuery
* @see #addFrom(Class, String)
- * @see #addJoin(String, String, boolean)
+ * @see #addJoin(String, String, boolean)
* @see #addLeftJoin(String, String, boolean)
* @deprecated since 2.3.4 use correct addFrom or addJoin or addLeftJoin
*/
@@ -425,7 +423,7 @@
* the query or for join as specific {@code separator}.
*
* @param property the property to add
- * @param alias alias of the property to add in form part of the query
+ * @param alias alias of the property to add in form part of the query
* @param separator The separator to use before adding the element (if null
* the {@link #FROM_SEPARATOR_DEFAULT} will be used).
* @return the TopiaQuery
@@ -545,7 +543,7 @@
// result.append(selectStatement).append(mainAlias);
// }
result.append(from);
-
+
if (CollectionUtils.isNotEmpty(wheres)) {
result.append(" WHERE ");
boolean first = true;
@@ -673,7 +671,7 @@
boolean needAlias = false;
if (StringUtils.isEmpty(mainAlias)) {
mainAlias = RandomStringUtils.randomAlphabetic(4);
- from.append(' ').append(mainAlias);
+ from.append(' ').append(mainAlias);
needAlias = true;
}
@@ -687,8 +685,8 @@
for (String current : properties) {
// Add missing alias if needed
- String property = needAlias ?
- getProperty(mainAlias, current) : current;
+ String property = needAlias ?
+ getProperty(mainAlias, current) : current;
// Split property on .
String[] parts = property.split("\\.");
@@ -709,7 +707,7 @@
}
// Add the property in left join with fetch to true
- addLeftJoin(propertyToJoin, alias, true);
+ addLeftJoin(propertyToJoin, alias, true);
}
}
return this;
@@ -767,7 +765,7 @@
}
/**
- * @param paramName name of the parameter to add
+ * @param paramName name of the parameter to add
* @param constraint constraint to use
* @param paramValue value of this parameter
* @return TopiaQuery
@@ -804,7 +802,7 @@
result.append(Op.NULL);
} else {
String valueName = getValueName(paramName);
- if (Op.IN ==operator || Op.NOT_IN == operator) {
+ if (Op.IN == operator || Op.NOT_IN == operator) {
result.append(operator).append(" (:").append(valueName).append(')');
} else {
@@ -830,13 +828,13 @@
if (getParams().contains(valueName)) {
valueName = valueName + "_" +
- RandomStringUtils.randomAlphanumeric(4);
+ RandomStringUtils.randomAlphanumeric(4);
}
return valueName;
}
/**
- * @param paramName name of the parameter to add
+ * @param paramName name of the parameter to add
* @param paramValue value of this parameter
* @return TopiaQuery
* @since 2.3.1
@@ -1025,7 +1023,7 @@
* Add link constraint between two properties. {@code elementProperty} is in
* elements of {@code containerProperty} which is a collection with same type
* than {@code elementProperty}. (HQL : elementProperty IN elements
- * (containerProperty))
+ * (containerProperty))
*
* @param elementProperty contains in containerProperty collection
* @param containerProperty collection which contains elementProperty
@@ -1090,7 +1088,7 @@
// Replace old paramName in subquery
subqueryString =
subqueryString.replace(":" + paramName,
- ":" + newParamName);
+ ":" + newParamName);
// Add the param to the current query
addParam(newParamName, paramValue);
@@ -1137,9 +1135,9 @@
userSelects.add(mainAlias);
}
}
-
+
userSelects.addAll(Arrays.asList(select));
-
+
// // if select is not null, add the new element to the select
// if (this.select != null) {
// this.select.append(", ");
@@ -1185,7 +1183,7 @@
* @return the TopiaQuery
*/
public TopiaQuery addOrder(String... order) {
- if (orderBys==null) {
+ if (orderBys == null) {
orderBys = new ArrayList<String>();
}
Collections.addAll(orderBys, order);
@@ -1210,7 +1208,7 @@
* @return the TopiaQuery
*/
public TopiaQuery addGroup(String... group) {
- if (groupBys==null) {
+ if (groupBys == null) {
groupBys = new ArrayList<String>();
}
Collections.addAll(groupBys, group);
@@ -1287,10 +1285,10 @@
* recent in first)
*
* @param filter Filter to apply on the query
- * @see #addFilter(EntityFilter, String)
* @return the TopiaQuery
* @throws IllegalArgumentException if referenceId is defined but no
* referenceProperty was set
+ * @see #addFilter(EntityFilter, String)
*/
public TopiaQuery addFilter(EntityFilter filter)
throws IllegalArgumentException {
@@ -1360,8 +1358,8 @@
if (filter.hasReference()) {
if (referenceProperty == null) {
throw new IllegalArgumentException("Reference property need" +
- " to be defined in filter to use referenceId = " +
- referenceId);
+ " to be defined in filter to use referenceId = " +
+ referenceId);
}
addEquals(getPropertyId(referenceProperty), referenceId);
}
@@ -1386,7 +1384,7 @@
List result;
if (startIndex != null && endIndex != null) {
result = transaction.find(query, startIndex, endIndex,
- getParams().toArray());
+ getParams().toArray());
} else {
result = transaction.findAll(query, getParams().toArray());
}
@@ -1425,8 +1423,8 @@
}
if (!entityClass.isAssignableFrom(o.getClass())) {
throw new ClassCastException(o.getClass().getName() +
- " can't be cast to " + entityClass.getName() +
- " o : " + o);
+ " can't be cast to " + entityClass.getName() +
+ " o : " + o);
}
E entity = (E) o;
// Check distinct constraint for complex query where o is firstly an
@@ -1469,7 +1467,7 @@
Object value = loadProperty(elmt, keyName);
if (value != null && !keyClass.isAssignableFrom(value.getClass())) {
throw new ClassCastException(value.getClass().getName() +
- " can't be cast to " + keyClass.getName());
+ " can't be cast to " + keyClass.getName());
}
results.put((K) value, elmt);
}
@@ -1492,7 +1490,7 @@
TopiaContext transaction, Class<E> entityClass)
throws TopiaException, ClassCastException {
return executeToEntityMap(transaction, entityClass,
- TopiaEntity.TOPIA_ID, String.class);
+ TopiaEntity.TOPIA_ID, String.class);
}
/**
@@ -1589,7 +1587,7 @@
*/
public int executeCount(TopiaContext transaction) throws TopiaException {
List<String> oldOrderBys = orderBys;
- orderBys=null;
+ orderBys = null;
// StringBuilder oldOrder = orderBy;
// orderBy = null;
StringBuilder count = new StringBuilder("COUNT(");
@@ -1639,10 +1637,10 @@
// orderBy = oldOrder;
return result;
}
-
+
protected boolean isUserSelectEqualsMainAlias() {
boolean result = !CollectionUtils.isEmpty(userSelects) &&
- userSelects.size()==1 &&
+ userSelects.size() == 1 &&
userSelects.get(0).equals(mainAlias);
return result;
}
@@ -1672,7 +1670,7 @@
}
if (log.isTraceEnabled()) {
log.trace("Current entity : " +
- currEntity.getClass().getSimpleName());
+ currEntity.getClass().getSimpleName());
log.trace("Current loading : " + s);
}
if (it.hasNext()) {
@@ -1717,7 +1715,7 @@
Object res = PropertyUtils.getProperty(entity, property);
if (log.isDebugEnabled()) {
log.debug("load property '" + property + "' for '" +
- entity.getClass().getSimpleName() + "'");
+ entity.getClass().getSimpleName() + "'");
}
if (res != null && Collection.class.isAssignableFrom(res.getClass())) {
Collection<?> list = (Collection<?>) res;
@@ -1726,16 +1724,16 @@
return res;
} catch (IllegalAccessException eee) {
throw new TopiaException("Illegal access on property " +
- property + " from entity " +
- entity.getClass().getName(), eee);
+ property + " from entity " +
+ entity.getClass().getName(), eee);
} catch (InvocationTargetException eee) {
throw new TopiaException("Invocation error on entity " +
- entity.getClass().getName() + " for property " +
- property, eee);
+ entity.getClass().getName() + " for property " +
+ property, eee);
} catch (NoSuchMethodException eee) {
throw new TopiaException("Getter method does not exist for" +
- " property " + property + " from entity " +
- entity.getClass().getName(), eee);
+ " property " + property + " from entity " +
+ entity.getClass().getName(), eee);
}
}
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -36,12 +36,10 @@
*/
package org.nuiton.topia.persistence;
-import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.event.TopiaEntityListener;
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
-import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.generator.EntityDAOTransformer;
import java.security.Permission;
@@ -50,37 +48,27 @@
/**
* TopiaDAO is used to manipulate entities corresponding to {@code E} type :
- * create, delete, update or find entities using properties of {@link
- * TopiaQuery}.
+ * create, delete, update or find entities.
* <p/>
* This interface is implemented by {@link TopiaDAOImpl} overridden by generation
* from {@link EntityDAOTransformer}.
* <p/>
*
- * @param <E> the entity type linked with the dao
+ * @param <E> the entity type managed by the dao
* @author bpoussin <poussin(a)codelutin.com>
* @author fdesbois <fdesbois(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
* @version $Id$
*/
-public interface TopiaDAO<E extends TopiaEntity> {
+public interface TopiaDAO<E extends TopiaEntity> extends TopiaDAODeprecated<E> {
- TopiaEntityEnum getTopiaEntityEnum();
+ //------------------------------------------------------------------------//
+ //-- Create - update - delete methods ------------------------------------//
+ //------------------------------------------------------------------------//
/**
- * When TopiaContextImpl create the TopiaDAOHibernate, it must call this
- * method just after.
+ * Create a new instance of managed entity <strong>not persisted</strong>.
*
- * @param context context
- * @param entityClass entity class
- * @throws TopiaException if any pb while init
- */
- void init(TopiaContextImplementor context, Class<E> entityClass)
- throws TopiaException;
-
- /**
- * Create a new instance of managed entity.
- *
* @return new entity instance
* @throws TopiaException if any pb while creating the entity
* @since 2.3.1
@@ -88,73 +76,6 @@
E newInstance() throws TopiaException;
/**
- * Return class of entity managed by this DAO.
- *
- * @return entity managed by this DAO
- */
- Class<E> getEntityClass();
-
- /**
- * Return context used by this DAO.
- *
- * @return Returns the context.
- */
- TopiaContextImplementor getContext();
-
- /**
- * Find usages of the given {@code entity} in the entities of the given
- * {@code type}.
- *
- * @param type the type of entity to search
- * @param entity the entity
- * @param <U> tthe type of entity to search
- * @return the list of entities of the given type which uses the given
- * entity
- * @throws TopiaException if any problem while getting data
- * @since 2.3.0
- */
- <U extends TopiaEntity> List<U> findUsages(Class<U> type, E entity)
- throws TopiaException;
-
- /**
- * Find all usages of the given {@code entity}.
- *
- * @param entity the entity
- * @return the dictionnary of usages of the given entities (keys are entity
- * usage container, values are the list of this type of entity to
- * use the given entity).
- * @throws TopiaException if any pb while getting data
- * @since 2.3.0
- */
-
- Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity)
- throws TopiaException;
-
- /**
- * Retourne les permissions a verifier pour l'acces a l'entite pour le
- * service Taas.
- *
- * @param topiaId topiaId d'une entite
- * @param actions encoded actions
- * @return la liste des permissions
- * @throws TopiaException if any pb while getting datas
- */
- List<Permission> getRequestPermission(String topiaId, int actions)
- throws TopiaException;
-
- /* Adders */
-
- void addTopiaEntityListener(TopiaEntityListener listener);
-
- void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /* Removers */
-
- void removeTopiaEntityListener(TopiaEntityListener listener);
-
- void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
-
- /**
* Construit une nouvelle instance de l'objet géré par ce DAO
*
* @param properties la liste des propriétés que doit avoir l'objet créé les
@@ -212,36 +133,13 @@
*/
void delete(E e) throws TopiaException;
- /**
- * Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM
- * E"
- *
- * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
- * type d'entité)
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
- */
- @Deprecated
- TopiaQuery createQuery();
+ //------------------------------------------------------------------------//
+ //-- findByXXX methods ---------------------------------------------------//
+ //------------------------------------------------------------------------//
/**
- * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias
- * valable dans la requête..
- * <p/>
- * Résultat attendu : "FROM E AS entityAlias"
- *
- * @param entityAlias alias permettant de manipuler l'entité dans la
- * requête
- * @return une nouvelle TopiaQuery
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
- */
- @Deprecated
- TopiaQuery createQuery(String entityAlias);
-
- /**
* Find an entity corresponding to the {@code id}. If the {@code id} is
- * null, nothing will be search.
+ * null, nothing will be searched.
*
* @param id topiaId of the entity to found
* @return the entity found or null if not
@@ -249,8 +147,15 @@
*/
E findByTopiaId(String id) throws TopiaException;
- E findByProperty(String propertyName, Object value)
- throws TopiaException;
+ /**
+ * Find an entity matching {@code value} for the given {@code propertyName}.
+ *
+ * @param propertyName property name to filter
+ * @param value value of the property to math
+ * @return the first entity matching the request
+ * @throws TopiaException
+ */
+ E findByProperty(String propertyName, Object value) throws TopiaException;
/**
* @param propertyName le nom de la propriété
@@ -260,26 +165,88 @@
* @return l'entité trouvé
* @throws TopiaException if any pb while getting datas
*/
- E findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException;
+ E findByProperties(String propertyName, Object value, Object... others) throws TopiaException;
+ /**
+ * Find an entity matching {@code properties}.
+ *
+ * @param properties les propriétés à matcher
+ * @return l'entité trouvé
+ * @throws TopiaException if any pb while getting datas
+ */
E findByProperties(Map<String, Object> properties) throws TopiaException;
/**
* Execute une requête basé sur l'entité du DAO. Permet de récupérer une
* entité correspondant à la requête.
*
- * @param query la requête
+ * @param hql la requête hql à executer
+ * @param params les paramètres de la requète
* @return l'entité correspondant à la recherche ou null si aucune entité
* n'a été trouvée
* @throws TopiaException if any pb while getting datas
- * @see TopiaQuery#executeToEntity(TopiaContext, Class)
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- E findByQuery(TopiaQuery query) throws TopiaException;
+ E findByQuery(String hql, Object... params) throws TopiaException;
+ /**
+ * Execute une requête basé sur le {@code type} donné.
+ * <p/>
+ * Permet de récupérer une entité correspondant à la requête.
+ *
+ * @param hql la requête hql à executer
+ * @param params les paramètres de la requète
+ * @return l'entité correspondant à la recherche ou null si aucune entité
+ * n'a été trouvée
+ * @throws TopiaException if any pb while getting datas
+ * @since 2.6.12
+ */
+ <R> R findByQuery(Class<R> type, String hql, Object... params) throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, chaque champs de la
+ * cle naturelle est une entre de la map passe en argument.
+ *
+ * @param keys la liste des champs de la cle naturelle avec leur valeur
+ * @return l'entite trouvé
+ * @throws TopiaException if any pb while getting datas
+ */
+ E findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
+
+ /**
+ * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
+ * est composé de plusieurs champs alors les arguments passés doivent être
+ * dans l'ordre de declaration dans le fichier de mapping
+ *
+ * @param k l'objet cle naturelle de la classe
+ * @return l'entité trouvé
+ * @throws TopiaException if any pb while getting datas
+ */
+ E findByPrimaryKey(Object... k) throws TopiaException;
+
+ /**
+ * Récupère la première entité (du type géré par ce dao) dont la
+ * collection nommée {@code propertyName} contient la {@code property}
+ * donnée.
+ *
+ * @param propertyName le nom de la propriété
+ * @param property la propriété recherchée
+ * @return la première entité recherchée
+ * @throws TopiaException pour tout erreur lors de la recherche
+ * @since 2.5.4
+ */
+ E findContains(String propertyName, Object property) throws TopiaException;
+
+ //------------------------------------------------------------------------//
+ //-- findAllXXX methods --------------------------------------------------//
+ //------------------------------------------------------------------------//
+
+ /**
+ * Gets all entitys of the dao type in db.
+ *
+ * @return all entities of the dao type in db
+ * @throws TopiaException
+ */
List<E> findAll() throws TopiaException;
/**
@@ -290,71 +257,112 @@
*/
List<String> findAllIds() throws TopiaException;
+ /**
+ * Gets all entities of the dao type matching the {@code value} for the
+ * given {@code propertyName}.
+ *
+ * @param propertyName property name to filter
+ * @param value value to match
+ * @return matching entities
+ * @throws TopiaException if any pb while getting datas
+ */
List<E> findAllByProperty(String propertyName, Object value)
throws TopiaException;
/**
+ * Gets all entities of the dao type matching the {@code value} for the
+ * given {@code propertyName} and {@code others}.
+ *
* @param propertyName le nom de la propriété
* @param value la valeur à tester
* @param others les autres proprietes doivent aller par 2
* propertyName, value
- * @return l'entité trouvé
+ * @return matching entities
* @throws TopiaException if any pb while getting datas
*/
List<E> findAllByProperties(String propertyName, Object value,
Object... others) throws TopiaException;
+ /**
+ * Gets all entities of the dao type matching all the {@code properties}.
+ *
+ * @param properties properties to match
+ * @return matching entities
+ * @throws TopiaException if any pb while getting datas
+ */
List<E> findAllByProperties(Map<String, Object> properties)
throws TopiaException;
/**
- * Execute une requête basé sur l'entité du DAO. Permet de récupérer une
- * liste d'entités correspondant à la requête.
+ * Gets all entities when executing the given select query for the dao
+ * entity type.
*
- * @param query la requête
- * @return la liste d'entités correspondant à la recherche
+ * @param hql hql query
+ * @param params query params
+ * @return entites of the query result
* @throws TopiaException if any pb while getting datas
- * @see TopiaQuery#executeToEntityList(TopiaContext, Class)
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- List<E> findAllByQuery(TopiaQuery query) throws TopiaException;
+ List<E> findAllByQuery(String hql, Object... params) throws TopiaException;
/**
- * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
- * d'entités correspondant à la requête. La clé de la map étant le topiaId
- * de l'entité.
+ * Gets all entities when executing the given select query for the given
+ * {@code type} which may not be a entity type (int, long, map,...).
*
- * @param query la requête
- * @return la map d'entités correspondant à la recherche
+ * @param hql hql query
+ * @param params query params
+ * @return entites of the query result
* @throws TopiaException if any pb while getting datas
- * @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
+ <R> List<R> findAllByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException;
/**
- * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
- * d'entités correspondant à la requête. Le type et le nom de la propriété
- * utilisé comme clé de la map doit être passé en argument.
+ * Gets a page of entities when executing the given select query for the dao
+ * entity type (will only return the window of {@code startIndex -
+ * endIndex} entities).
*
- * @param <K> type de la clé de la map
- * @param query la requête
- * @param keyName nom de la propriété de l'entité utilisée comme clé
- * @param keyClass type de la propriété de l'entité utilisée comme clé
- * @return la map d'entités correspondant à la recherche
+ * @param hql hql query to execute
+ * @param startIndex first index of entity to return
+ * @param endIndex last index of entity to return
+ * @param params query params
+ * @return entites of the paginated query result
* @throws TopiaException if any pb while getting datas
- * @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
- * @since 2.3
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- <K> Map<K, E> findAllMappedByQuery(TopiaQuery query,
- String keyName, Class<K> keyClass) throws TopiaException;
+ List<E> findAllByQueryWithBound(String hql,
+ int startIndex,
+ int endIndex,
+ Object... params) throws TopiaException;
+ /**
+ * Gets a page of entities of the given select {@code hql} query using the
+ * {@code pager} to obtain the window of entities to return.
+ *
+ * @param hql hql query to execute
+ * @param pager pager to obtan the correct window of data
+ * @param params params of the query
+ * @return entities of the paginated query result
+ * @throws TopiaException if any pb while getting datas
+ * @see TopiaFilterPagerUtil.FilterPagerBean
+ * @since 2.6.12
+ */
+ List<E> findAllByQueryAndPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException;
+
+ /**
+ * Gets all entites for the dao entity type order by given {@code propertyNames}.
+ * <p/>
+ * You can add on each {@code property} {@code ASC} ou {@code DESC} to
+ * fix order way (by default is {@code ASC}).
+ *
+ * @param propertyNames property names of order to apply
+ * @return all entities of the dao entity type with given order
+ * @throws TopiaException if any pb while getting datas
+ */
List<E> findAllWithOrder(String... propertyNames)
throws TopiaException;
@@ -372,19 +380,9 @@
List<E> findAllContains(String propertyName,
Object property) throws TopiaException;
- /**
- * Récupère la première entité (du type géré par ce dao) dont la
- * collection nommée {@code propertyName} contient la {@code property}
- * donnée.
- *
- * @param propertyName le nom de la propriété
- * @param property la propriété recherchée
- * @return la première entité recherchée
- * @throws TopiaException pour tout erreur lors de la recherche
- * @since 2.5.4
- */
- E findContains(String propertyName,
- Object property) throws TopiaException;
+ //------------------------------------------------------------------------//
+ //-- existsByXXX methods -------------------------------------------------//
+ //------------------------------------------------------------------------//
/**
* Check the existence of an entity with technical {@code id}.
@@ -411,19 +409,21 @@
boolean existByProperties(String propertyName, Object propertyValue,
Object... others) throws TopiaException;
-
/**
- * Check the existence of an entity using a {@code query}.
+ * Check the existence of an entity using a {@code hql} query.
*
- * @param query query used to test existence
+ * @param hql query used to test existence
+ * @param params params used by the query
* @return true if entity exists, false otherwise
* @throws TopiaException
- * @since 2.3.4
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- boolean existByQuery(TopiaQuery query) throws TopiaException;
+ boolean existsByQuery(String hql, Object... params) throws TopiaException;
+ //------------------------------------------------------------------------//
+ //-- countXXX methods ----------------------------------------------------//
+ //------------------------------------------------------------------------//
+
/**
* Count the number of existing entities.
*
@@ -434,70 +434,124 @@
long count() throws TopiaException;
/**
- * Count the number of entities based on {@code query}.
+ * Count the number of entities based on a {@code hql}.
*
- * @param query query
+ * @param hql hql query to use
* @return number of entities filtered by the query
* @throws TopiaException if any pb while getting datas
- * @since 2.3.4
- * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ * @since 2.6.12
*/
- @Deprecated
- int countByQuery(TopiaQuery query) throws TopiaException;
+ long countByQuery(String hql, Object... params) throws TopiaException;
+ //------------------------------------------------------------------------//
+ //-- other request methods -----------------------------------------------//
+ //------------------------------------------------------------------------//
+
/**
- * Recherche la classe en utilisant la cle naturelle, chaque champs de la
- * cle naturelle est une entre de la map passe en argument.
+ * Find usages of the given {@code entity} in the entities of the given
+ * {@code type}.
*
- * @param keys la liste des champs de la cle naturelle avec leur valeur
- * @return l'entite trouvé
- * @throws TopiaException if any pb while getting datas
+ * @param type the type of entity to search
+ * @param entity the entity on which search is done
+ * @param <R> type of entity to search
+ * @return the list of entities of the given type which uses the given
+ * entity
+ * @throws TopiaException if any problem while getting data
+ * @since 2.3.0
*/
- E findByPrimaryKey(Map<String, Object> keys) throws TopiaException;
+ <R extends TopiaEntity> List<R> findUsages(Class<R> type, E entity)
+ throws TopiaException;
/**
- * Recherche la classe en utilisant la cle naturelle, si la cle naturelle
- * est composé de plusieurs champs alors les arguments passés doivent être
- * dans l'ordre de declaration dans le fichier de mapping
+ * Find all usages of the given {@code entity}.
*
- * @param k l'objet cle naturelle de la classe
- * @return l'entité trouvé
+ * @param entity the entity
+ * @return the dictionnary of usages of the given entities (keys are entity
+ * usage container, values are the list of this type of entity to
+ * use the given entity).
+ * @throws TopiaException if any pb while getting data
+ * @since 2.3.0
+ */
+
+ Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> findAllUsages(E entity)
+ throws TopiaException;
+
+ /**
+ * Execute the count {@code hql} query and then synch the pager to this
+ * result (says fill the
+ * {@link TopiaFilterPagerUtil.FilterPagerBean#records} field and then adapt
+ * the number of pages available and the current number page).
+ *
+ * @param hql the count hql to execute
+ * @param pager the page to synch
+ * @param params params of the count query
* @throws TopiaException if any pb while getting datas
+ * @see TopiaFilterPagerUtil.FilterPagerBean
+ * @since 2.6.12
*/
- E findByPrimaryKey(Object... k) throws TopiaException;
+ void computeAndAddRecordsToPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException;
- boolean existsByQuery(String hql,
- Object... params) throws TopiaException;
+ //------------------------------------------------------------------------//
+ //-- Misc methods --------------------------------------------------------//
+ //------------------------------------------------------------------------//
- long countByQuery(String hql,
- Object... params) throws TopiaException;
+ /**
+ * Get the entityEnum of the type of entity managed by this DAO.
+ *
+ * @return entity type enum managed by this DAO
+ */
+ TopiaEntityEnum getTopiaEntityEnum();
- E findUniqueByQuery(String hql,
- Object... params) throws TopiaException;
+ /**
+ * Get the type of entity managed by this DAO.
+ *
+ * @return entity type managed by this DAO
+ */
+ Class<E> getEntityClass();
- <R> R findUniqueByQuery(Class<R> type,
- String hql,
- Object... params) throws TopiaException;
+ /**
+ * When TopiaContextImpl create the TopiaDAOHibernate, it must call this
+ * method just after.
+ *
+ * @param context context
+ * @param entityClass entity class
+ * @throws TopiaException if any pb while init
+ */
+ void init(TopiaContextImplementor context, Class<E> entityClass)
+ throws TopiaException;
- List<E> findAllByQuery(String hql,
- Object... params) throws TopiaException;
+ /**
+ * Return context used by this DAO.
+ *
+ * @return the context.
+ */
+ TopiaContextImplementor getContext();
- <R> List<R> findAllByQuery(Class<R> type,
- String hql,
- Object... params) throws TopiaException;
+ /**
+ * Retourne les permissions a verifier pour l'acces a l'entite pour le
+ * service Taas.
+ *
+ * @param topiaId topiaId d'une entite
+ * @param actions encoded actions
+ * @return la liste des permissions
+ * @throws TopiaException if any pb while getting datas
+ */
+ List<Permission> getRequestPermission(String topiaId, int actions)
+ throws TopiaException;
- List<E> findAllByQueryWithBound(String hql,
- int startIndex,
- int endIndex,
- Object... params) throws TopiaException;
+ //------------------------------------------------------------------------//
+ //-- Listener methods ----------------------------------------------------//
+ //------------------------------------------------------------------------//
- List<E> findByQueryAndPager(String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager,
- Object... params) throws TopiaException;
+ void addTopiaEntityListener(TopiaEntityListener listener);
- void computeAndAddRecordsToPager(String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager,
- Object... params) throws TopiaException;
+ void addTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+ void removeTopiaEntityListener(TopiaEntityListener listener);
+
+ void removeTopiaEntityVetoable(TopiaEntityVetoable vetoable);
+
} //TopiaDAO
Added: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java (rev 0)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -0,0 +1,155 @@
+package org.nuiton.topia.persistence;
+/*
+ * #%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%
+ */
+
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaQuery;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Contains all method that are deprecated from {@link TopiaDAO} in version
+ * {@code 2.6.12} and then will be removed in next major version ({@code 3.0}).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.6.12
+ */
+public interface TopiaDAODeprecated<E extends TopiaEntity> {
+
+ /**
+ * Crée une requete basé sur l'entité lié au DAO. Résultat attendu : "FROM
+ * E"
+ *
+ * @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
+ * type d'entité)
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ TopiaQuery createQuery();
+
+ /**
+ * Crée une requête basé sur l'entité lié au DAO et lui assigne un alias
+ * valable dans la requête..
+ * <p/>
+ * Résultat attendu : "FROM E AS entityAlias"
+ *
+ * @param entityAlias alias permettant de manipuler l'entité dans la
+ * requête
+ * @return une nouvelle TopiaQuery
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ TopiaQuery createQuery(String entityAlias);
+
+ /**
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une
+ * entité correspondant à la requête.
+ *
+ * @param query la requête
+ * @return l'entité correspondant à la recherche ou null si aucune entité
+ * n'a été trouvée
+ * @throws TopiaException if any pb while getting datas
+ * @see TopiaQuery#executeToEntity(TopiaContext, Class)
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ E findByQuery(TopiaQuery query) throws TopiaException;
+
+ /**
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une
+ * liste d'entités correspondant à la requête.
+ *
+ * @param query la requête
+ * @return la liste d'entités correspondant à la recherche
+ * @throws TopiaException if any pb while getting datas
+ * @see TopiaQuery#executeToEntityList(TopiaContext, Class)
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ List<E> findAllByQuery(TopiaQuery query) throws TopiaException;
+
+ /**
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
+ * d'entités correspondant à la requête. La clé de la map étant le topiaId
+ * de l'entité.
+ *
+ * @param query la requête
+ * @return la map d'entités correspondant à la recherche
+ * @throws TopiaException if any pb while getting datas
+ * @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
+
+ /**
+ * Execute une requête basé sur l'entité du DAO. Permet de récupérer une map
+ * d'entités correspondant à la requête. Le type et le nom de la propriété
+ * utilisé comme clé de la map doit être passé en argument.
+ *
+ * @param <K> type de la clé de la map
+ * @param query la requête
+ * @param keyName nom de la propriété de l'entité utilisée comme clé
+ * @param keyClass type de la propriété de l'entité utilisée comme clé
+ * @return la map d'entités correspondant à la recherche
+ * @throws TopiaException if any pb while getting datas
+ * @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
+ * @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ <K> Map<K, E> findAllMappedByQuery(TopiaQuery query,
+ String keyName, Class<K> keyClass) throws TopiaException;
+
+ /**
+ * Check the existence of an entity using a {@code query}.
+ *
+ * @param query query used to test existence
+ * @return true if entity exists, false otherwise
+ * @throws TopiaException
+ * @since 2.3.4
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ boolean existByQuery(TopiaQuery query) throws TopiaException;
+
+ /**
+ * Count the number of entities based on {@code query}.
+ *
+ * @param query query
+ * @return number of entities filtered by the query
+ * @throws TopiaException if any pb while getting datas
+ * @since 2.3.4
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
+ */
+ @Deprecated
+ int countByQuery(TopiaQuery query) throws TopiaException;
+}
Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAODeprecated.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -594,20 +594,20 @@
public long countByQuery(String hql,
Object... params) throws TopiaException {
- Preconditions.checkNotNull(hql);
- Preconditions.checkArgument(hql.startsWith("SELECT COUNT("));
+ Preconditions.checkNotNull(StringUtils.isNotBlank(hql));
+ Preconditions.checkArgument(hql.toUpperCase().trim().startsWith("SELECT COUNT("));
- return findUniqueByQuery(Long.class, hql, params);
+ return findByQuery(Long.class, hql, params);
}
- public E findUniqueByQuery(String hql,
- Object... params) throws TopiaException {
- return findUniqueByQuery(getEntityClass(), hql, params);
+ public E findByQuery(String hql,
+ Object... params) throws TopiaException {
+ return findByQuery(getEntityClass(), hql, params);
}
- public <R> R findUniqueByQuery(Class<R> type,
- String hql,
- Object... params) throws TopiaException {
+ public <R> R findByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException {
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(hql);
@@ -646,9 +646,9 @@
return result;
}
- public List<E> findByQueryAndPager(String hql,
- TopiaFilterPagerUtil.FilterPagerBean pager,
- Object... params) throws TopiaException {
+ public List<E> findAllByQueryAndPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException {
Preconditions.checkNotNull(pager);
Preconditions.checkNotNull(hql);
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOLegacy.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -63,14 +63,15 @@
/**
* Surcharge du {@link TopiaDAOImpl} pour utiliser l'api criteria au lieu du hql
* pour tout ce qui est requétage.
- *
+ * <p/>
* Created: 31 déc. 2005 13:10:34
*
* @param <E> le type de l'entite
* @author bpoussin <poussin(a)codelutin.com>
* @author tchemit <chemit(a)codelutin.com>
+ * @deprecated since 2.6.12 Using the hibernate Criteria api is not a good idea as we wants to use in ToPIA next generation (version 3.0) jpa api.
*/
-
+@Deprecated
public class TopiaDAOLegacy<E extends TopiaEntity> extends TopiaDAOImpl<E> { // TopiaDAOLegacy
/** Logger. */
@@ -88,20 +89,20 @@
Object propertyName = null;
Object value = null;
try {
- for (int i = 0; i < properties.length;) {
+ for (int i = 0; i < properties.length; ) {
propertyName = properties[i++];
value = properties[i++];
map.put((String) propertyName, value);
}
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException("Wrong number of argument "
- + properties.length
- + ", you must have even number. Last property name read: "
- + propertyName);
+ + properties.length
+ + ", you must have even number. Last property name read: "
+ + propertyName);
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
"Wrong argument type, wait property name as String and have "
- + propertyName.getClass().getName());
+ + propertyName.getClass().getName());
}
E result = create(map);
@@ -123,7 +124,7 @@
throw new TopiaException(eee);
}
throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
+ + " n'a pas de cle primaire naturelle");
}
@@ -150,17 +151,17 @@
throw new TopiaException(eee);
}
throw new TopiaException("La classe " + entityClass.getName()
- + " n'a pas de cle primaire naturelle");
+ + " n'a pas de cle primaire naturelle");
}
@Override
public E findByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
+ Object... others) throws TopiaException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, value);
Object name = null;
- for (int i = 0; i < others.length;) {
+ for (int i = 0; i < others.length; ) {
try {
name = others[i++];
value = others[i++];
@@ -168,12 +169,12 @@
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
"Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ + propertyName.getClass().getName(), eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2)
- + " La dernière propriété était: " + name, eee);
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
}
}
E result = findByProperties(properties);
@@ -182,11 +183,11 @@
@Override
public List<E> findAllByProperties(String propertyName, Object value,
- Object... others) throws TopiaException {
+ Object... others) throws TopiaException {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, value);
Object name = null;
- for (int i = 0; i < others.length;) {
+ for (int i = 0; i < others.length; ) {
try {
name = others[i++];
value = others[i++];
@@ -194,12 +195,12 @@
} catch (ClassCastException eee) {
throw new IllegalArgumentException(
"Les noms des propriétés doivent être des chaines et non pas "
- + propertyName.getClass().getName(), eee);
+ + propertyName.getClass().getName(), eee);
} catch (ArrayIndexOutOfBoundsException eee) {
throw new IllegalArgumentException(
"Le nombre d'argument n'est pas un nombre pair: "
- + (others.length + 2)
- + " La dernière propriété était: " + name, eee);
+ + (others.length + 2)
+ + " La dernière propriété était: " + name, eee);
}
}
List<E> result = findAllByProperties(properties);
@@ -384,7 +385,7 @@
String[] numFields = fields.numFields();
for (String propName : numFields) {
criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + "'"));
+ + " like '" + textValue + "'"));
}
}
//boolFields
@@ -403,14 +404,14 @@
String[] boolFields = fields.numFields();
for (String propName : boolFields) {
criterion = or(criterion, Restrictions.eq(propName,
- booleanValue));
+ booleanValue));
}
}
//timeFields
String[] timeFields = fields.dateFields();
for (String propName : timeFields) {
criterion = or(criterion, Restrictions.sqlRestriction(propName
- + " like '" + textValue + "'"));
+ + " like '" + textValue + "'"));
}
return criterion;
}
@@ -480,7 +481,7 @@
Criteria criteria = createCriteria(FlushMode.AUTO);
List<E> result = (List<E>) criteria.list();
result = getContext().getFiresSupport().fireEntitiesLoad(context,
- result);
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -495,7 +496,6 @@
}
-
@Override
public List<E> findAllWithOrder(String... propertyNames)
throws TopiaException {
@@ -506,7 +506,7 @@
}
List<E> result = (List<E>) criteria.list();
result = getContext().getFiresSupport().fireEntitiesLoad(context,
- result);
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -531,7 +531,7 @@
criteria.add(criterion);
List<E> result = (List<E>) criteria.list();
result = getContext().getFiresSupport().fireEntitiesLoad(context,
- result);
+ result);
return result;
} catch (HibernateException eee) {
throw new TopiaException(eee);
@@ -546,14 +546,14 @@
List<E> result = (List<E>) criteria.list();
int sizeBefore = result != null ? result.size() : 0;
result = getContext().getFiresSupport().fireEntitiesLoad(context,
- result);
+ result);
int sizeAfter = result != null ? result.size() : 0;
if (sizeAfter < sizeBefore) {
if (log.isDebugEnabled()) {
log.debug((sizeBefore - sizeAfter)
- + " element(s) removed. Filter entity: "
- + entityClass.getName() + " - criterion: "
- + criterion);
+ + " element(s) removed. Filter entity: "
+ + entityClass.getName() + " - criterion: "
+ + criterion);
}
}
if (result != null && result.size() > 0) {
@@ -612,6 +612,7 @@
/**
* Renvoie un Criteria créé avec l'entityClass
+ *
* @param mode le FlushMode du Criteria
* @return le Criteria nouvellement créé
* @throws TopiaException if any pb
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaFilterPagerUtil.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -48,6 +48,13 @@
protected TopiaFilterPagerUtil() {
}
+ /**
+ * @param query
+ * @param pager
+ * @return
+ * @deprecated since 2.6.12 TopiaQuery will be removed in version 3.0 of ToPIA
+ */
+ @Deprecated
public static TopiaQuery addPagerToQuery(TopiaQuery query,
FilterPagerBean pager) {
PagerUtil.computeRecordIndexesAndPagesNumber(pager);
Modified: branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-08-19 11:11:32 UTC (rev 2633)
+++ branches/topia-2.6.x/topia-persistence/src/test/java/org/nuiton/topia/test/ano1991/TopiaQueryTest.java 2012-08-19 11:11:48 UTC (rev 2634)
@@ -46,6 +46,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.6.8
*/
+@Deprecated
public class TopiaQueryTest {
@Rule
1
0
r2633 - branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out
by tchemit@users.nuiton.org 19 Aug '12
by tchemit@users.nuiton.org 19 Aug '12
19 Aug '12
Author: tchemit
Date: 2012-08-19 13:11:32 +0200 (Sun, 19 Aug 2012)
New Revision: 2633
Url: http://nuiton.org/repositories/revision/topia/2633
Log:
refs #2266: Add some api about import / export in csv format (improve export stuff)
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-08-18 12:11:22 UTC (rev 2632)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/out/ExportEntityVisitor.java 2012-08-19 11:11:32 UTC (rev 2633)
@@ -59,11 +59,27 @@
protected final TopiaEntityEnumProvider<T> entityEnumProvider;
- public ExportEntityVisitor(TopiaEntityEnumProvider<T> entityEnumProvider, Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters) {
+ public static <T extends TopiaEntityEnum> ExportEntityVisitor<T> newVisitor(
+ TopiaEntityEnumProvider<T> entityEnumProvider,
+ Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters) {
+ return new ExportEntityVisitor<T>(
+ entityEnumProvider,
+ entityExporters
+ );
+ }
+
+ public ExportEntityVisitor(TopiaEntityEnumProvider<T> entityEnumProvider,
+ Map<T, TopiaCsvExports.EntityExportContext<T>> entityExporters) {
this.entityEnumProvider = entityEnumProvider;
this.entityExporters = entityExporters;
}
+ public <E extends TopiaEntity> void export(Iterable<E> entities) {
+ for (E entity : entities) {
+ export(entity);
+ }
+ }
+
public void export(TopiaEntity entity) {
Preconditions.checkNotNull(entity);
long s1 = TimeLog.getTime();
1
0
r2632 - in branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia: framework persistence
by tchemit@users.nuiton.org 18 Aug '12
by tchemit@users.nuiton.org 18 Aug '12
18 Aug '12
Author: tchemit
Date: 2012-08-18 14:11:22 +0200 (Sat, 18 Aug 2012)
New Revision: 2632
Url: http://nuiton.org/repositories/revision/topia/2632
Log:
refs #2271: Deprecate TopiaQuery
refs #2272: Add new methods to TopiaDAO to help hql query
Modified:
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-18 10:37:13 UTC (rev 2631)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/framework/TopiaQuery.java 2012-08-18 12:11:22 UTC (rev 2632)
@@ -226,10 +226,12 @@
* @author fdesbois
* @version $Revision$
* @since 2.3.0
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
* <p/>
* Mise a jour: $Date$ par
* : $Author$
*/
+@Deprecated
public class TopiaQuery {
private static final Log log = LogFactory.getLog(TopiaQuery.class);
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-18 10:37:13 UTC (rev 2631)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAO.java 2012-08-18 12:11:22 UTC (rev 2632)
@@ -42,9 +42,7 @@
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.generator.DAOAbstractTransformer;
-import org.nuiton.topia.generator.DAOImplTransformer;
-import org.nuiton.topia.generator.DAOTransformer;
+import org.nuiton.topia.generator.EntityDAOTransformer;
import java.security.Permission;
import java.util.List;
@@ -56,9 +54,7 @@
* TopiaQuery}.
* <p/>
* This interface is implemented by {@link TopiaDAOImpl} overridden by generation
- * from {@link DAOTransformer} for specific entity interface, {@link
- * DAOAbstractTransformer} for abstract implementation and {@link
- * DAOImplTransformer} for final implementation class.
+ * from {@link EntityDAOTransformer}.
* <p/>
*
* @param <E> the entity type linked with the dao
@@ -223,7 +219,9 @@
* @return une nouvelle TopiaQuery vide. (uniquement avec le From sur le
* type d'entité)
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
TopiaQuery createQuery();
/**
@@ -236,7 +234,9 @@
* requête
* @return une nouvelle TopiaQuery
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
TopiaQuery createQuery(String entityAlias);
/**
@@ -275,7 +275,9 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntity(TopiaContext, Class)
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
E findByQuery(TopiaQuery query) throws TopiaException;
List<E> findAll() throws TopiaException;
@@ -314,7 +316,9 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityList(TopiaContext, Class)
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
List<E> findAllByQuery(TopiaQuery query) throws TopiaException;
/**
@@ -327,7 +331,9 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
Map<String, E> findAllMappedByQuery(TopiaQuery query) throws TopiaException;
/**
@@ -343,7 +349,9 @@
* @throws TopiaException if any pb while getting datas
* @see TopiaQuery#executeToEntityMap(TopiaContext, Class)
* @since 2.3
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
<K> Map<K, E> findAllMappedByQuery(TopiaQuery query,
String keyName, Class<K> keyClass) throws TopiaException;
@@ -411,7 +419,9 @@
* @return true if entity exists, false otherwise
* @throws TopiaException
* @since 2.3.4
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
boolean existByQuery(TopiaQuery query) throws TopiaException;
/**
@@ -430,7 +440,9 @@
* @return number of entities filtered by the query
* @throws TopiaException if any pb while getting datas
* @since 2.3.4
+ * @deprecated since 2.6.12, {@link TopiaQuery} will be removed in version 3.0
*/
+ @Deprecated
int countByQuery(TopiaQuery query) throws TopiaException;
/**
@@ -454,5 +466,38 @@
*/
E findByPrimaryKey(Object... k) throws TopiaException;
+ boolean existsByQuery(String hql,
+ Object... params) throws TopiaException;
+
+ long countByQuery(String hql,
+ Object... params) throws TopiaException;
+
+ E findUniqueByQuery(String hql,
+ Object... params) throws TopiaException;
+
+ <R> R findUniqueByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException;
+
+ List<E> findAllByQuery(String hql,
+ Object... params) throws TopiaException;
+
+ <R> List<R> findAllByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException;
+
+ List<E> findAllByQueryWithBound(String hql,
+ int startIndex,
+ int endIndex,
+ Object... params) throws TopiaException;
+
+ List<E> findByQueryAndPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException;
+
+ void computeAndAddRecordsToPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException;
+
} //TopiaDAO
Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java
===================================================================
--- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-18 10:37:13 UTC (rev 2631)
+++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaDAOImpl.java 2012-08-18 12:11:22 UTC (rev 2632)
@@ -37,7 +37,9 @@
package org.nuiton.topia.persistence;
+import com.google.common.base.Preconditions;
import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
@@ -48,6 +50,7 @@
import org.nuiton.topia.event.TopiaEntityVetoable;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.util.PagerUtil;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
@@ -237,7 +240,7 @@
Object propertyName = null;
Object value;
try {
- for (int i = 0; i < properties.length;) {
+ for (int i = 0; i < properties.length; ) {
propertyName = properties[i++];
value = properties[i++];
map.put((String) propertyName, value);
@@ -517,7 +520,7 @@
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(propertyName, propertyValue);
Object name = null;
- for (int i = 0; i < others.length;) {
+ for (int i = 0; i < others.length; ) {
try {
name = others[i++];
propertyValue = others[i++];
@@ -580,9 +583,98 @@
}
throw new TopiaException("La classe " + entityClass.getName()
+ " n'a pas de cle primaire naturelle");
+ }
+ public boolean existsByQuery(String hql,
+ Object... params) throws TopiaException {
+ long count = countByQuery(hql, params);
+ return count > 0;
}
+ public long countByQuery(String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(hql);
+ Preconditions.checkArgument(hql.startsWith("SELECT COUNT("));
+
+ return findUniqueByQuery(Long.class, hql, params);
+ }
+
+ public E findUniqueByQuery(String hql,
+ Object... params) throws TopiaException {
+ return findUniqueByQuery(getEntityClass(), hql, params);
+ }
+
+ public <R> R findUniqueByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(hql);
+
+ Object unique = getContext().findUnique(hql, params);
+ Preconditions.checkState(unique == null ||
+ type.isAssignableFrom(unique.getClass()));
+ return (R) unique;
+ }
+
+ public List<E> findAllByQuery(String hql,
+ Object... params) throws TopiaException {
+
+ return findAllByQuery(getEntityClass(), hql, params);
+ }
+
+ public <R> List<R> findAllByQuery(Class<R> type,
+ String hql,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(type);
+ Preconditions.checkNotNull(hql);
+
+ List<R> result = getContext().findAll(hql, params);
+ return result;
+ }
+
+ public List<E> findAllByQueryWithBound(String hql,
+ int startIndex,
+ int endIndex,
+ Object... params) throws TopiaException {
+
+ Preconditions.checkNotNull(hql);
+
+ List<E> result = getContext().find(hql, startIndex, endIndex, params);
+ return result;
+ }
+
+ public List<E> findByQueryAndPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException {
+ Preconditions.checkNotNull(pager);
+ Preconditions.checkNotNull(hql);
+
+ if (StringUtils.isNotBlank(pager.getSortColumn())) {
+ hql += " ORDER BY " + pager.getSortColumn();
+ if (!pager.isSortAscendant()) {
+ hql += " DESC";
+ }
+ }
+ List<E> result = findAllByQueryWithBound(hql,
+ pager.getRecordStartIndex(),
+ pager.getRecordEndIndex() - 1,
+ params);
+ return result;
+ }
+
+ public void computeAndAddRecordsToPager(String hql,
+ TopiaFilterPagerUtil.FilterPagerBean pager,
+ Object... params) throws TopiaException {
+
+ long records = countByQuery(hql, params);
+
+ pager.setRecords((int) records);
+ PagerUtil.computeRecordIndexesAndPagesNumber(pager);
+ }
+
/**
* Renvoie la Session contenue dans le contexte
*
@@ -609,5 +701,5 @@
}
return meta;
}
-
+
} //TopiaDAOImpl
1
0