Example usage for com.mongodb BasicDBObject get

List of usage examples for com.mongodb BasicDBObject get

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject get.

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value from this object

Usage

From source file:com.effektif.mongo.MongoReaderHelper.java

License:Apache License

protected static String getString(BasicDBObject dbObject, String fieldName) {
    return (String) dbObject.get(fieldName);
}

From source file:com.effektif.mongo.MongoReaderHelper.java

License:Apache License

protected static Long getLong(BasicDBObject dbObject, String fieldName) {
    Object object = dbObject.get(fieldName);
    if (object == null) {
        return null;
    }// www  .  j av a  2  s .  c  o m
    if (object instanceof Long) {
        return (Long) object;
    }
    return ((Number) object).longValue();
}

From source file:com.effektif.mongo.MongoReaderHelper.java

License:Apache License

protected static Boolean getBoolean(BasicDBObject dbObject, String fieldName) {
    return (Boolean) dbObject.get(fieldName);
}

From source file:com.effektif.mongo.MongoReaderHelper.java

License:Apache License

protected static LocalDateTime getTime(BasicDBObject dbObject, String fieldName) {
    Date date = (Date) dbObject.get(fieldName);
    return (date != null ? new LocalDateTime(date) : null);
}

From source file:com.effektif.mongo.MongoWorkflowInstanceStore.java

License:Apache License

public WorkflowInstanceImpl readWorkflowInstanceImpl(BasicDBObject dbWorkflowInstance) {
    if (dbWorkflowInstance == null) {
        return null;
    }//w w  w .j  a v a  2s.co  m
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.id = readWorkflowInstanceId(dbWorkflowInstance, _ID);
    workflowInstance.businessKey = readString(dbWorkflowInstance, BUSINESS_KEY);

    Object workflowIdObject = readObject(dbWorkflowInstance, WORKFLOW_ID);

    // workflowId is ObjectId in the MongoConfiguration
    // workflowId is String in the MongoMemoryConfiguration
    // The code is written to work dynamically (and not according to the 
    // configuration field storeWorkflowIdsAsStrings) because the test 
    // suite cleanup might encounter workflow instances created by the other engine
    WorkflowId workflowId = new WorkflowId(workflowIdObject.toString());
    WorkflowImpl workflow = workflowEngine.getWorkflowImpl(workflowId);
    if (workflow == null) {
        throw new RuntimeException("No workflow for instance " + workflowInstance.id);
    }

    workflowInstance.workflow = workflow;
    workflowInstance.workflowInstance = workflowInstance;
    workflowInstance.scope = workflow;
    workflowInstance.configuration = configuration;
    workflowInstance.callingWorkflowInstanceId = readWorkflowInstanceId(dbWorkflowInstance,
            CALLING_WORKFLOW_INSTANCE_ID);
    workflowInstance.callingActivityInstanceId = readString(dbWorkflowInstance, CALLING_ACTIVITY_INSTANCE_ID);
    workflowInstance.nextActivityInstanceId = readLong(dbWorkflowInstance, NEXT_ACTIVITY_INSTANCE_ID);
    workflowInstance.nextVariableInstanceId = readLong(dbWorkflowInstance, NEXT_VARIABLE_INSTANCE_ID);
    workflowInstance.lock = readLock((BasicDBObject) dbWorkflowInstance.get(LOCK));
    workflowInstance.jobs = readJobs(readList(dbWorkflowInstance, JOBS));

    Map<ActivityInstanceImpl, String> allActivityIds = new HashMap<>();
    readScopeImpl(workflowInstance, dbWorkflowInstance, allActivityIds);
    resolveActivityReferences(workflowInstance, workflow, allActivityIds);

    workflowInstance.work = readWork(dbWorkflowInstance, WORK, workflowInstance);
    workflowInstance.workAsync = readWork(dbWorkflowInstance, WORK_ASYNC, workflowInstance);
    workflowInstance.properties = readObjectMap(dbWorkflowInstance, PROPERTIES);
    workflowInstance.setProperty(ORGANIZATION_ID, readObject(dbWorkflowInstance, ORGANIZATION_ID));

    copyProperties(dbWorkflowInstance, workflowInstance);

    return workflowInstance;
}

From source file:com.effektif.mongo.MongoWorkflowInstanceStore.java

License:Apache License

/**
 * Reads database fields (that do not have Java fields) and copies them to workflow instance properties.
 * This makes it possible to write non-standard fields to the database and read them from properties.
 *///from  w w w  .  j  a  v a  2s. co  m
private void copyProperties(BasicDBObject dbWorkflowInstance, WorkflowInstanceImpl workflowInstance) {
    if (dbWorkflowInstance == null || workflowInstance == null) {
        return;
    }
    Set<String> invalidPropertyKeys = Extensible.getInvalidPropertyKeys(WorkflowInstance.class);
    // Map<String,?> mappedBeanFields = mongoMapper.write(workflowInstance.toWorkflowInstance());
    for (String fieldName : dbWorkflowInstance.keySet()) {
        boolean property = !invalidPropertyKeys.contains(fieldName);
        if (property) {
            workflowInstance.setProperty(fieldName, dbWorkflowInstance.get(fieldName));
        }
    }
}

From source file:com.effektif.mongo.MongoWorkflowInstanceStore.java

License:Apache License

@SuppressWarnings("unchecked")
protected Queue<ActivityInstanceImpl> readWork(BasicDBObject dbWorkflowInstance, String fieldName,
        WorkflowInstanceImpl workflowInstance) {
    Queue<ActivityInstanceImpl> workQueue = null;
    List<String> workActivityInstanceIds = (List<String>) dbWorkflowInstance.get(fieldName);
    if (workActivityInstanceIds != null) {
        workQueue = new LinkedList<>();
        for (String workActivityInstanceId : workActivityInstanceIds) {
            ActivityInstanceImpl workActivityInstance = workflowInstance
                    .findActivityInstance(workActivityInstanceId);
            workQueue.add(workActivityInstance);
        }/*from   w  w w . ja v a 2s  .  c o  m*/
    }
    return workQueue;
}

From source file:com.effektif.mongo.MongoWorkflowStore.java

License:Apache License

@Override
public WorkflowId findLatestWorkflowIdBySource(String sourceWorkflowId) {
    Exceptions.checkNotNullParameter(sourceWorkflowId, "sourceWorkflowId");
    Query query = new Query().equal(SOURCE_WORKFLOW_ID, sourceWorkflowId).orderDesc(CREATE_TIME).page(0, 1);
    Fields fields = new Fields().include(_ID);
    BasicDBObject dbWorkflow = workflowsCollection.findOne("find-latest-workflow", query.get(), fields.get(),
            query.orderBy);//from w  w  w  . ja  v a  2  s.c  o  m
    return dbWorkflow != null ? new WorkflowId(dbWorkflow.get(_ID).toString()) : null;
}

From source file:com.effektif.mongo.MongoWriterHelper.java

License:Apache License

@SuppressWarnings("unchecked")
public void addListElementOpt(BasicDBObject dbParentScope, String fieldName, Object element) {
    if (element != null) {
        List<Object> list = (List<Object>) dbParentScope.get(fieldName);
        if (list == null) {
            list = new ArrayList<>();
            dbParentScope.put(fieldName, list);
        }//from w  w w. ja  v  a 2  s  . c  om
        list.add(element);
    }
}

From source file:com.entrib.mongoslate.visitor.stmt.translator.select.SelectStatementTranslator.java

License:Apache License

private Object buildMongoFind(SelectStatement selectStatement) {
    Find find = selectStatement.isDistinct() ? new Distinct() : new Find();

    find.setCollection(selectStatement.getCollection().getValueAsString());

    BasicDBObject keys = (BasicDBObject) selectStatement.getTagListExpression()
            .accept(expressionTranslatorVisitor);
    find.setKeys(keys);//from   w  w w .  ja  va2  s. com

    BasicDBObject query = (BasicDBObject) selectStatement.getLogicalExpression()
            .accept(expressionTranslatorVisitor);
    find.setQuery(query);

    OrderByListExpression orderByExpression = selectStatement.getOrderByListExpression();
    if (orderByExpression != null) {
        BasicDBObject sort = (BasicDBObject) orderByExpression.accept(expressionTranslatorVisitor);
        find.setSort(sort);
    }

    LimitExpression limitExpression = selectStatement.getLimitExpression();
    if (limitExpression != null) {
        BasicDBObject skipAndLimit = (BasicDBObject) limitExpression.accept(expressionTranslatorVisitor);
        find.setSkip((Integer) ((IntValue) skipAndLimit.get("skip")).getValueAsObject());
        find.setLimit((Integer) ((IntValue) skipAndLimit.get("limit")).getValueAsObject());
    }

    return find;
}