ServerCommitServiceMock.java :  » Log » magicdroid » org » magicdroid » app » test » Android Open Source

Android Open Source » Log » magicdroid 
magicdroid » org » magicdroid » app » test » ServerCommitServiceMock.java
package org.magicdroid.app.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.magicdroid.app.clientsynch.SynchCommitServiceImpl;
import org.magicdroid.commons.Structures;
import org.magicdroid.features.EntityFeature;
import org.magicdroid.features.IdentifyFeature;
import org.magicdroid.features.IdentifyFeature.EntityId;
import org.magicdroid.server.CommitService;

public class ServerCommitServiceMock implements CommitService, SynchCommitServiceImpl.XYZ {
  
  private final Map<Class<?>, Map<IdentifyFeature.EntityId, Map<String,Object>>> db = new Structures.MapWithLazyLoading<Class<?>, Map<IdentifyFeature.EntityId, Map<String,Object>>>() {
    @Override protected Map<EntityId, Map<String,Object>> load(Class<?> key) {
      return new HashMap<IdentifyFeature.EntityId, Map<String,Object>>();
    }
  };
  
  @Override
  public void commit(EntityFeature<?>[] changed, EntityId[] deleted) {
    try {
      Thread.sleep(20);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }
    
    for (EntityId id : deleted)
      this.db.get(id.getType()).remove(id);
    
//    List<EntityId> result = new ArrayList<EntityId>();
    for (EntityFeature<?> entity : changed) {
      Map<EntityId, Map<String,Object>> table = this.db.get(entity.metaEntityType());
      EntityId id = entity.getId();
      if (! table.containsKey(entity.getId()))
        id = new EntityId(id.getType(), id.getValue());
      table.put(id, entity.metaAsMap());
//      result.add(id);
    }
    //TODO clientid
//    return result.toArray(new EntityId[0]);
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.