Package org.bson.types

Examples of org.bson.types.CodeWScope


    @Override
    public Object getValue() {
        String code = getStringFieldValue(Item.value);
        String scope = getStringFieldValue(Item.scope);
        if (!scope.isEmpty())
            return new CodeWScope(code, (BSONObject) JSON.parse(scope));
        return new Code(code);
    }
View Full Code Here


    @Test
    public void testWhereCodeWScopeQuery() throws Exception {
        ds.save(new PhotoWithKeywords());
//        CodeWScope hasKeyword = new CodeWScope("for (kw in this.keywords) { if(kw.keyword == kwd) return true; } return false;", new BasicDBObject("kwd","california"));
        CodeWScope hasKeyword = new CodeWScope("this.keywords != null", new BasicDBObject());
        assertNotNull(ds.find(PhotoWithKeywords.class).where(hasKeyword).get());
    }
View Full Code Here

    }

    @Test
    public void testWhereWithInvalidStringQuery() throws Exception {
        ds.save(new PhotoWithKeywords());
        CodeWScope hasKeyword = new CodeWScope("keywords != null", new BasicDBObject());
    try {
      // must fail
          assertNotNull(ds.find(PhotoWithKeywords.class).where(hasKeyword.getCode()).get());
      Assert.fail("Invalid javascript magically isn't invalid anymore?");
    } catch (MongoInternalException e) {
    } catch (MongoException e) {
      // fine
    }
View Full Code Here

        assertNull( c.findOne() );

        c.save( BasicDBObjectBuilder.start().add( "a" , 1 ).get() );
        assertNotNull( c.findOne() != null );

        assertNotNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , new CodeWScope( "this.a == x" , new BasicDBObject( "x" , 1 )  ) ).get() ) );
        assertNull( c.findOne( BasicDBObjectBuilder.start().add( "$where" , new CodeWScope( "this.a == x" , new BasicDBObject( "x" , 2 )  ) ).get() ) );


        c.drop();
        BasicDBObject in = new BasicDBObject();
        in.put( "_id" , 1 );
        in.put( "a" , new Code("x=5") );
        in.put( "b" , new CodeWScope( "x=5" , new BasicDBObject( "x" , 2 ) ) );
        c.insert( in );

        DBObject out = c.findOne();

        assertEquals( in , out );
View Full Code Here

        _put( name , new Code( code ) );
    }

    @Override
    public void gotCodeWScope(final String name, final String code, final Object scope) {
        _put( name , new CodeWScope( code, (BSONObject)scope ) );
    }
View Full Code Here

            case BSON.CODE_W_SCOPE:
                int strsize = _input.getInt( record.valueOffset + 4 );
                String code = _input.getUTF8String( record.valueOffset + 4 );
                BSONObject scope =
                        (BSONObject) _callback.createObject( _input.array(), record.valueOffset + 4 + 4 + strsize );
                return new CodeWScope( code, scope );
            case BSON.REF:
                int csize = _input.getInt( record.valueOffset );
                String ns = _input.getCString( record.valueOffset + 4 );
                int oidOffset = record.valueOffset + csize + 4;
                ObjectId oid = new ObjectId( _input.getIntBE( oidOffset ),
View Full Code Here

        DBDecoder decoder = DefaultDBDecoder.FACTORY.create();
        assertEquals(new BasicDBObject("b1", true)
                     .append("b2", false)
                     .append("a1", asList("danke", ""))
                     .append("d1", new BasicDBObject("do", 60.0).append("i32", 40).append("i64", Long.MAX_VALUE))
                     .append("js1", new CodeWScope("print x", new BasicDBObject("x", 1)))
                     .append("oid1", oid1),
                     decoder.decode(baos.toByteArray(), cleanupMongo.getDB("test").getCollection("testWriteRead")));
    }
View Full Code Here

        ObjectId oid = (ObjectId) a.get("oid");
        assert (oid.equals(new ObjectId("4d83ab3ea39562db9c1ae2ae")));
        DBRef ref = (DBRef) a.get("ref");
        assert (ref.equals(new DBRef(null, "test.test", new ObjectId("4d83ab59a39562db9c1ae2af"))));
        assert (a.get("code").equals(new Code("asdfdsa")));
        assert (a.get("codews").equals(new CodeWScope("ggggg", new BasicBSONObject())));
        assert (a.get("ts").equals(new BSONTimestamp(1300474885, 10)));
        assert (a.get("uuid").equals(UUID.fromString("60f65152-6d4a-4f11-9c9b-590b575da7b5")));
        String json2 = JSON.serialize(a);
        BasicDBObject b = (BasicDBObject) JSON.parse(json2);
        a.equals(b);
View Full Code Here

        serializer.serialize(testObj, buf);
        assertEquals(buf.toString(), "{ \"code\" : { \"$code\" : \"test code\"}}");
       
        // test  CODE_W_SCOPE
        testObj = new BasicDBObject("scope", "scope of code");
        CodeWScope codewscope = new CodeWScope("test code", testObj);
        buf = new StringBuilder();
        serializer.serialize(codewscope, buf);
        assertEquals(buf.toString(), "{ \"$code\" : \"test code\" , \"$scope\" : { \"scope\" : \"scope of code\"}}");
       
        // test  DATE
View Full Code Here

        list.add("val1");
        StringBuilder buf = new StringBuilder();
        serializer.serialize(list, buf);
        assertEquals(buf.toString(), "[val1]");
       
        CodeWScope code  = new CodeWScope("code_test", null);
        buf = new StringBuilder();
        serializer.serialize(code, buf);
        assertEquals(buf.toString(), "serialized as Object class");
    }
View Full Code Here

TOP

Related Classes of org.bson.types.CodeWScope

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.