Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.FieldTypes


            }

            byte[] rowId = recordId.toBytes();

            try {
                FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();

                long version = 1L;
                byte[] oldOccBytes = null;
                long newOcc = 1L;
                // If the record existed it would have been deleted.
View Full Code Here


            if (recordId == null) {
                throw new InvalidRecordException("The recordId cannot be null for a record to be updated.",
                        record.getId());
            }

            FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();

            // Check if the update is an update of mutable fields
            if (updateVersion) {
                try {
                    return updateMutableFields(record, useLatestRecordType, conditions, fieldTypes);
View Full Code Here

        long before = System.currentTimeMillis();
        byte[] rowId = recordId.toBytes();
        try {
            // We need to read the original record in order to put the delete marker in the non-versioned fields.
            // Throw RecordNotFoundException if there is no record to be deleted
            FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();

            // The existing record is read with authorization disabled, because when deleting a full record we
            // must make sure we can delete all the fields in it.
            Pair<Record, byte[]> recordAndOcc = readWithOcc(recordId, null, null, fieldTypes, true);
            recordAndOcc.getV1().setAttributes(attributes);
            Record originalRecord = new UnmodifiableRecord(recordAndOcc.getV1());

            // If the record contains any field with scope != non-versioned, do not allow to delete it if
            // authorization is active. This is because access to these fields will not be validated by the
            // first Put call below, and hence the clearData afterwards might fail, leaving us with a half-deleted
            // record.
            if (AuthorizationContextHolder.getCurrentContext() != null) {
                for (QName field : originalRecord.getFields().keySet()) {
                    if (fieldTypes.getFieldType(field).getScope() != Scope.NON_VERSIONED) {
                        throw new RepositoryException("Deleting records with versioned or versioned-mutable fields "
                                + "is not supported when authorization is active.");
                    }
                }
            }

            byte[] oldOcc = recordAndOcc.getV2();

            RecordEvent recordEvent = new RecordEvent();
            recordEvent.setType(Type.DELETE);
            recordEvent.setTableName(getTableName());
            if (attributes != null && !attributes.isEmpty()) {
                recordEvent.getAttributes().putAll(attributes);
            }

            for (RecordUpdateHook hook : updateHooks) {
                hook.beforeDelete(originalRecord, this, fieldTypes, recordEvent);
            }

            if (conditions != null) {
                Record conditionsRecord = MutationConditionVerifier.checkConditions(originalRecord, conditions, this,
                        null);
                if (conditionsRecord != null) {
                    return conditionsRecord;
                }
            }

            Put put = new Put(rowId);
            // Mark the record as deleted
            put.add(RecordCf.DATA.bytes, RecordColumn.DELETED.bytes, 1L, Bytes.toBytes(true));

            // Put the delete marker in the non-versioned fields instead of deleting their columns in the clearData call
            // This is needed to avoid non-versioned fields to be lost due to the hbase delete thombstone
            // See trac ticket http://dev.outerthought.org/trac/outerthought_lilyproject/ticket/297
            Map<QName, Object> fields = originalRecord.getFields();
            for (Entry<QName, Object> fieldEntry : fields.entrySet()) {
                FieldTypeImpl fieldType = (FieldTypeImpl) fieldTypes.getFieldType(fieldEntry.getKey());
                if (Scope.NON_VERSIONED == fieldType.getScope()) {
                    put.add(RecordCf.DATA.bytes, fieldType.getQualifier(), 1L, FieldFlags.getDeleteMarker());
                }

            }
View Full Code Here

    }

    @Test
    public void testEmptyRecord() throws Exception {
        converter = new AvroConverter();
        FieldTypes fieldTypesSnapshot = control.createMock(FieldTypes.class);
        recordFactory.newRecord();
        expectLastCall().andReturn(new RecordImpl()).anyTimes();
        typeManager.getFieldTypesSnapshot();
        expectLastCall().andReturn(fieldTypesSnapshot).anyTimes();
        control.replay();
View Full Code Here

    @Test
    public void testRecord() throws Exception {
        converter = new AvroConverter();
        FieldType fieldType = control.createMock(FieldType.class);
        FieldTypes fieldTypesSnapshot = control.createMock(FieldTypes.class);
        ValueType valueType = new StringValueType();
        IdGenerator idGenerator = new IdGeneratorImpl();

        recordFactory.newRecord();
        expectLastCall().andReturn(new RecordImpl()).anyTimes();
        repository.getIdGenerator();
        expectLastCall().andReturn(idGenerator).anyTimes();
        typeManager.getFieldTypesSnapshot();
        expectLastCall().andReturn(fieldTypesSnapshot).anyTimes();
        fieldTypesSnapshot.getFieldType(isA(QName.class));
        expectLastCall().andReturn(fieldType).anyTimes();
        fieldType.getValueType();
        expectLastCall().andReturn(valueType).anyTimes();
        typeManager.getValueType("STRING");
        expectLastCall().andReturn(valueType).anyTimes();
View Full Code Here

            writeNullOrQName(record.getRecordTypeName(scope), output);
            writeNullOrVLong(record.getRecordTypeVersion(scope), output);
        }

        // Write the fields array
        FieldTypes fieldTypes = repository.getTypeManager().getFieldTypesSnapshot();
        output.writeVInt(record.getFields().size());
        for (Map.Entry<QName, Object> entry : record.getFields().entrySet()) {
            if (entry.getKey() == null) {
                throw new IllegalArgumentException("Record contains field with null key.");
            }
            if (entry.getValue() == null) {
                throw new IllegalArgumentException("Record contains field with null value.");
            }

            ValueType valueType = fieldTypes.getFieldType(entry.getKey()).getValueType();

            writeQName(entry.getKey(), output);
            output.writeUTF(valueType.getName());
            try {
                valueType.write(entry.getValue(), output, new IdentityRecordStack());
View Full Code Here

    }

    @Override
    public List<Record> read(List<RecordId> recordIds, QName... fieldNames)
            throws RepositoryException, InterruptedException {
        FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
        List<FieldType> fields = getFieldTypesFromNames(fieldTypes, fieldNames);

        return read(recordIds, fields, fieldTypes);
    }
View Full Code Here

    }

    @Override
    public Record read(RecordId recordId, Long version, QName... fieldNames)
            throws RepositoryException, InterruptedException {
        FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
        List<FieldType> fields = getFieldTypesFromNames(fieldTypes, fieldNames);

        return read(recordId, version, fields, fieldTypes);
    }
View Full Code Here

    }

    @Override
    public IdRecord readWithIds(RecordId recordId, Long version, List<SchemaId> fieldIds)
            throws RepositoryException, InterruptedException {
        FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
        List<FieldType> fields = getFieldTypesFromIds(fieldIds, fieldTypes);

        return readWithIds(recordId, version, fields, fieldTypes);
    }
View Full Code Here

        if (fromVersion > toVersion) {
            throw new IllegalArgumentException("fromVersion '" + fromVersion +
                    "' must be smaller or equal to toVersion '" + toVersion + "'");
        }

        FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();
        List<FieldType> fields = getFieldTypesFromNames(fieldTypes, fieldNames);

        int numberOfVersionsToRetrieve = (int) (toVersion - fromVersion + 1);
        Result result = getRow(recordId, toVersion, numberOfVersionsToRetrieve, fields);
        if (fromVersion < 1L) {
View Full Code Here

TOP

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

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.