public void updatePartitionDimensionIndexIfNeeded(EntityConfig config, Object entity) throws HiveLockableException { // Detect partition key changes Object originalPartitionKey = hive.directory() .getPrimaryIndexKeyOfResourceId(config.getResourceName(), config.getId(entity)); if (!config.getPrimaryIndexKey(entity).equals(originalPartitionKey)) { conditionallyInsertPrimaryIndexKey(config, entity); hive.directory() .updatePrimaryIndexKeyOfResourceId( config.getResourceName(), config.getId(entity), config.getPrimaryIndexKey(entity)); } }
public void insert(final EntityConfig config, final Object entity) throws HiveLockableException { try { conditionallyInsertPrimaryIndexKey(config, entity); hive.directory() .insertResourceId( config.getResourceName(), config.getId(entity), config.getPrimaryIndexKey(entity)); conditionallyInsertDelegatedResourceIndexes(config, entity); insertSecondaryIndexes(config, entity); } catch (RuntimeException e) { hive.directory().deleteResourceId(config.getResourceName(), config.getId(entity)); throw e; } }
private void conditionallyInsertDelegatedResourceIndexes(EntityConfig config, Object entity) throws HiveLockableException { for (EntityIndexConfig entityIndexConfig : config.getEntityIndexConfigs()) if (entityIndexConfig.getIndexType().equals(IndexType.Delegates)) { final EntityIndexConfigDelegator delegateEntityConfig = ((EntityIndexConfigDelegator) entityIndexConfig); for (Object value : entityIndexConfig.getIndexValues(entity)) if (!hive.directory() .doesResourceIdExist( delegateEntityConfig.getDelegateEntityConfig().getResourceName(), value)) insert( delegateEntityConfig.getDelegateEntityConfig(), delegateEntityConfig.stubEntityInstance(value, config.getPrimaryIndexKey(entity))); } }
public void conditionallyInsertPrimaryIndexKey(final EntityConfig config, final Object entity) throws HiveLockableException { if (!hive.directory().doesPrimaryIndexKeyExist(config.getPrimaryIndexKey(entity))) hive.directory().insertPrimaryIndexKey(config.getPrimaryIndexKey(entity)); }
public void delete(EntityConfig config, Object entity) throws HiveLockableException { if (config.isPartitioningResource()) hive.directory().deletePrimaryIndexKey(config.getPrimaryIndexKey(entity)); else hive.directory().deleteResourceId(config.getResourceName(), config.getId(entity)); }