Package org.hivedb.configuration

Examples of org.hivedb.configuration.EntityConfig


    this.hive = hive;
  }

  // The Hive HAS to be responsible for shard allocation
  public ShardId selectShardIdForNewObject(Object entity) {
    EntityConfig config = hiveConfig.getEntityConfig(resolveEntityConfigClass(entity.getClass()));

    if (!hive.directory().doesPrimaryIndexKeyExist(config.getPrimaryIndexKey(entity)))
      try {
        hive.directory().insertPrimaryIndexKey(config.getPrimaryIndexKey(entity));
      } catch (HiveLockableException e) {
        throw new HiveRuntimeException(e.getMessage(), e);
      }

    Collection<Integer> nodeIds =
      hive.directory().getNodeIdsOfPrimaryIndexKey(config.getPrimaryIndexKey(entity));

    return Atom.getFirstOrThrow(Transform.map(HiveShardResolver.nodeIdToShardIdConverter(), nodeIds));
  }
View Full Code Here


      throw new RuntimeException(e);
    }
  }

  public static Service load(Class clazz, Class serviceClass, Class serviceResponseClass, Class serviceContainerClass, Hive hive, EntityHiveConfig entityHiveConfig, ShardAccessStrategy strategy) {
    EntityConfig config = entityHiveConfig.getEntityConfig(clazz.getCanonicalName());
    List<Class<?>> classes = Lists.newArrayList();
    classes.addAll(new EntityResolver(entityHiveConfig).getEntityClasses());
    HiveSessionFactory factory = new HiveSessionFactoryBuilderImpl(entityHiveConfig, hive, strategy);
    DataAccessObject dao = new BaseDataAccessObject(config, hive, factory);
    return (Service) GeneratedClassFactory.newInstance(serviceClass, new GeneratedServiceInterceptor(clazz, serviceClass, serviceResponseClass, serviceContainerClass, dao, config));
View Full Code Here

  private void updateIndexes(Object entity) {
    try {
      final Class<?> resolvedEntityClass = resolveEntityClass(entity.getClass());
      if (resolvedEntityClass != null) {
        final EntityConfig entityConfig = hiveConfig.getEntityConfig(entity.getClass());
        if (indexer.idExists(entityConfig, entityConfig.getId(entity)))
          indexer.updatePartitionDimensionIndexIfNeeded(hiveConfig.getEntityConfig(resolvedEntityClass), entity);
        indexer.update(entityConfig, entity);
      }
    } catch (HiveLockableException e) {
      log.warn(e);
View Full Code Here

  protected abstract Service createService(ConfigurationReader reader);
 
  @Test
  public void saveAndRetrieve() throws Exception {
    Object instance = getPersistentInstance();
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    validate(createServiceResponse(Arrays.asList(instance)), invoke(getClient(), "get", entityConfig.getId(instance)), Arrays.asList(new String[] {}));
  }
View Full Code Here

    }
  }
 
  @Test
  public void saveAll() throws Exception {
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    Collection<T> instances = Lists.newArrayList();
    for(int i=0; i<5; i++) {
      final T instance = getInstance();
      instances.add(instance);
    }
    Service s = getClient();
    invokeWithArrayArgument(s, "saveAll", collectionToArray(clazz, instances));
    for(Object original : instances)
      validate(
          createServiceResponse(Arrays.asList(original)),
          invoke(s, "get", entityConfig.getId(original)),
          Arrays.asList(new String[] {}));
  }
View Full Code Here

          Arrays.asList(new String[] {}));
  }
 
  @Test
  public void update() throws Exception {
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    Collection<T> instances = Lists.newArrayList();
    for(int i=0; i<5; i++) {
      final T instance = getInstance();
      instances.add(instance);
    }
    Service s = getClient();
    invokeWithArrayArgument(s, "saveAll", collectionToArray(clazz, instances));
    for(Object original : instances) {
      for (EntityIndexConfig entityIndexConfig :config.getEntityConfig(clazz).getEntityIndexConfigs()) {
        Object newValue = ReflectionTools.isCollectionProperty(clazz, entityIndexConfig.getPropertyName())
          ? new GenerateInstanceCollection(ReflectionTools.getCollectionItemType(clazz, entityIndexConfig.getPropertyName()), 3).generate()
          : new GenerateInstance(entityIndexConfig.getIndexClass()).generate();
        GeneratedInstanceInterceptor.setProperty(original, entityIndexConfig.getPropertyName(), newValue);
      }
    }
    invokeWithArrayArgument(s, "saveAll", collectionToArray(clazz, instances));
    for(Object updated : instances) {
      validate(
          createServiceResponse(Arrays.asList(updated)),
          invoke(s, "get", entityConfig.getId(updated)),
          Arrays.asList(new String[] {}));
    }
  }
View Full Code Here

  }
 
  @Test
  public void delete() throws Exception {
    Object instance = getPersistentInstance();
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    Service s = getClient();
    final Serializable id = entityConfig.getId(instance);
    validate(createServiceResponse(Arrays.asList(instance)), invoke(s, "get",id), Arrays.asList(new String[] {}));
    Assert.assertEquals(id, invokeDelete(s, "delete", id));
    Assert.assertFalse(invokeExists(s, "exists", id));
  }
View Full Code Here

    Assert.assertFalse(invokeExists(s, "exists", id));
  }
 
  @Test
  public void exists() throws Exception {
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    Service s = getClient();
    Assert.assertFalse(invokeExists(s,"exists",new GeneratePrimitiveValue<Object>((Class<Object>) entityConfig.getIdClass()).generate()));
    // Make sure that the service generates an empty response when fetching missing items
    Assert.assertEquals(0, invoke(s, "get", new GeneratePrimitiveValue<Object>((Class<Object>) entityConfig.getIdClass()).generate()).getContainers().size());
    Object p = getPersistentInstance();
    Assert.assertTrue(invokeExists(s, "exists", entityConfig.getId(p)));
  }
View Full Code Here

    * @see org.hivedb.services.DataGenerationService#generate(java.lang.String, java.lang.Integer, java.lang.Integer)
    */
  public Collection<Long> generate(String clazz, Integer partitionKeyCount, Integer instanceCount) {
    Collection<Long> ids = Lists.newArrayList();
    try {
      EntityConfig entityConfig = config.getEntityConfig(clazz);
      Generator<Object> pKeyGenerator;
      if (PrimitiveUtils.isPrimitiveClass(entityConfig.getPrimaryKeyClass()))
        pKeyGenerator = new GeneratePrimitiveValue<Object>((Class<Object>) entityConfig.getPrimaryKeyClass());
      else
        pKeyGenerator = new GenerateInstance<Object>((Class<Object>) entityConfig.getPrimaryKeyClass());
      for (int i = 0; i < partitionKeyCount; i++) {
        Object pkey = pKeyGenerator.generate();
        DataAccessObject<Object, Serializable> dao = daos.get(entityConfig.getRepresentedInterface());
        GenerateInstance<Object> instanceGenerator = new GenerateInstance<Object>((Class<Object>) entityConfig.getRepresentedInterface());
        for (int j = 0; j < instanceCount; j++) {
          Object instance = instanceGenerator.generate();
          ReflectionTools.invokeSetter(instance, entityConfig.getPrimaryIndexKeyPropertyName(), pkey);
          dao.save(instance);
          Serializable id = entityConfig.getId(instance);
          if (Number.class.isAssignableFrom(id.getClass())) {
            ids.add(Long.parseLong(id.toString()));
          } else
            throw new UnsupportedOperationException("This implementation can only generate classes with numeric ids.");
        }
View Full Code Here

  }

  @Test
  public void findByProperty() throws Exception {
    Object instance = getPersistentInstance();
    final EntityConfig entityConfig = config.getEntityConfig(clazz);
    for (EntityIndexConfig entityIndexConfig : getFilteredEntityIndexConfigs(entityConfig)) {
      if (entityIndexConfig.getIndexValues(instance).size() == 0)
        continue;
      validate(
          createServiceResponse(Arrays.asList(instance)),
View Full Code Here

TOP

Related Classes of org.hivedb.configuration.EntityConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.