当前位置: 首页>>代码示例>>Java>>正文


Java Key类代码示例

本文整理汇总了Java中org.mongodb.morphia.Key的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Key类属于org.mongodb.morphia包,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: _findUniqueKey

import org.mongodb.morphia.Key; //导入依赖的package包/类
protected Key<OvalDefinitions> _findUniqueKey(
                final OvalDefinitions oval_definitions
                )
{
    Query<OvalDefinitions>  q = createQuery();

    GeneratorType  generator = oval_definitions.getGenerator();
    q.filter( "generator.timestamp",      generator.getTimestamp() );
    q.filter( "generator.schema_version", generator.getSchemaVersion() );

    String  digest = oval_definitions.getDefinitionsDigest();
    q.filter( "definitions_digest", digest );

    _LOG_.debug( "find unique: query=" + q );
    Key<OvalDefinitions>  id = find( q ).getKey();
    _LOG_.debug( "find unique: id=" + id );

    return id;
}
 
开发者ID:nakamura5akihito,项目名称:six-oval,代码行数:20,代码来源:OvalDefinitionsDAO.java

示例2: _findExistingKey

import org.mongodb.morphia.Key; //导入依赖的package包/类
protected Key<OvalDefinitions> _findExistingKey(
                final OvalDefinitions oval_definitions
                )
{
    Query<OvalDefinitions>  q = createQuery();

    String  pid = oval_definitions.getPersistentID();
    if (pid == null) {
        GeneratorType  generator = oval_definitions.getGenerator();
        q.filter( "generator.timestamp",      generator.getTimestamp() );
        q.filter( "generator.schema_version", generator.getSchemaVersion() );

        String  digest = oval_definitions.getDefinitionsDigest();
        q.filter( "definitions_digest", digest );

    } else {
        q.filter( "_id", oval_definitions.getPersistentID() );
    }

    _LOG_.debug( "find existing key: query=" + q );
    Key<OvalDefinitions>  key = find( q ).getKey();
    _LOG_.debug( "find existing key: found key=" + key );

    return key;
}
 
开发者ID:nakamura5akihito,项目名称:six-oval,代码行数:26,代码来源:OvalDefinitionsDAO.java

示例3: save

import org.mongodb.morphia.Key; //导入依赖的package包/类
@Override
    public Key<OvalVariables> save(
                    final OvalVariables oval_variables
                    )
    {
        String  pid = oval_variables.getPersistentID();
        if (pid == null) {
            pid = UUID.randomUUID().toString();
            oval_variables.setPersistentID( pid );
        }

        VariablesType  variables = oval_variables.getVariables();
        if (variables != null) {
            DAO<VariableType, String>  dao = _getForwardingDAO( VariableType.class );
            for (VariableType  variable : variables.getVariable()) {
//                variable.ovalSetGenerator( oval_variables.getGenerator() );
                dao.save( variable );
            }
        }

        return super.save( oval_variables );
    }
 
开发者ID:nakamura5akihito,项目名称:six-oval,代码行数:23,代码来源:OvalVariablesDAO.java

示例4: fromDBObject

import org.mongodb.morphia.Key; //导入依赖的package包/类
@Override
public void fromDBObject(final DBObject dbObject, final MappedField mf, final Object entity, final EntityCache cache, final Mapper mapper) {

    final Key key = extractKey(mapper, mf, (DBObject) dbObject.get(mf.getNameToStore()));
    if (key != null && cache.getEntity(key) != null) {
        final Object object = cache.getEntity(key);
        mf.setFieldValue(entity, object);
    } else if (this.customMappers.containsKey(mf.getType())) {
        this.customMappers.get(mf.getType()).fromDBObject(dbObject, mf, entity, cache, mapper);
    } else if (isAwkwardMap(mf)) {
        this.awkwardMapper.fromDBObject(dbObject, mf, entity, cache, mapper);
    } else {
        // the first two conditions (isMap and isMultipleValues) are part of the hack to fix handling primitives
        if (mf.isMap()) {
            readMap(dbObject, mf, entity, cache, mapper);
        } else if (mf.isMultipleValues()) {
            readCollection(dbObject, mf, entity, cache, mapper);
        } else {
            mapper.getOptions().getEmbeddedMapper().fromDBObject(dbObject, mf, entity, cache, mapper);
        }

        this.serializationMethodInvoker.callReadResolve(mf.getFieldValue(entity));
    }


}
 
开发者ID:groupon,项目名称:DotCi,代码行数:27,代码来源:JenkinsEmbeddedMapper.java

示例5: insertData

import org.mongodb.morphia.Key; //导入依赖的package包/类
private void insertData() {
    final Datastore datastore = getDs();

    Channel sportChannel = new Channel("Sport channel");
    datastore.save(sportChannel);

    datastore.save(new Channel("Art channel"));

    Channel fitnessChannel = new Channel("Fitness channel");
    datastore.save(fitnessChannel);

    final List<Key<Channel>> followedChannels = new ArrayList<Key<Channel>>();
    followedChannels.add(datastore.getKey(sportChannel));
    followedChannels.add(datastore.getKey(fitnessChannel));

    datastore.save(new User("Roberto", datastore.getKey(sportChannel), followedChannels));
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:18,代码来源:KeyMappingTest.java

示例6: deref

import org.mongodb.morphia.Key; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T> Iterable<T> deref(Class<T> clazz, List<Key<T>> keys) {
    if (keys == null || keys.isEmpty()) {
        return Collections.emptyList();
    }
    ListMultimap<String, Key<T>> kindMap = getKindMap(clazz, keys);
    List<Iterable<T>> fetched = Lists.newLinkedList();
    for (String kind : kindMap.keySet()) {
        List<Key<T>> kindKeys = kindMap.get(kind);
        List<Object> objIds = new ArrayList<>(kindKeys.size());
        Class<T> kindClass = clazz == null
                             ? (Class<T>) kindKeys.get(0).getType()
                             : clazz;
        kindKeys.stream().map(Key::getId).forEach(objIds::add);
        fetched.add(getDatastore()
                .find(kindClass)
                .disableValidation()
                .field(Mapper.ID_KEY)
                .in(objIds)
                .fetch());
    }
    return Iterables.concat(fetched);
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:24,代码来源:MongoDB.java

示例7: getKindMap

import org.mongodb.morphia.Key; //导入依赖的package包/类
protected <T> ListMultimap<String, Key<T>> getKindMap(Class<T> clazz,
                                                      List<Key<T>> keys) {
    ListMultimap<String, Key<T>> kindMap = LinkedListMultimap.create();
    String clazzKind = (clazz == null) ? null : getMapper()
            .getCollectionName(clazz);
    for (Key<T> key : keys) {
        getMapper().updateCollection(key);
        String kind = key.getCollection();

        if (clazzKind != null && !kind.equals(clazzKind)) {
            throw new IllegalArgumentException(String.format(
                    "Types are not equal (%s!=%s) for key and method parameter clazz",
                    clazz, key.getType()));
        }
        kindMap.put(kind, key);
    }
    return kindMap;
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:19,代码来源:MongoDB.java

示例8: delete

import org.mongodb.morphia.Key; //导入依赖的package包/类
@Override
public void delete(User u, boolean deleteContent) {
    MongoUser user = (MongoUser) u;
    if (deleteContent) {
        trackDao.deleteUser(user);
        measurementDao.deleteUser(user);
    } else {
        trackDao.removeUser(user);
        measurementDao.removeUser(user);
    }
    groupDao.removeUser(user);
    fuelingDao.removeUser(user);
    Key<MongoUser> userRef = key(user);
    UpdateResults result = update(
            q().field(MongoUser.FRIENDS).hasThisElement(userRef),
            up().removeAll(MongoUser.FRIENDS, userRef));
    if (result.getWriteResult() != null && !result.getWriteResult().wasAcknowledged()) {
        log.error("Error removing user {} as friend: {}",
                u, result.getWriteResult());
    } else {
        log.debug("Removed user {} from {} friend lists",
                u, result.getUpdatedCount());
    }
    delete(user.getName());
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:26,代码来源:MongoUserDao.java

示例9: getFriendRefs

import org.mongodb.morphia.Key; //导入依赖的package包/类
public Set<Key<MongoUser>> getFriendRefs(User user) {
    MongoUser u = (MongoUser) user;
    Set<Key<MongoUser>> friendRefs = u.getFriends();
    if (friendRefs == null) {
        MongoUser userWithFriends = q()
                .field(MongoUser.NAME).equal(u.getName())
                .retrievedFields(true, MongoUser.FRIENDS).get();
        if (userWithFriends != null) {
            friendRefs = userWithFriends.getFriends();
        }
    }
    if (friendRefs == null) {
        friendRefs = Collections.emptySet();
    }
    return friendRefs;
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:17,代码来源:MongoUserDao.java

示例10: getBidirectionalFriendRefs

import org.mongodb.morphia.Key; //导入依赖的package包/类
public Set<Key<MongoUser>> getBidirectionalFriendRefs(User user) {
    final Set<Key<MongoUser>> friendRefs = getFriendRefs(user);
    final Set<String> ids = Sets.newHashSetWithExpectedSize(friendRefs.size());
    for (Key<MongoUser> key : friendRefs) {
        ids.add((String) key.getId());
    }

    if (ids.isEmpty()) {
        return Sets.newHashSet();
    }

    final Iterable<Key<MongoUser>> filtered = q()
            .field(MongoUser.NAME).in(ids)
            .field(MongoUser.FRIENDS).hasThisElement(key(user))
            .fetchKeys();
    return Sets.newHashSet(filtered);
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:18,代码来源:MongoUserDao.java

示例11: testExternalMapping

import org.mongodb.morphia.Key; //导入依赖的package包/类
@Test
public void testExternalMapping() throws Exception {
    final Mapper mapper = getMorphia().getMapper();
    final CloneMapper helper = new CloneMapper(mapper);
    helper.map(Skeleton.class, EntityWithNoAnnotations.class);
    final MappedClass mc = mapper.getMappedClass(EntityWithNoAnnotations.class);
    mc.update();
    assertNotNull(mc.getIdField());
    assertNotNull(mc.getEntityAnnotation());
    assertEquals("special", mc.getEntityAnnotation().value());

    EntityWithNoAnnotations ent = new EntityWithNoAnnotations();
    ent.id = "test";
    final Key<EntityWithNoAnnotations> k = getDs().save(ent);
    assertNotNull(k);
    ent = getDs().get(EntityWithNoAnnotations.class, "test");
    assertNotNull(ent);
    assertEquals("test", ent.id);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:20,代码来源:ExternalMapperExtTest.java

示例12: getKey

import org.mongodb.morphia.Key; //导入依赖的package包/类
private Key<?> getKey(final Object entity, final Mapper mapper) {
    try {
        if (entity instanceof ProxiedEntityReference) {
            final ProxiedEntityReference proxy = (ProxiedEntityReference) entity;
            return proxy.__getKey();
        }
        final MappedClass mappedClass = mapper.getMappedClass(entity);
        Object id = mappedClass.getIdField().get(entity);
        if (id == null) {
            throw new MappingException("@Id field cannot be null!");
        }
        return new Key(mappedClass.getClazz(), mappedClass.getCollectionName(), id);
    } catch (IllegalAccessException iae) {
        throw new RuntimeException(iae);
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:17,代码来源:ReferenceMapper.java

示例13: testInQueryByKey

import org.mongodb.morphia.Key; //导入依赖的package包/类
@Test
public void testInQueryByKey() throws Exception {
    checkMinServerVersion(2.5);
    final HasRef hr = new HasRef();
    List<Key<ReferencedEntity>> refs = new ArrayList<Key<ReferencedEntity>>();
    for (int x = 0; x < 10; x++) {
        final ReferencedEntity re = new ReferencedEntity("" + x);
        getDs().save(re);
        refs.add(new Key<ReferencedEntity>(ReferencedEntity.class,
                                           getMorphia().getMapper().getCollectionName(ReferencedEntity.class),
                                           re.getId()));
    }
    hr.ref = refs.get(0);

    getDs().save(hr);

    Query<HasRef> query = getDs().find(HasRef.class).field("ref").in(refs);
    try {
        Assert.assertEquals(1, query.asList().size());
    } catch (MongoException e) {
        LOG.debug("query = " + query);
        throw e;
    }
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:25,代码来源:QueryInTest.java

示例14: getKey

import org.mongodb.morphia.Key; //导入依赖的package包/类
/**
 * Gets the Key for an entity and a specific collection
 *
 * @param entity     the entity to process
 * @param collection the collection to use in the Key rather than the mapped collection as defined on the entity's class
 * @param <T>        the type of the entity
 * @return the Key
 */
public <T> Key<T> getKey(final T entity, final String collection) {
    T unwrapped = entity;
    if (unwrapped instanceof ProxiedEntityReference) {
        final ProxiedEntityReference proxy = (ProxiedEntityReference) unwrapped;
        return (Key<T>) proxy.__getKey();
    }

    unwrapped = ProxyHelper.unwrap(unwrapped);
    if (unwrapped instanceof Key) {
        return (Key<T>) unwrapped;
    }

    final Object id = getId(unwrapped);
    final Class<T> aClass = (Class<T>) unwrapped.getClass();
    return id == null ? null : new Key<T>(aClass, collection, id);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:25,代码来源:Mapper.java

示例15: keyToDBRef

import org.mongodb.morphia.Key; //导入依赖的package包/类
/**
 * Converts a Key to a DBRef
 *
 * @param key the Key to convert
 * @return the DBRef
 */
public DBRef keyToDBRef(final Key key) {
    if (key == null) {
        return null;
    }
    if (key.getType() == null && key.getCollection() == null) {
        throw new IllegalStateException("How can it be missing both?");
    }
    if (key.getCollection() == null) {
        key.setCollection(getCollectionName(key.getType()));
    }

    Object id = key.getId();
    if (isMapped(id.getClass())) {
        id = toMongoObject(id, true);
    }
    return new DBRef(key.getCollection(), id);
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:24,代码来源:Mapper.java


注:本文中的org.mongodb.morphia.Key类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。