Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.ValueType


        }
    }

    private Set<BlobReference> getReferencedBlobs(FieldTypeImpl fieldType, Object value) throws BlobException {
        HashSet<BlobReference> referencedBlobs = new HashSet<BlobReference>();
        ValueType valueType = fieldType.getValueType();
        if ((valueType.getDeepestValueType() instanceof BlobValueType) && !isDeleteMarker(value)) {
            Set<Object> values = valueType.getValues(value);
            for (Object object : values) {
                referencedBlobs.add(new BlobReference((Blob) object, null, fieldType));
            }
        }
        return referencedBlobs;
View Full Code Here


        }
        Set<BlobReference> unReferencedBlobs = new HashSet<BlobReference>();
        for (BlobReference blobReference : blobs) {
            FieldTypeImpl fieldType = (FieldTypeImpl) blobReference.getFieldType();
            byte[] recordIdBytes = recordId.toBytes();
            ValueType valueType = fieldType.getValueType();

            Get get = new Get(recordIdBytes);
            get.addColumn(RecordCf.DATA.bytes, fieldType.getQualifier());
            byte[] valueToCompare = Bytes.toBytes(valueType.getNestingLevel());

            // Note, if a encoding of the BlobValueType is added, this might have to change.
            valueToCompare = Bytes.add(valueToCompare, blobReference.getBlob().getValue());
            WritableByteArrayComparable valueComparator = new ContainsValueComparator(valueToCompare);
            Filter filter = new SingleColumnValueFilter(RecordCf.DATA.bytes, fieldType.getQualifier(), CompareOp.EQUAL,
View Full Code Here

        private byte[] encodeFieldValue(Record parentRecord, FieldType fieldType, Object fieldValue, Metadata metadata)
                throws RepositoryException, InterruptedException {
            if (isDeleteMarker(fieldValue)) {
                return FieldFlags.getDeleteMarker();
            }
            ValueType valueType = fieldType.getValueType();

            // fieldValue should never be null by the time we get here, but check anyway
            if (fieldValue == null) {
                throw new RepositoryException("Null field values are not allowed. Field: " + fieldType.getName());
            }

            if (!valueType.getType().isAssignableFrom(fieldValue.getClass())) {
                throw new RepositoryException(String.format("Incorrect type of value provided for field %s. "
                        + "Expected instance of %s but got %s.", fieldType.getName(), valueType.getType().getName(),
                        fieldValue.getClass().getName()));
            }

            DataOutput dataOutput = new DataOutputImpl();
            boolean hasMetadata = metadata != null && !metadata.getMap().isEmpty();

            dataOutput.writeByte(hasMetadata ? FieldFlags.METADATA_V1 : FieldFlags.DEFAULT);
            try {
                valueType.write(fieldValue, dataOutput, new IdentityRecordStack(parentRecord));
            } catch (InterruptedException e) {
                throw e;
            } catch (Exception e) {
                // wrap the exception so that it is known what field causes the problem
                throw new RepositoryException("Error serializing value for field " + fieldType.getName(), e);
View Full Code Here

        }

        private Result getBlobUsage(byte[] blobKey, SchemaId recordId, SchemaId fieldId) throws FieldTypeNotFoundException,
                TypeException, InterruptedException, IOException, RepositoryException {
            FieldTypeImpl fieldType = (FieldTypeImpl)typeManager.getFieldTypeById(fieldId);
            ValueType valueType = fieldType.getValueType();
            Get get = new Get(recordId.getBytes());
            get.addColumn(RecordCf.DATA.bytes, fieldType.getQualifier());
            byte[] valueToCompare = Bytes.toBytes(valueType.getNestingLevel());
            valueToCompare = Bytes.add(valueToCompare, blobKey);
            WritableByteArrayComparable valueComparator = new ContainsValueComparator(valueToCompare);
            Filter filter = new SingleColumnValueFilter(RecordCf.DATA.bytes, fieldType.getQualifier(), CompareOp.EQUAL, valueComparator);
            get.setFilter(filter);
View Full Code Here

    }

    private Blob getBlobFromRecord(Record record, QName fieldName, FieldType fieldType, int... indexes)
            throws BlobNotFoundException {
        Object value = record.getField(fieldName);
        ValueType valueType = fieldType.getValueType();
        if (!valueType.getDeepestValueType().getBaseName().equals("BLOB")) {
            throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() + "', '" +
                    fieldName + "' at index: " + Ints.join("/", indexes));
        }

        if (indexes == null) {
            indexes = new int[0];
        }

        for (int i = 0; i < indexes.length; i++) {
            int index = indexes[i];
            try {
                if (valueType.getBaseName().equals("LIST")) {
                    value = ((List<Object>) value).get(index);
                    valueType = valueType.getNestedValueType();
                    continue;
                }
                if (valueType.getBaseName().equals("PATH")) {
                    value = ((HierarchyPath)value).getElements()[index];
                    valueType = valueType.getNestedValueType();
                    continue;
                }
                throw new BlobNotFoundException("Invalid index to retrieve Blob from '" + record.getId() +
                        "', '" + fieldName + "' : " + Ints.join("/", Arrays.copyOf(indexes, i + 1)));
            } catch (IndexOutOfBoundsException e) {
                throw new BlobNotFoundException("Invalid index to retrieve Blob from '" + record.getId() +
                        "', '" + fieldName + "' : " + Ints.join("/", Arrays.copyOf(indexes, i + 1)), e);
            }
        }
        if (!valueType.getBaseName().equals("BLOB")) {
            throw new BlobNotFoundException("Blob could not be retrieved from '" + record.getId() +
                    "', '" + fieldName + "' at index: " + Ints.join("/", indexes));
        }
        return (Blob)value;
    }
View Full Code Here

            Thread.sleep(20);
        }
    }

    private static void setupSchema() throws Exception {
        ValueType stringValueType = typeManager.getValueType("STRING");
        ValueType stringMvValueType = typeManager.getValueType("LIST<STRING>");

        ValueType longValueType = typeManager.getValueType("LONG");

        ValueType linkValueType = typeManager.getValueType("LINK");

        ValueType blobValueType = typeManager.getValueType("BLOB");
        ValueType blobMvHierValueType = typeManager.getValueType("LIST<PATH<BLOB>>");
        ValueType blobNestedValueType = typeManager.getValueType("LIST<LIST<LIST<BLOB>>>");

        ValueType dateTimeValueType = typeManager.getValueType("DATETIME");
        ValueType dateValueType = typeManager.getValueType("DATE");

        ValueType intHierValueType = typeManager.getValueType("PATH<INTEGER>");


        //
        // Version tag fields
        //
View Full Code Here

        messageVerifier.init();

        //
        // Create schema
        //
        ValueType stringValueType = typeManager.getValueType("STRING");
        ValueType longValueType = typeManager.getValueType("LONG");
        ValueType mvStringValueType = typeManager.getValueType("LIST<STRING>");
        ValueType hierStringValueType = typeManager.getValueType("PATH<STRING>");
        ValueType dateValueType = typeManager.getValueType("DATE");
        ValueType blobValueType = typeManager.getValueType("BLOB");

        FieldType field1 = typeManager.createFieldType(stringValueType, new QName(DYN_NS1, "field1"), Scope.VERSIONED);

        FieldType field2 = typeManager.createFieldType(stringValueType, new QName(DYN_NS2, "field2"), Scope.VERSIONED);
View Full Code Here

        //
        // Create schema
        //
        log.debug("Begin test V401");
        ValueType stringValueType = typeManager.getValueType("STRING");
        ValueType linkValueType = typeManager.getValueType("LINK");

        FieldType field1 = typeManager.createFieldType(stringValueType, new QName(NS, "sf_field1"), Scope.VERSIONED);

        FieldType field2 = typeManager.createFieldType(linkValueType, new QName(NS, "sf_field2"), Scope.VERSIONED);
View Full Code Here

public class HierarchicalFacetPrefixFormatter implements Formatter {
    @Override
    public List<String> format(List<IndexValue> indexValues, LRepository repository) throws InterruptedException {
        List<String> result = new ArrayList<String>();
        for (IndexValue indexValue : indexValues) {
            ValueType valueType = indexValue.fieldType.getValueType();
            if (valueType.getBaseName().equals("LIST")) {
                // The values of the first list-level are supplied as individual IndexValues
                valueType = valueType.getNestedValueType();
            }

            if (!valueType.getName().equals("STRING")) {
                throw new RuntimeException(this.getClass().getSimpleName() + " only supports string values, but got: "
                        + valueType.getName());
            }
            processPath((String)indexValue.value, result);
        }
        return result;
    }
View Full Code Here

                AvroMutationCondition avroCond = new AvroMutationCondition();

                avroCond.setName(convert(condition.getField()));

                if (condition.getValue() != null) {
                    ValueType valueType = fieldType.getValueType();
                    avroCond.setValueType(valueType.getName());

                    byte[] value = valueType.toBytes(condition.getValue(), parentRecords);
                    avroCond.setValue(ByteBuffer.wrap(value));
                }
                avroCond.setOperator(convert(condition.getOp()));
                avroCond.setAllowMissing(condition.getAllowMissing());
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.ValueType

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.