Index: topia/src/java/org/codelutin/topia/persistence/xml/XmlPersistenceHelper.java diff -u /dev/null topia/src/java/org/codelutin/topia/persistence/xml/XmlPersistenceHelper.java:1.1 --- /dev/null Fri Jun 10 17:16:43 2005 +++ topia/src/java/org/codelutin/topia/persistence/xml/XmlPersistenceHelper.java Fri Jun 10 17:16:38 2005 @@ -0,0 +1,191 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* 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. +*##%*/ + +/* * +* XmlPersistenceHelper.java +* +* Created: 10 juin 2005 +* +* @author Arnaud Thimel +* @version $Revision: 1.1 $ +*/ + + +package org.codelutin.topia.persistence.xml; + +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.codelutin.topia.AsynchronousLoader; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaEntity; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.TopiaQuery; +import org.codelutin.topia.persistence.AbstractPersistenceHelper; +import org.codelutin.generator.Util; + + +public class XmlPersistenceHelper extends AbstractPersistenceHelper { + + // Cache par nom d'entité + protected Map entityNameToDoEntitiesSetMap = new HashMap(); + // Cache par id d'entité + protected Map topiaIdToDoEntityMap = new HashMap(); + + + /** + * @param context + * @param properties + */ + public XmlPersistenceHelper(TopiaContext context, Properties properties) { + super(context, properties); + // TODO Arno : Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#makePersistent(org.codelutin.topia.TopiaEntity) + */ + public TopiaEntity makePersistent(TopiaEntity entity) throws TopiaException { + entity.set_topiaLastUpdateDate_(new Date()); + String entityId = entity.get_topiaId_(); + TopiaEntity doEntity = (TopiaEntity)topiaIdToDoEntityMap.get(entityId); + if ("0".equals(entity.get_topiaVersion_())) {//L'entité vient d'être créée + if (doEntity == null) { + doEntity = entity; + add(doEntity); + } else { + throw new TopiaException("Can't persist new Entity, topiaId already in use : " + entityId); + } + } else { + if (doEntity == null) { + throw new TopiaException("Can't persist entity, can't find entity for topiaId : " + entityId); + } else { + //TODO Arno : Update ??? + } + } + return entity; + } + + /** + * @param doEntity + */ + protected void add(TopiaEntity doEntity) throws TopiaException { + String entityId = doEntity.get_topiaId_(); + String entityName = Util.toLowerCaseFirstLetter(entityId.substring(entityId.indexOf("entities.") + 9, entityId.indexOf('#'))); + // Ajoute l'entité au cache par nom d'entité + Set entitiesSet = (Set) entityNameToDoEntitiesSetMap.get(entityName); + if (entitiesSet == null) { + entitiesSet = new HashSet(); + entityNameToDoEntitiesSetMap.put(entityName, entitiesSet); + } + entitiesSet.add(doEntity); + // Ajoute l'entité au cache par id d'entité + topiaIdToDoEntityMap.put(entityId, doEntity); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#update(org.codelutin.topia.TopiaEntity) + */ + public TopiaEntity update(TopiaEntity entity) throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#delete(org.codelutin.topia.TopiaEntity) + */ + public void delete(TopiaEntity entity) throws TopiaException { + // TODO Arno : Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#find(org.codelutin.topia.TopiaQuery) + */ + public List find(TopiaQuery query) throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#findAsynchronously(org.codelutin.topia.TopiaQuery) + */ + public AsynchronousLoader findAsynchronously(TopiaQuery query) + throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#findInRange(org.codelutin.topia.TopiaQuery, int, int) + */ + public List findInRange(TopiaQuery query, int startIndex, int endIndex) + throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#findInRangeAsynchronously(org.codelutin.topia.TopiaQuery, int, int) + */ + public AsynchronousLoader findInRangeAsynchronously(TopiaQuery query, + int startIndex, int endIndex) throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#size(org.codelutin.topia.TopiaQuery) + */ + public int size(TopiaQuery query) throws TopiaException { + // TODO Arno : Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#importXML(java.lang.String) + */ + public void importXML(String xml) throws TopiaException { + // TODO Arno : Auto-generated method stub + + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#exportXML() + */ + public String exportXML() throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.persistence.PersistenceHelper#findByTopiaId(java.lang.String) + */ + public TopiaEntity findByTopiaId(String id) throws TopiaException { + // TODO Arno : Auto-generated method stub + return null; + } + +}