use of org.apache.ignite.cache.QueryEntityPatch in project ignite by apache.
the class QuerySchema method makePatch.
/**
* Make query schema patch.
*
* @param targetCfg Cache configuration when it should be changed (enabling indexing dynamically).
* @param target Query entity list to which current schema should be expanded.
* @return Patch to achieve entity which is a result of merging current one and target.
* @see QuerySchemaPatch
*/
public QuerySchemaPatch makePatch(CacheConfiguration<?, ?> targetCfg, Collection<QueryEntity> target) {
synchronized (mux) {
if (entities.isEmpty() && targetCfg != null) {
SchemaAddQueryEntityOperation op = new SchemaAddQueryEntityOperation(UUID.randomUUID(), targetCfg.getName(), targetCfg.getSqlSchema(), target, targetCfg.getQueryParallelism(), targetCfg.isSqlEscapeAll());
return new QuerySchemaPatch(Collections.singletonList(op), Collections.emptyList(), "");
}
Map<String, QueryEntity> localEntities = new HashMap<>();
for (QueryEntity entity : entities) {
if (localEntities.put(entity.getTableName(), entity) != null)
throw new IllegalStateException("Duplicate key");
}
Collection<SchemaAbstractOperation> patchOperations = new ArrayList<>();
Collection<QueryEntity> entityToAdd = new ArrayList<>();
StringBuilder conflicts = new StringBuilder();
for (QueryEntity queryEntity : target) {
if (localEntities.containsKey(queryEntity.getTableName())) {
QueryEntity localEntity = localEntities.get(queryEntity.getTableName());
QueryEntityPatch entityPatch = localEntity.makePatch(queryEntity);
if (entityPatch.hasConflict()) {
if (conflicts.length() > 0)
conflicts.append("\n");
conflicts.append(entityPatch.getConflictsMessage());
}
if (!entityPatch.isEmpty())
patchOperations.addAll(entityPatch.getPatchOperations());
} else
entityToAdd.add(QueryUtils.copy(queryEntity));
}
return new QuerySchemaPatch(patchOperations, entityToAdd, conflicts.toString());
}
}
Aggregations