Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.SchemaId


            this.typeManager = typeManager;
        }

        @Override
        public RecordTypeInfo decode(byte[] bytes) {
            SchemaId id = new SchemaIdImpl(bytes);
            QName name;
            try {
                name = typeManager.getRecordTypeById(id, null).getName();
            } catch (Exception e) {
                name = new QName("", "Failure retrieving record type name");
View Full Code Here


        ArgumentValidator.notNull(recordType.getName(), "recordType.name");

        RecordType newRecordType = recordType.clone();
        Long recordTypeVersion = Long.valueOf(1);
        try {
            SchemaId id = getValidId();
            byte[] rowId = id.getBytes();
            // Take a counter on a row with the name as key
            byte[] nameBytes = encodeName(recordType.getName());

            // Prepare put
            Put put = new Put(rowId);
View Full Code Here

        if (recordType.getId() == null && recordType.getName() == null) {
            throw new IllegalArgumentException("No id or name specified in the supplied record type.");
        }

        SchemaId id;
        if (recordType.getId() == null) {
            // Map the name to id
            RecordType existingType = getRecordTypeFromCache(recordType.getName(), recordType.getVersion());
            if (existingType == null) {
                throw new RecordTypeNotFoundException(recordType.getName(), null);
            } else {
                id = existingType.getId();
            }
        } else {
            id = recordType.getId();
        }

        RecordType newRecordType = recordType.clone();
        newRecordType.setId(id);

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

        try {
View Full Code Here

    private boolean updateSupertypes(Put put, Long newRecordTypeVersion, RecordType recordType, RecordType latestRecordType) {
        boolean changed = false;
        Map<SchemaId, Long> latestSupertypes = latestRecordType.getSupertypes();
        // Update supertypes
        for (Entry<SchemaId, Long> entry : recordType.getSupertypes().entrySet()) {
            SchemaId supertypeId = entry.getKey();
            Long supertypeVersion = entry.getValue();
            if (!supertypeVersion.equals(latestSupertypes.get(supertypeId))) {
                put.add(TypeCf.SUPERTYPE.bytes, supertypeId.getBytes(), newRecordTypeVersion, Bytes.toBytes(supertypeVersion));
                changed = true;
            }
            latestSupertypes.remove(supertypeId);
        }
        // Remove remaining supertypes
View Full Code Here

            NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> allVersionsMap = result.getMap();
            NavigableMap<byte[], NavigableMap<Long, byte[]>> fieldTypeEntriesVersionsMap = allVersionsMap
                    .get(TypeCf.FIELDTYPE_ENTRY.bytes);
            if (fieldTypeEntriesVersionsMap != null) {
                for (Entry<byte[], NavigableMap<Long, byte[]>> entry : fieldTypeEntriesVersionsMap.entrySet()) {
                    SchemaId fieldTypeId = new SchemaIdImpl(entry.getKey());
                    Entry<Long, byte[]> ceilingEntry = entry.getValue().ceilingEntry(version);
                    if (ceilingEntry != null) {
                        FieldTypeEntry fieldTypeEntry = decodeFieldTypeEntry(ceilingEntry.getValue(), fieldTypeId);
                        if (fieldTypeEntry != null) {
                            recordType.addFieldTypeEntry(fieldTypeEntry);
                        }
                    }
                }
            }
        } else {
            NavigableMap<byte[], byte[]> versionableMap = result.getFamilyMap(TypeCf.FIELDTYPE_ENTRY.bytes);
            if (versionableMap != null) {
                for (Entry<byte[], byte[]> entry : versionableMap.entrySet()) {
                    SchemaId fieldTypeId = new SchemaIdImpl(entry.getKey());
                    FieldTypeEntry fieldTypeEntry = decodeFieldTypeEntry(entry.getValue(), fieldTypeId);
                    if (fieldTypeEntry != null) {
                        recordType.addFieldTypeEntry(fieldTypeEntry);
                    }
                }
View Full Code Here

        if (version != null) {
            NavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> allVersionsMap = result.getMap();
            NavigableMap<byte[], NavigableMap<Long, byte[]>> supertypeVersionsMap = allVersionsMap.get(TypeCf.SUPERTYPE.bytes);
            if (supertypeVersionsMap != null) {
                for (Entry<byte[], NavigableMap<Long, byte[]>> entry : supertypeVersionsMap.entrySet()) {
                    SchemaId supertypeId = new SchemaIdImpl(entry.getKey());
                    Entry<Long, byte[]> ceilingEntry = entry.getValue().ceilingEntry(version);
                    if (ceilingEntry != null) {
                        if (!isDeletedField(ceilingEntry.getValue())) {
                            recordType.addSupertype(supertypeId, Bytes.toLong(ceilingEntry.getValue()));
                        }
View Full Code Here

        ArgumentValidator.notNull(fieldType.getScope(), "fieldType.scope");

        FieldType newFieldType;
        Long version = Long.valueOf(1);
        try {
            SchemaId id = getValidId();
            byte[] rowId = id.getBytes();
            byte[] nameBytes = encodeName(fieldType.getName());

            // Prepare the put
            Put put = new Put(rowId);
            put.add(TypeCf.DATA.bytes, TypeColumn.FIELDTYPE_VALUETYPE.bytes, encodeValueType(fieldType.getValueType()));
View Full Code Here

    /**
     * Generates a SchemaId based on a uuid and checks if it's not already in use
     */
    private SchemaId getValidId() throws IOException {
        SchemaId id = new SchemaIdImpl(UUID.randomUUID());
        byte[] rowId = id.getBytes();
        // The chance it would already exist is small
        if (typeTable.exists(new Get(rowId))) {
            return getValidId();
        }
        // The chance a same uuid is generated after doing the exists check is
View Full Code Here

    @GET
    @Produces("application/json")
    public Entity<FieldType> get(@PathParam("id") String id, @Context UriInfo uriInfo) {
        try {
            SchemaId schemaId = idGenerator.getSchemaId(id);
            return Entity.create(typeManager.getFieldTypeById(schemaId), uriInfo);
        } catch (FieldTypeNotFoundException e) {
            throw new ResourceException(e, NOT_FOUND.getStatusCode());
        } catch (Exception e) {
            throw new ResourceException("Error loading field type with id " + id, e, INTERNAL_SERVER_ERROR.getStatusCode());
View Full Code Here

    @PUT
    @Produces("application/json")
    @Consumes("application/json")
    public Response put(@PathParam("id") String id, FieldType fieldType, @Context UriInfo uriInfo) {
        SchemaId schemaId = idGenerator.getSchemaId(id);

        if (fieldType.getId() != null && !fieldType.getId().equals(schemaId)) {
            throw new ResourceException("ID in submitted field type does not match the id in URI.",
                    BAD_REQUEST.getStatusCode());
        }
View Full Code Here

TOP

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

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.