Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.TypeException


            updateFieldTypeCache(newFieldType);

            // Clear the concurrency timestamp
            clearConcurrency(nameBytes, now);
        } catch (IOException e) {
            throw new TypeException("Exception occurred while creating fieldType '" + fieldType.getName()
                    + "' version: '" + version + "' on HBase", e);
        } catch (InterruptedException e) {
            throw new TypeException("Exception occurred while creating fieldType '" + fieldType.getName()
                    + "' version: '" + version + "' on HBase", e);
        }
        return newFieldType;
    }
View Full Code Here


        if (fieldType.getId() == null || fieldType.getName() == null) {
            // Since the only updateable property of a field type is its name, it only makes sense
            // that both ID and name are present (without ID, the name cannot be updated, without
            // name, there is nothing to update)
            throw new TypeException("ID and name must be specified in the field type to update.");
        }

        FieldType newFieldType = fieldType.clone();

        byte[] rowId = fieldType.getId().getBytes();
        byte[] nameBytes = null;
        Long now = null;

        try {
            // Do an exists check first
            if (!getTypeTable().exists(new Get(rowId))) {
                throw new FieldTypeNotFoundException(fieldType.getId());
            }
            // First increment the counter on the row with the name as key, then
            // read the field type
            nameBytes = encodeName(fieldType.getName());

            // Check for concurrency
            now = System.currentTimeMillis();
            checkConcurrency(fieldType.getName(), nameBytes, now);

            // Prepare the update
            FieldType latestFieldType = getFieldTypeByIdWithoutCache(fieldType.getId());
            copyUnspecifiedFields(newFieldType, latestFieldType);
            checkImmutableFieldsCorrespond(newFieldType, latestFieldType);
            if (!newFieldType.getName().equals(latestFieldType.getName())) {
                try {
                    // TODO FIXME: doesn't this rely on the field type cache being up to date?
                    getFieldTypeByName(newFieldType.getName());
                    throw new FieldTypeUpdateException("Changing the name '" + newFieldType.getName()
                            + "' of a fieldType '" + newFieldType.getId()
                            + "' to a name that already exists is not allowed; old '" + latestFieldType.getName()
                            + "' new '" + newFieldType.getName() + "'");
                } catch (FieldTypeNotFoundException allowed) {
                }
                // Update the field type on the table
                Put put = new Put(rowId);
                put.add(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_NAME.bytes, nameBytes);

                getTypeTable().put(put);
            }

            // Update the caches
            updateFieldTypeCache(newFieldType.clone());
        } catch (IOException e) {
            throw new TypeException("Exception occurred while updating fieldType '" + fieldType.getId() + "' on HBase",
                    e);
        } catch (InterruptedException e) {
            throw new TypeException("Exception occurred while updating fieldType '" + fieldType.getId() + "' on HBase",
                    e);
        } finally {
            if (nameBytes != null && now != null) {
                clearConcurrency(nameBytes, now);
            }
View Full Code Here

    @Override
    public FieldType createOrUpdateFieldType(FieldType fieldType) throws RepositoryException, InterruptedException {
        ArgumentValidator.notNull(fieldType, "fieldType");

        if (fieldType.getId() == null && fieldType.getName() == null) {
            throw new TypeException("No ID or name specified in the field type to create-or-update.");
        }

        if (fieldType.getId() != null && fieldType.getName() != null) {
            // If the ID is specified, we can assume it is a field type which is supposed to exist already
            // so we call update. We also require the name to be specified, since the name is the only
            // property of field type which can be updated, so otherwise it makes no sense to call update
            // (update will throw an exception in that case).
            return updateFieldType(fieldType);
        } else if (fieldType.getId() != null) {
            // There's nothing to update or create: just fetch the field type, check its state corresponds
            // and return it
            FieldType latestFieldType = getFieldTypeByIdWithoutCache(fieldType.getId());
            // don't modify input object
            FieldType newFieldType = fieldType.clone();
            copyUnspecifiedFields(newFieldType, latestFieldType);
            checkImmutableFieldsCorrespond(newFieldType, latestFieldType);
            // The supplied name was null, so no need to check if it corresponds
            return latestFieldType;
        } else { // if (fieldType.getName() != null) {
            int attempts;
            for (attempts = 0; attempts < 3; attempts++) {
                FieldType existingFieldType = schemaCache.getFieldTypeByNameReturnNull(fieldType.getName());
                if (existingFieldType != null) {
                    // Field types cannot be deleted so there is no possibility that it would have been deleted
                    // in the meantime.
                    FieldType latestFieldType = getFieldTypeByIdWithoutCache(existingFieldType.getId());
                    if (!latestFieldType.getName().equals(fieldType.getName())) {
                        // Between what we got from the cache and from the persistent storage, the name could
                        // be different if the cache was out of date. In such case, we could loop a few times
                        // before giving up, but for now just throwing an exception since this is not expected
                        // to occur much
                        throw new TypeException("Field type create-or-update: id-name mapping in cache different" +
                                " than what is stored. This is not a user error, just retry please.");
                    }
                    // don't modify input object
                    FieldType newFieldType = fieldType.clone();
                    copyUnspecifiedFields(newFieldType, latestFieldType);
                    checkImmutableFieldsCorrespond(newFieldType, latestFieldType);
                    return latestFieldType;
                } else {
                    try {
                        return createFieldType(fieldType);
                    } catch (FieldTypeExistsException e) {
                        // someone created the field type since we checked, we try again
                    }
                }
            }
            throw new TypeException("Field type create-or-update failed after " + attempts +
                    " attempts, toggling between create and exists mode: this should be impossible" +
                    "since field types cannot be deleted.");
        }
    }
View Full Code Here

            if (result == null || result.isEmpty()
                    || result.getValue(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_NAME.bytes) == null) {
                throw new FieldTypeNotFoundException(id);
            }
        } catch (IOException e) {
            throw new TypeException("Exception occurred while retrieving fieldType '" + id + "' from HBase", e);
        }
        return extractFieldType(id, result);
    }
View Full Code Here

            scan.addColumn(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_NAME.bytes);
            scan.addColumn(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_VALUETYPE.bytes);
            scan.addColumn(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_SCOPE.bytes);
            scanner = getTypeTable().getScanner(scan);
        } catch (IOException e) {
            throw new TypeException("Exception occurred while retrieving field types without cache ", e);
        }
        for (Result result : scanner) {
            fieldTypes.add(extractFieldType(new SchemaIdImpl(result.getRow()), result));
        }
        Closer.close(scanner);
View Full Code Here

            scan.addFamily(TypeCf.FIELDTYPE_ENTRY.bytes);
            scan.addFamily(TypeCf.SUPERTYPE.bytes);

            scanner = getTypeTable().getScanner(scan);
        } catch (IOException e) {
            throw new TypeException("Exception occurred while retrieving record types without cache ", e);
        }
        for (Result result : scanner) {
            recordTypes.addAll(extractRecordType(new SchemaIdImpl(result.getRow()), null, result));
        }
        Closer.close(scanner);
View Full Code Here

        scan.setMaxVersions(); // we want all available versions

        try {
            scanner = getTypeTable().getScanner(scan);
        } catch (IOException e) {
            throw new TypeException("Exception occurred while retrieving field types and record types without cache ",
                    e);
        }

        // Collect the results first and close the scanner as fast as possible
        List<Result> results = new ArrayList<Result>();
View Full Code Here

            scan.setStopRow(new byte[]{rowPrefix[1]});
        }
        try {
            scanner = getTypeTable().getScanner(scan);
        } catch (IOException e) {
            throw new TypeException("Exception occurred while retrieving field types and record types without cache ",
                    e);
        }

        // Collect the results first and close the scanner as fast as possible
        List<Result> results = new ArrayList<Result>();
View Full Code Here

    }

    private ValueType decodeValueType(byte[] bytes) throws RepositoryException, InterruptedException {
        DataInput dataInput = new DataInputImpl(bytes);
        if (valueTypeEncodingVersion != dataInput.readByte()) {
            throw new TypeException("Unknown value type encoding version encountered in schema");
        }

        return getValueType(dataInput.readUTF());
    }
View Full Code Here

TOP

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

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.