Author: glandais Date: 2008-02-22 16:49:23 +0000 (Fri, 22 Feb 2008) New Revision: 1197 Removed: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/KeyValue.java Modified: trunk/simexplorer-is/simexplorer-is-storage/pom.xml trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties Log: Matching entities update Modified: trunk/simexplorer-is/simexplorer-is-storage/pom.xml =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/pom.xml 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/pom.xml 2008-02-22 16:49:23 UTC (rev 1197) @@ -44,6 +44,11 @@ <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.2.2</version> + </dependency> + <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>2.3.0</version> Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -21,9 +21,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Random; import java.util.UUID; @@ -36,6 +34,7 @@ import fr.cemagref.simexplorer.is.entities.data.Constant; import fr.cemagref.simexplorer.is.entities.data.ConstantValue; import fr.cemagref.simexplorer.is.entities.data.DataEntity; +import fr.cemagref.simexplorer.is.entities.data.Descriptor; import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.entities.data.ExplorationData; import fr.cemagref.simexplorer.is.entities.data.Library; @@ -168,15 +167,14 @@ private void update(LoggableElement element) throws Exception { MetaData metaData = new MetaData(); metaData.setUuid(UUID.randomUUID().toString()); - metaData.setType(element.getClass().getSimpleName()); - metaData.setName(metaData.getType() + "-" + counter++); + element.setName(element.getClass().getSimpleName() + "-" + counter++); StringBuffer sb = new StringBuffer(""); for (int i = 0, max = 3 + r.nextInt(5); i < max; i++) { sb.append(randomstrings[r.nextInt(cs)]).append(" "); } - metaData.setDescription(sb.toString()); + element.setDescription(sb.toString()); Version v = new Version("0"); @@ -188,16 +186,16 @@ metaData.setHash(shortString()); metaData.setLatest(true); - Map<String, String> descriptors = new HashMap<String, String>(); + List<Descriptor> descriptors = new ArrayList<Descriptor>(); for (int i = 0, max = 1 + r.nextInt(12); i < max; i++) { - descriptors.put(Integer.toString(i), shortString()); + descriptors.add(new Descriptor(shortString(), shortString())); } - metaData.setDescriptors(descriptors); + element.setDescriptors(descriptors); if (element instanceof Library || element instanceof ExplorationData) { // generate attachments for (int i = 0, max = r.nextInt(15); i < max; i++) { - metaData.getAttachments().add(generateAttachment()); + element.getAttachments().add(generateAttachment()); } } @@ -219,7 +217,7 @@ List<T> elements = new ArrayList<T>(); int i = 3 + r.nextInt(2); for (int j = 0; j < i; j++) { - T element = BaseEntityFactory.<T> getFactory(clazz).createInstance(); + T element = clazz.newInstance(); if (element instanceof LoggableElement) { update((LoggableElement) element); } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -17,16 +17,14 @@ * ##% */ package fr.cemagref.simexplorer.is.storage; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.entities.metadata.Version; - -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.metadata.Version; + /** * The Class MetaDataGenerator. */ @@ -57,8 +55,8 @@ MetaData me = generateMetaDataEntity(uuid, version); if (parentVersion != null) { - me.setParentVersionUuid(parentVersion.getUuid()); - me.setParentVersionVersion(parentVersion.getVersion().toString()); + me.setParentUuid(parentVersion.getUuid()); + me.setParentVersion(parentVersion.getVersion()); parentVersion.setLatest(false); } me.setLatest(true); @@ -79,7 +77,7 @@ me.setUuid(uuid); me.setName(uuid); - me.setType("LuceneDatabaseTestCase"); + me.setElementClass(MetaData.class); me.setDescription(uuid + " " + version.toString()); me.setVersion(version.toString()); me.setLatest(true); @@ -92,10 +90,8 @@ for (int j = 0; j < i; j++) { descriptors.put("descriptor" + j, UUID.randomUUID().toString()); } - me.setDescriptors(descriptors); - me.setAttachments(new ArrayList<Attachment>()); - me.setParentVersionUuid(null); - me.setParentVersionVersion(null); + me.setParentUuid(null); + me.setParentVersion((Version) null); return me; } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -17,14 +17,14 @@ * ##% */ package fr.cemagref.simexplorer.is.storage; -import fr.cemagref.simexplorer.is.entities.metadata.Version; - -import java.util.Random; -import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.Random; +import fr.cemagref.simexplorer.is.entities.metadata.Version; + /** * A Version generator. * Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/attachment/AttachmentHandler.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -33,15 +33,11 @@ /** * Store content. * - * @param entity - * DataEntity related to content - * @param is - * Content - * @param attachment - * the attachment + * @param entity DataEntity related to content + * @param is Content + * @param attachment the attachment * - * @throws SimExplorerException - * the sim explorer storage exception + * @throws SimExplorerException the sim explorer storage exception */ public abstract void storeData(MetaData entity, Attachment attachment, InputStream is) throws SimExplorerException; @@ -49,47 +45,35 @@ /** * Retrieve content. * - * @param entity - * DataEntity related to content - * @param attachment - * the attachment + * @param entity DataEntity related to content + * @param attachment the attachment * * @return Content * - * @throws SimExplorerException - * the sim explorer storage exception + * @throws SimExplorerException the sim explorer storage exception */ - public abstract InputStream retrieveData(MetaData entity, Attachment attachment) - throws SimExplorerException; + public abstract InputStream retrieveData(MetaData entity, Attachment attachment) throws SimExplorerException; /** * Retrieve MD5. * - * @param entity - * the entity - * @param attachment - * the attachment + * @param entity the entity + * @param attachment the attachment * * @return the string * - * @throws SimExplorerException - * the sim explorer storage exception + * @throws SimExplorerException the sim explorer storage exception */ - public abstract String retrieveMD5Data(MetaData entity, Attachment attachment) - throws SimExplorerException; + public abstract String retrieveMD5Data(MetaData entity, Attachment attachment) throws SimExplorerException; /** * Delete content. * - * @param entity - * DataEntity related to content - * @param attachment - * the attachment + * @param entity DataEntity related to content + * @param attachment the attachment * - * @throws SimExplorerException - * the sim explorer storage exception + * @throws SimExplorerException the sim explorer storage exception */ - public abstract void deleteData(MetaData entity, Attachment attachment) - throws SimExplorerException; + public abstract void deleteData(MetaData entity, Attachment attachment) throws SimExplorerException; } \ No newline at end of file Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -21,11 +21,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; +import fr.cemagref.simexplorer.is.storage.SortColumn; +import fr.cemagref.simexplorer.is.storage.SortOrder; /** * Interface of a database able to manage metadata elements. @@ -93,10 +94,12 @@ * * @param fromElement the from element * @param toElement the to element + * * @throws SimExplorerException TODO */ - public abstract void duplicateElementHierarchy(MetaData fromElement, MetaData toElement) throws SimExplorerException; - + public abstract void duplicateElementHierarchy(MetaData fromElement, MetaData toElement) + throws SimExplorerException; + // Read /** @@ -129,6 +132,7 @@ * @param mde the mde * * @return the elements used by + * * @throws SimExplorerException TODO */ public abstract List<MetaData> getElementsUsedBy(MetaData mde) throws SimExplorerException; @@ -139,6 +143,7 @@ * @param mde the mde * * @return the elements using + * * @throws SimExplorerException TODO */ public abstract List<MetaData> getElementsUsing(MetaData mde) throws SimExplorerException; @@ -166,7 +171,7 @@ * @throws SimExplorerException the sim explorer storage exception */ public List<MetaData> findElementsByProperties(Map<String, String> properties) throws SimExplorerException { - return findElementsByProperties(properties, 0, -1, 0); + return findElementsByProperties(properties, 0, -1, SortColumn.None, SortOrder.Ascending); } /** @@ -176,14 +181,15 @@ * @param properties Matching properties needed * @param start Index of first element returned * @param count Number of elements to return - * @param dateOrder the date order + * @param sortOrder the order + * @param column the column * * @return Element list * * @throws SimExplorerException the sim explorer storage exception */ public abstract List<MetaData> findElementsByProperties(Map<String, String> properties, int start, int count, - int dateOrder) throws SimExplorerException; + SortColumn column, SortOrder sortOrder) throws SimExplorerException; /** * Retrieve element count specific properties. @@ -194,20 +200,19 @@ * * @throws SimExplorerException the sim explorer storage exception */ - public abstract int findElementsByPropertiesCount(Map<String, String> properties) - throws SimExplorerException; + public abstract int findElementsByPropertiesCount(Map<String, String> properties) throws SimExplorerException; /** * Prepare properties for query. * - * @param type Type of entity wanted * @param onlyLatest Only wanted elements + * @param className the class name * * @return Properties for query */ - private Map<String, String> getPropertiesByType(String type, boolean onlyLatest) { + private Map<String, String> getPropertiesByType(String className, boolean onlyLatest) { Map<String, String> properties = new HashMap<String, String>(); - properties.put(KEY_TYPE, type); + properties.put(KEY_CLASSNAME, className); if (onlyLatest) { properties.put(KEY_LATEST, "1"); } @@ -221,15 +226,16 @@ * @param onlyLatest Only latest elements * @param start Start index * @param count Number of documents - * @param dateOrder Sorting + * @param column the column + * @param sortOrder the sort order * * @return Element list * * @throws SimExplorerException the sim explorer storage exception */ - public List<MetaData> findElementsByType(String type, boolean onlyLatest, int start, int count, int dateOrder) - throws SimExplorerException { - return findElementsByProperties(getPropertiesByType(type, onlyLatest), start, count, dateOrder); + public List<MetaData> findElementsByType(String type, boolean onlyLatest, int start, int count, SortColumn column, + SortOrder sortOrder) throws SimExplorerException { + return findElementsByProperties(getPropertiesByType(type, onlyLatest), start, count, column, sortOrder); } /** @@ -254,14 +260,15 @@ * @param onlyLatest the only latest * @param start Index of first element returned * @param count Number of elements to return - * @param dateOrder the date order + * @param column the column + * @param sortOrder the sort order * * @return Element list * * @throws SimExplorerException the sim explorer storage exception */ public abstract List<MetaData> findElementsByContentSearch(String queryText, boolean onlyLatest, int start, - int count, int dateOrder) throws SimExplorerException; + int count, SortColumn column, SortOrder sortOrder) throws SimExplorerException; /** * Retrieve element count with specific content. @@ -299,5 +306,4 @@ */ public abstract void deleteElement(String uuid, Version version) throws SimExplorerException; - } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -42,9 +42,6 @@ /** Field name for name. */ public static final String KEY_NAME = "simexplorer.name"; - /** Field name for type. */ - public static final String KEY_TYPE = "simexplorer.type"; - /** Field name for description. */ public static final String KEY_DESCRIPTION = "simexplorer.description"; @@ -54,57 +51,30 @@ /** Field name for latest. */ public static final String KEY_LATEST = "simexplorer.latest"; + /** Field name for latest. */ + public static final String KEY_CLASSNAME = "simexplorer.classname"; + /** Field name for creation date. */ public static final String KEY_CREATIONDATE = "simexplorer.creationdate"; /** Field name for hash. */ public static final String KEY_HASH = "simexplorer.hash"; - /** Field name for descriptor. */ - public static final String KEY_DESCRIPTOR = "simexplorer.descriptor"; - - /** Field name for descriptor. */ - public static final String KEY_DESCRIPTOR_KEY = "key"; - - /** Field name for descriptor. */ - public static final String KEY_DESCRIPTOR_VALUE = "value"; - - /** Field name for attachment. */ - public static final String KEY_ATTACHMENT = "simexplorer.attachment"; - - /** Field name for attachment. */ - public static final String KEY_ATTACHMENT_FILENAME = "filename"; - - /** Field name for attachment. */ - public static final String KEY_ATTACHMENT_HASH = "hash"; - - /** Field name for attachment. */ - public static final String KEY_ATTACHMENT_TYPE = "type"; - - /** Field name for id of parent data. */ - public static final String KEY_PARENTDATA_UUID = "simexplorer.parentdata.uuid"; - - /** Field name for version of parent data. */ - public static final String KEY_PARENTDATA_VERSION = "simexplorer.parentdata.version"; - /** Field name for id of parent version. */ - public static final String KEY_PARENTVERSION_UUID = "simexplorer.parentversion.uuid"; + public static final String KEY_PARENT_UUID = "simexplorer.parent.uuid"; /** Field name for version of parent version. */ - public static final String KEY_PARENTVERSION_VERSION = "simexplorer.parentversion.version"; + public static final String KEY_PARENT_VERSION = "simexplorer.parent.version"; /** Field name for searchable content. */ public static final String KEY_SEARCHABLE_CONTENT = "simexplorer.searchablecontent"; - /** Field name for sorting. */ - public static final String SORT_DATE_FIELD = KEY_CREATIONDATE; - /** No date sort. */ - public static final int SORT_DATE_NONE = 0; + public static final int SORT_NONE = 0; /** Sort element by date (ascending). */ - public static final int SORT_DATE_ASCENDING = 1; + public static final int SORT_ASCENDING = 1; /** Sort element by date (descending). */ - public static final int SORT_DATE_DESCENDING = -1; + public static final int SORT_DESCENDING = -1; } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.StringTokenizer; import java.util.Properties; import java.util.Map.Entry; @@ -35,7 +34,6 @@ import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; -import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; @@ -55,15 +53,14 @@ import org.apache.lucene.store.LockFactory; import org.apache.lucene.store.NoLockFactory; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; -import fr.cemagref.simexplorer.is.factories.ContentTypeFactory; +import fr.cemagref.simexplorer.is.storage.SortColumn; +import fr.cemagref.simexplorer.is.storage.SortOrder; import fr.cemagref.simexplorer.is.storage.database.Database; import fr.cemagref.simexplorer.is.storage.util.Config; -import fr.cemagref.simexplorer.is.storage.util.KeyValue; /** * Lucene implementation. @@ -114,7 +111,7 @@ @Override public String toString() { - return super.toString()+"<dbFolder:"+dbFolder+", optimizePeriod:"+optimizePeriod+">"; + return super.toString() + "<dbFolder:" + dbFolder + ", optimizePeriod:" + optimizePeriod + ">"; } /** @@ -353,7 +350,7 @@ // Search elements Hits hits; - hits = findHits(properties, searcher, SORT_DATE_NONE); + hits = findHits(properties, searcher, SortColumn.None, SortOrder.Ascending); return hits; } @@ -372,7 +369,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + Hits hits = findHits(properties, searcher, SortColumn.None, SortOrder.Ascending); // Add all versions to a list versions = new ArrayList<Version>(); @@ -411,7 +408,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + Hits hits = findHits(properties, searcher, SortColumn.None, SortOrder.Ascending); result = convertHitsToElements(hits, 0, -1); } finally { // Release searcher instance @@ -438,7 +435,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher, SORT_DATE_NONE); + Hits hits = findHits(properties, searcher, SortColumn.None, SortOrder.Ascending); result = hits.length(); } finally { // Release searcher instance @@ -456,15 +453,15 @@ * @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsByProperties(java.util.Map, int, int, int) */ @Override - public List<MetaData> findElementsByProperties(Map<String, String> properties, int start, int count, int dateOrder) - throws SimExplorerException { + public List<MetaData> findElementsByProperties(Map<String, String> properties, int start, int count, + SortColumn column, SortOrder sortOrder) throws SimExplorerException { List<MetaData> result = null; try { // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher, dateOrder); + Hits hits = findHits(properties, searcher, column, sortOrder); result = convertHitsToElements(hits, start, count); } finally { // Release searcher instance @@ -516,21 +513,22 @@ /** * Retrieve a Lucene Sort for date sorting. * - * @param dateOrder sort wanted SORT_DATE_NONE, SORT_DATE_DESCENDING, SORT_DATE_ASCENDING, + * @param column the column + * @param sortOrder the sort order * * @return null if no sort */ - private Sort getSortDate(int dateOrder) { + private Sort getSortDate(SortColumn column, SortOrder sortOrder) { Sort sort; - if (dateOrder != SORT_DATE_NONE) { + if (column != SortColumn.None) { SortField[] fields = new SortField[3]; fields[1] = SortField.FIELD_SCORE; fields[2] = SortField.FIELD_DOC; - if (dateOrder == SORT_DATE_DESCENDING) { - fields[0] = new SortField(SORT_DATE_FIELD, SortField.LONG, true); + if (sortOrder == SortOrder.Ascending) { + fields[0] = new SortField(column.getColumn(), column.getType(), true); } else { - fields[0] = new SortField(SORT_DATE_FIELD, SortField.LONG, false); + fields[0] = new SortField(column.getColumn(), column.getType(), false); } sort = new Sort(fields); } else { @@ -544,7 +542,7 @@ */ @Override public List<MetaData> findElementsByContentSearch(String queryText, boolean onlyLatest, int start, int count, - int dateOrder) throws SimExplorerException { + SortColumn column, SortOrder sortOrder) throws SimExplorerException { Query query; try { query = getQueryByContentSearch(queryText, onlyLatest); @@ -559,7 +557,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - hits = searcher.search(query, getSortDate(dateOrder)); + hits = searcher.search(query, getSortDate(column, sortOrder)); // Convert hits to elements result = convertHitsToElements(hits, start, count); } finally { @@ -631,13 +629,15 @@ * * @param properties criteria * @param searcher the searcher - * @param dateOrder the date order + * @param column the column + * @param sortOrder the sort order * * @return Documents and search handle * * @throws IOException Signals that an I/O exception has occurred. */ - private Hits findHits(Map<String, String> properties, Searcher searcher, int dateOrder) throws IOException { + private Hits findHits(Map<String, String> properties, Searcher searcher, SortColumn column, SortOrder sortOrder) + throws IOException { // Create a query with all parameters BooleanQuery query = new BooleanQuery(); for (Entry<String, String> kv : properties.entrySet()) { @@ -645,7 +645,7 @@ } Hits hits; - hits = searcher.search(query, getSortDate(dateOrder)); + hits = searcher.search(query, getSortDate(column, sortOrder)); return hits; } @@ -696,7 +696,11 @@ element.setUuid(document.get(KEY_UUID)); element.setName(document.get(KEY_NAME)); - element.setType(document.get(KEY_TYPE)); + try { + element.setElementClass(Class.forName(document.get(KEY_CLASSNAME))); + } catch (ClassNotFoundException e) { + throw new SimExplorerTechnicalException(e); + } element.setDescription(document.get(KEY_DESCRIPTION)); element.setVersion(document.get(KEY_VERSION)); if ("1".equals(document.get(KEY_LATEST))) { @@ -712,75 +716,9 @@ } element.setHash(document.get(KEY_HASH)); - Map<Integer, KeyValue> descriptors = new HashMap<Integer, KeyValue>(); - Map<Integer, Attachment> attachments = new HashMap<Integer, Attachment>(); + element.setParentUuid(document.get(KEY_PARENT_UUID)); + element.setParentVersion(document.get(KEY_PARENT_VERSION)); - List<Fieldable> fields = document.getFields(); - for (Fieldable fieldable : fields) { - - if (fieldable.name().startsWith(KEY_DESCRIPTOR)) { - String fieldValue = fieldable.stringValue(); - - String key = fieldable.name().replace(KEY_DESCRIPTOR + DOT, ""); - StringTokenizer st = new StringTokenizer(key, DOT); - Integer iDescriptor = Integer.valueOf(st.nextToken()); - - KeyValue kv = descriptors.get(iDescriptor); - if (kv == null) { - kv = new KeyValue(); - descriptors.put(iDescriptor, kv); - } - - if (st.nextToken().equals(KEY_DESCRIPTOR_KEY)) { - kv.setKey(fieldValue); - } else { - kv.setValue(fieldValue); - } - } - - if (fieldable.name().startsWith(KEY_ATTACHMENT)) { - - String fieldValue = fieldable.stringValue(); - - String key = fieldable.name().replace(KEY_ATTACHMENT + DOT, ""); - StringTokenizer st = new StringTokenizer(key, DOT); - Integer iAttachment = Integer.valueOf(st.nextToken()); - - Attachment attachment = attachments.get(iAttachment); - if (attachment == null) { - attachment = new Attachment(); - attachments.put(iAttachment, attachment); - } - - String field = st.nextToken(); - - if (field.equals(KEY_ATTACHMENT_FILENAME)) { - attachment.setFileName(fieldValue); - } - if (field.equals(KEY_ATTACHMENT_HASH)) { - attachment.setDataHash(fieldValue); - } - if (field.equals(KEY_ATTACHMENT_TYPE)) { - attachment.setContentType(ContentTypeFactory.getContentTypeInstance(fieldValue)); - } - } - } - - Map<String, String> finalDescriptors = new HashMap<String, String>(); - for (Map.Entry<Integer, KeyValue> entry : descriptors.entrySet()) { - finalDescriptors.put(entry.getValue().getKey(), entry.getValue().getValue()); - } - element.setDescriptors(finalDescriptors); - - List<Attachment> finalAttachments = new ArrayList<Attachment>(); - for (Map.Entry<Integer, Attachment> entry : attachments.entrySet()) { - finalAttachments.add(entry.getValue()); - } - element.setAttachments(finalAttachments); - - element.setParentVersionUuid(document.get(KEY_PARENTVERSION_UUID)); - element.setParentVersionVersion(document.get(KEY_PARENTVERSION_VERSION)); - return element; } @@ -849,7 +787,7 @@ addSimpleField(document, KEY_UUID_VERSION, getUuidVersion(element.getUuid(), element.getVersion())); addSimpleField(document, KEY_NAME, element.getName()); - addSimpleField(document, KEY_TYPE, element.getType()); + addSimpleField(document, KEY_CLASSNAME, element.getElementClass().getCanonicalName()); addSimpleField(document, KEY_DESCRIPTION, element.getDescription()); if (element.isLatest()) { addSimpleField(document, KEY_LATEST, "1"); @@ -862,29 +800,11 @@ } addSimpleField(document, KEY_HASH, element.getHash()); - Map<String, String> descriptors = element.getDescriptors(); - int i = 0; - for (Map.Entry<String, String> entry : descriptors.entrySet()) { - String key = KEY_DESCRIPTOR + DOT + i; - addSimpleField(document, key + DOT + KEY_DESCRIPTOR_KEY, entry.getKey()); - addSimpleField(document, key + DOT + KEY_DESCRIPTOR_VALUE, entry.getValue()); - i++; + addSimpleField(document, KEY_PARENT_UUID, element.getParentUuid()); + if (element.getParentVersion() != null) { + addSimpleField(document, KEY_PARENT_VERSION, element.getParentVersion().toString()); } - List<Attachment> attachments = element.getAttachments(); - i = 0; - for (Attachment attachment : attachments) { - String key = KEY_ATTACHMENT + DOT + i; - addSimpleField(document, key + DOT + KEY_ATTACHMENT_FILENAME, attachment.getFileName()); - addSimpleField(document, key + DOT + KEY_ATTACHMENT_HASH, attachment.getDataHash()); - addSimpleField(document, key + DOT + KEY_ATTACHMENT_TYPE, attachment.getContentType().getClass() - .getSimpleName()); - i++; - } - - addSimpleField(document, KEY_PARENTVERSION_UUID, element.getParentVersionUuid()); - addSimpleField(document, KEY_PARENTVERSION_VERSION, element.getParentVersionVersion()); - for (Reader reader : readers) { document.add(new Field(KEY_SEARCHABLE_CONTENT, reader)); } Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -20,7 +20,6 @@ import java.io.InputStream; import java.util.List; import java.util.Map; -import java.util.Set; import javax.ejb.Local; @@ -28,6 +27,8 @@ import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; +import fr.cemagref.simexplorer.is.storage.SortColumn; +import fr.cemagref.simexplorer.is.storage.SortOrder; /** * The Interface StorageEngine. @@ -86,6 +87,7 @@ * @param token the token * @param fromElement the from element * @param toElement the to element + * * @throws SimExplorerException if any problem while operation */ public abstract void duplicateElementHierarchy(String token, MetaData fromElement, MetaData toElement) @@ -239,15 +241,16 @@ * @param onlyLatest the only latest * @param indexStart the index start * @param count the count - * @param dateOrder the date order * @param token the token + * @param column the column + * @param sortOrder the sort order * * @return the meta data[] * * @throws SimExplorerException the sim explorer storage exception */ public abstract MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, - int dateOrder) throws SimExplorerException; + SortColumn column, SortOrder sortOrder) throws SimExplorerException; /** * Retrieve list of items of type wanted. @@ -256,15 +259,16 @@ * @param onlyLatest the only latest * @param start the start * @param count the count - * @param dateOrder the date order * @param token the token + * @param column the column + * @param sortOrder the sort order * * @return the meta data[] * * @throws SimExplorerException the sim explorer storage exception */ public abstract MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, - int dateOrder) throws SimExplorerException; + SortColumn column, SortOrder sortOrder) throws SimExplorerException; /** * Retrieve number of items of type wanted. Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -17,30 +17,32 @@ * ##% */ package fr.cemagref.simexplorer.is.storage.engine; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + import fr.cemagref.simexplorer.is.entities.attachment.Attachment; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; import fr.cemagref.simexplorer.is.exceptions.SimExplorerTechnicalException; +import fr.cemagref.simexplorer.is.storage.SortColumn; +import fr.cemagref.simexplorer.is.storage.SortOrder; import fr.cemagref.simexplorer.is.storage.attachment.AttachmentHandler; import fr.cemagref.simexplorer.is.storage.attachment.FileSystemAttachmentHandler; import fr.cemagref.simexplorer.is.storage.database.Database; import fr.cemagref.simexplorer.is.storage.database.lucene.LuceneDatabase; import fr.cemagref.simexplorer.is.storage.util.Config; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - /** * Handle data storage and indexing. - * + * * @author landais */ public class StorageEngineImpl implements StorageEngine { @@ -63,12 +65,10 @@ } /** - * constructor with specified configuration - * <p/> - * default implementations of storage and indexing. - * + * constructor with specified configuration <p/> default implementations of storage and indexing. + * * @param configFile location of config file - * @param prefixKey prefix key to suppress on properties key + * @param prefixKey prefix key to suppress on properties key */ public StorageEngineImpl(String configFile, String prefixKey) { super(); @@ -149,12 +149,10 @@ Reader reader = new StringReader(element.getDescription()); readers.add(reader); } - Map<String, String> descriptors = element.getDescriptors(); - for (Map.Entry<String, String> descriptor : descriptors.entrySet()) { - readers.add(new StringReader(descriptor.getValue())); - } + // FIXME descriptors // Insert element in database + // FIXME separate search database.insertElement(element, readers); } @@ -278,8 +276,9 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullText(java.lang.String, boolean, int, int, int) */ public MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, - int dateOrder) throws SimExplorerException { - List<MetaData> elements = database.findElementsByContentSearch(query, onlyLatest, indexStart, count, dateOrder); + SortColumn column, SortOrder sortOrder) throws SimExplorerException { + List<MetaData> elements = database.findElementsByContentSearch(query, onlyLatest, indexStart, count, column, + sortOrder); MetaData[] result; result = elements.toArray(new MetaData[elements.size()]); return result; @@ -289,8 +288,8 @@ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByType(java.lang.String, boolean, int, int, int) */ public MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count, - int dateOrder) throws SimExplorerException { - List<MetaData> elements = database.findElementsByType(type, onlyLatest, start, count, dateOrder); + SortColumn column, SortOrder sortOrder) throws SimExplorerException { + List<MetaData> elements = database.findElementsByType(type, onlyLatest, start, count, column, sortOrder); MetaData[] result; result = elements.toArray(new MetaData[elements.size()]); return result; @@ -320,10 +319,11 @@ */ public void deleteElement(String token, String uuid, Version version) throws SimExplorerException { MetaData element = getMetadata(token, uuid, version); - List<Attachment> attachments = element.getAttachments(); - for (Attachment attachment : attachments) { - attachmentHandler.deleteData(element, attachment); - } + // FIXME delete attachments + // List<Attachment> attachments = element.getAttachments(); + // for (Attachment attachment : attachments) { + // attachmentHandler.deleteData(element, attachment); + // } database.deleteElement(element); } @@ -331,7 +331,7 @@ /** * Gets the tmp attachment. - * + * * @param id the id * @return the tmp attachment */ Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/Config.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -17,9 +17,6 @@ * ##% */ package fr.cemagref.simexplorer.is.storage.util; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -31,6 +28,9 @@ import java.util.Map; import java.util.Properties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** The Class Config. */ public class Config { Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/KeyValue.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/KeyValue.java 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/util/KeyValue.java 2008-02-22 16:49:23 UTC (rev 1197) @@ -1,90 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* 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 Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.storage.util; - -/** - * The Class KeyValue. - */ -public class KeyValue { - - /** The key. */ - private String key; - - /** The value. */ - private String value; - - /** - * Instantiates a new key value. - */ - public KeyValue() { - super(); - } - - /** - * Instantiates a new key value. - * - * @param key - * the key - * @param value - * the value - */ - public KeyValue(String key, String value) { - super(); - this.key = key; - this.value = value; - } - - /** - * Gets the key. - * - * @return the key - */ - public String getKey() { - return key; - } - - /** - * Sets the key. - * - * @param key - * the new key - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Gets the value. - * - * @return the value - */ - public String getValue() { - return value; - } - - /** - * Sets the value. - * - * @param value - * the new value - */ - public void setValue(String value) { - this.value = value; - } - -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties 2008-02-22 16:48:39 UTC (rev 1196) +++ trunk/simexplorer-is/simexplorer-is-storage/src/resources/properties/config.properties 2008-02-22 16:49:23 UTC (rev 1197) @@ -1,4 +1,4 @@ -simexplorer.db=/var/local/simexplorer/db1 -simexplorer.data=/var/local/simexplorer/data1/ +simexplorer.db=/var/local/simexplorer/server-db +simexplorer.data=/var/local/simexplorer/server-data/ simexplorer.optimizeperiod=3600 simexplorer.adminmail=landais at codelutin.com