/** * Create data transfer object for given cache type metadata. * * @param q Actual cache query entities. */ private VisorQueryEntity(QueryEntity q) { assert q != null; keyType = q.getKeyType(); valType = q.getValueType(); keyFields = toList(q.getKeyFields()); LinkedHashMap<String, String> qryFields = q.getFields(); qryFlds = new LinkedHashMap<>(qryFields); aliases = U.copyMap(q.getAliases()); Collection<QueryIndex> qryIdxs = q.getIndexes(); grps = new ArrayList<>(qryIdxs.size()); for (QueryIndex qryIdx : qryIdxs) grps.add(new VisorQueryIndex(qryIdx)); tblName = q.getTableName(); keyFieldName = q.getKeyFieldName(); valFieldName = q.getValueFieldName(); }
String valFieldName = entity.getValueFieldName();
/** * Checks if given column can be removed from table using its {@link QueryEntity}. * * @param entity Query entity. * @param fieldName Name of the field of the key or value object. * @param colName Name of the column. * @return {@code null} if it's OK to remove the column and exception otherwise. */ public static SchemaOperationException validateDropColumn(QueryEntity entity, String fieldName, String colName) { if (F.eq(fieldName, entity.getKeyFieldName()) || KEY_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache key"); if (F.eq(fieldName, entity.getValueFieldName()) || VAL_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache value"); Set<String> keyFields = entity.getKeyFields(); if (keyFields != null && keyFields.contains(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it is a part of a cache key"); Collection<QueryIndex> indexes = entity.getIndexes(); if (indexes != null) { for (QueryIndex idxDesc : indexes) { if (idxDesc.getFields().containsKey(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because an index exists (\"" + idxDesc.getName() + "\") that uses the column."); } } return null; }
String valFieldName = qryEntity.getValueFieldName();
writer.writeString(qryEntity.getTableName()); writer.writeString(qryEntity.getKeyFieldName()); writer.writeString(qryEntity.getValueFieldName());
/** * Transforms cache entry to map (column name -> value). * * @param meta Meta information (QueryEntity) about table. * @param key Key of the cache entry. * @param val Value of the cache entry. */ private static Map<String, Object> entryToMap(QueryEntity meta, Object key, Object val) { Map<String, Object> row = new LinkedHashMap<>(); // Look up for the field in the key if (key instanceof BinaryObject) { BinaryObject compositeKey = (BinaryObject)key; for (String field : compositeKey.type().fieldNames()) row.put(field, compositeKey.field(field)); } else row.put(meta.getKeyFieldName(), key); // And in the value. if (val instanceof BinaryObject) { BinaryObject compositeVal = (BinaryObject)val; for (String field : compositeVal.type().fieldNames()) row.put(field, compositeVal.field(field)); } else row.put(meta.getValueFieldName(), val); return row; }
fields.put(entity.getValueFieldName(), entity.getValueType());
w.writeString(e.getTableName()); w.writeString(e.getKeyFieldName()); w.writeString(e.getValueFieldName()); ClientUtils.collection( e.getFields().entrySet(),
normalEntity.setKeyFields(entity.getKeyFields()); normalEntity.setKeyFieldName(entity.getKeyFieldName()); normalEntity.setValueFieldName(entity.getValueFieldName()); normalEntity.setNotNullFields(entity.getNotNullFields()); normalEntity.setDefaultFieldValues(entity.getDefaultFieldValues());
desc.valueFieldName(qryEntity.getValueFieldName());
String valFieldName = qryEntity.getValueFieldName();
/** * Create data transfer object for given cache type metadata. * * @param q Actual cache query entities. */ private VisorQueryEntity(QueryEntity q) { assert q != null; keyType = q.getKeyType(); valType = q.getValueType(); keyFields = toList(q.getKeyFields()); LinkedHashMap<String, String> qryFields = q.getFields(); qryFlds = new LinkedHashMap<>(qryFields); aliases = U.copyMap(q.getAliases()); Collection<QueryIndex> qryIdxs = q.getIndexes(); grps = new ArrayList<>(qryIdxs.size()); for (QueryIndex qryIdx : qryIdxs) grps.add(new VisorQueryIndex(qryIdx)); tblName = q.getTableName(); keyFieldName = q.getKeyFieldName(); valFieldName = q.getValueFieldName(); }
/** * Checks if given column can be removed from table using its {@link QueryEntity}. * * @param entity Query entity. * @param fieldName Name of the field of the key or value object. * @param colName Name of the column. * @return {@code null} if it's OK to remove the column and exception otherwise. */ public static SchemaOperationException validateDropColumn(QueryEntity entity, String fieldName, String colName) { if (F.eq(fieldName, entity.getKeyFieldName()) || KEY_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache key"); if (F.eq(fieldName, entity.getValueFieldName()) || VAL_FIELD_NAME.equalsIgnoreCase(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it represents an entire cache value"); Set<String> keyFields = entity.getKeyFields(); if (keyFields != null && keyFields.contains(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because it is a part of a cache key"); Collection<QueryIndex> indexes = entity.getIndexes(); if (indexes != null) { for (QueryIndex idxDesc : indexes) { if (idxDesc.getFields().containsKey(fieldName)) return new SchemaOperationException("Cannot drop column \"" + colName + "\" because an index exists (\"" + idxDesc.getName() + "\") that uses the column."); } } return null; }
String valFieldName = entity.getValueFieldName();
writer.writeString(qryEntity.getTableName()); writer.writeString(qryEntity.getKeyFieldName()); writer.writeString(qryEntity.getValueFieldName());
w.writeString(e.getTableName()); w.writeString(e.getKeyFieldName()); w.writeString(e.getValueFieldName()); ClientUtils.collection( e.getFields().entrySet(),
normalEntity.setKeyFields(entity.getKeyFields()); normalEntity.setKeyFieldName(entity.getKeyFieldName()); normalEntity.setValueFieldName(entity.getValueFieldName()); normalEntity.setNotNullFields(entity.getNotNullFields()); normalEntity.setDefaultFieldValues(entity.getDefaultFieldValues());
desc.valueFieldName(qryEntity.getValueFieldName());