Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordId


     * Decode the given HBase result into a Lily Record assuming it contains the state of the latest version of
     * the record (if the record has any versions, otherwise it only contains non-versioned fields).
     */
    public Record decodeRecord(Result result) throws InterruptedException, RepositoryException {
        Long latestVersion = getLatestVersion(result);
        RecordId recordId = idGenerator.fromBytes(result.getRow());
        return decodeRecord(recordId, latestVersion, null, result, typeManager.getFieldTypesSnapshot());
    }
View Full Code Here


    /**
     * Version of #decodeRecord() which returns an {@link IdRecord} instance rather than a {@link Record} instance.
     */
    public IdRecord decodeRecordWithIds(Result result) throws InterruptedException, RepositoryException {
        Long latestVersion = getLatestVersion(result);
        RecordId recordId = idGenerator.fromBytes(result.getRow());
        return decodeRecordWithIds(recordId, latestVersion, result, typeManager.getFieldTypesSnapshot());
    }
View Full Code Here

    public Entity<Record> get(@PathParam("id") String id, @Context UriInfo uriInfo) {
        return get(id, uriInfo, getRepository(uriInfo), getTable(uriInfo));
    }

    public Entity<Record> get(String id, UriInfo uriInfo, LRepository repository, LTable table) {
        RecordId recordId = repository.getIdGenerator().fromString(id);
        List<QName> fieldQNames = ResourceClassUtil.parseFieldList(uriInfo);
        try {
            return Entity.create(table.read(recordId, fieldQNames), uriInfo);
        } catch (RecordNotFoundException e) {
            throw new ResourceException(e, NOT_FOUND.getStatusCode());
View Full Code Here

        LTable table = getTable(uriInfo);
        return put(id, record, uriInfo, repository, table);
    }

    public Response put(String id, Record record, UriInfo uriInfo, LRepository repository, LTable table) {
        RecordId recordId = repository.getIdGenerator().fromString(id);

        if (record.getId() != null && !record.getId().equals(recordId)) {
            throw new ResourceException("Record id in submitted record does not match record id in URI.",
                    BAD_REQUEST.getStatusCode());
        }
View Full Code Here

        return post(id, postAction, uriInfo, repository, table);
    }

    public Response post(String id, PostAction<Record> postAction, UriInfo uriInfo, LRepository repository, LTable table) {
        if (postAction.getAction().equals("update")) {
            RecordId recordId = repository.getIdGenerator().fromString(id);
            Record record = postAction.getEntity();

            if (record.getId() != null && !record.getId().equals(recordId)) {
                throw new ResourceException("Record id in submitted record does not match record id in URI.",
                        BAD_REQUEST.getStatusCode());
            }

            record.setId(recordId);

            ImportResult<Record> result;
            try {
                result = RecordImport.importRecord(record, ImportMode.UPDATE, postAction.getConditions(), table);
            } catch (Exception e) {
                throw new ResourceException(e, INTERNAL_SERVER_ERROR.getStatusCode());
            }

            // TODO record we respond with should be full record or be limited to user-specified field list
            record = result.getEntity();
            Response response;

            ImportResultType resultType = result.getResultType();
            switch (resultType) {
                case CANNOT_UPDATE_DOES_NOT_EXIST:
                    throw new ResourceException("Record not found: " + recordId, NOT_FOUND.getStatusCode());
                case UPDATED:
                case UP_TO_DATE:
                    response = Response.ok(Entity.create(record, uriInfo)).build();
                    break;
                case CONDITION_CONFLICT:
                    response = Response.status(CONFLICT.getStatusCode()).entity(Entity.create(record, uriInfo)).build();
                    break;
                default:
                    throw new RuntimeException("Unexpected import result type: " + resultType);
            }

            return response;

        } else if (postAction.getAction().equals("delete")) {
            RecordId recordId = repository.getIdGenerator().fromString(id);
            try {
                Record record = table.delete(recordId, postAction.getConditions());
                if (record != null && record.getResponseStatus() == ResponseStatus.CONFLICT) {
                    return Response.status(CONFLICT.getStatusCode()).entity(Entity.create(record, uriInfo)).build();
                }
View Full Code Here

        LTable table = getTable(uriInfo);
        return delete(id, repository, table);
    }

    public Response delete(String id, LRepository repository, LTable table) {
        RecordId recordId = repository.getIdGenerator().fromString(id);
        try {
            table.delete(recordId);
        } catch (RecordNotFoundException e) {
            throw new ResourceException(e, NOT_FOUND.getStatusCode());
        } catch (Exception e) {
View Full Code Here

        lilyProxy.getLilyServerProxy().addIndexFromResource(repository.getRepositoryName(), indexName,
                SolrDefinition.DEFAULT_CORE_NAME, "org/lilyproject/lilyservertestfw/test/lilytestutility_indexerconf.xml",
                60000L);

        // Create an extra record
        RecordId recordId = null;
        int i = 0;
        try {
            while (true) {
                recordId = repository.getIdGenerator().newRecordId("MyRecord" + i++);
                Record read = repository.read(recordId);
                System.out.println("[KeepDataTest] Record already exists: " + recordId);
            }
        } catch (RecordNotFoundException e) {
            System.out.println("[KeepDataTest] Record does not exist yet. Create it: " + recordId);
            Record record = repository.newRecord(recordId);
            record.setRecordType(RECORDTYPE1);
            record.setField(FIELD1, "name1");
            record = repository.create(record);
        }
        Record record = repository.read(recordId);
        Assert.assertEquals("name1", (String) record.getField(FIELD1));

        // Wait for messages to be processed
        Assert.assertTrue("Processing events took too long", lilyProxy.getHBaseProxy().waitOnSepIdle(60000L));
        lilyProxy.getSolrProxy().commit();

        // Query Solr and assert all previously created records are indexed
        List<RecordId> recordIds = querySolr("name1");

        for (RecordId recordId2 : recordIds) {
            System.out.println("[KeepDataTest] RecordId from query : " + recordId2);
        }
        for (int j = 0; j < i; j++) {
            RecordId expectedRecordId = repository.getIdGenerator().newRecordId("MyRecord" + j);
            Assert.assertTrue("Expected " + expectedRecordId + " to be in query result", recordIds.contains(expectedRecordId));
        }
    }
View Full Code Here

        if (testRecord == null) {
            return;
        }

        TestRecordType recordTypeToUpdate = testRecord.getRecordType();
        RecordId recordId = testRecord.getRecordId();
        ActionResult result = updateRecord(recordTypeToUpdate, recordId);
        report(result.success, result.duration, "U", null);
        if (result.success) {
            testActionContext.records.addRecord(destination, new TestRecord(((Record)result.object).getId(),
                    recordTypeToUpdate));
View Full Code Here

        long before = System.currentTimeMillis();
        try {
            checkCreatePreconditions(record);

            RecordId recordId = record.getId();
            if (recordId == null) {
                recordId = idGenerator.newRecordId();
            }

            byte[] rowId = recordId.toBytes();

            try {
                FieldTypes fieldTypes = typeManager.getFieldTypesSnapshot();

                long version = 1L;
View Full Code Here

    @Override
    public Record update(Record record, boolean updateVersion, boolean useLatestRecordType,
                         List<MutationCondition> conditions) throws RepositoryException, InterruptedException {

        long before = System.currentTimeMillis();
        RecordId recordId = record.getId();
        try {
            if (recordId == null) {
                throw new InvalidRecordException("The recordId cannot be null for a record to be updated.",
                        record.getId());
            }
View Full Code Here

TOP

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

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.