简体   繁体   English

OrientDB自定义类型存储为布尔值

[英]OrientDB Custom Type Storing as Boolean

I have been working with the OrientDB Object database lately, but I have hit an odd stumbling point. 我最近一直在使用OrientDB Object数据库,但是遇到了一个奇怪的绊脚石。 Some of the objects I want to store have BigIntegers as members and for some reason they are storing in the database as Boolean. 我要存储的某些对象将BigIntegers作为成员,并且由于某种原因它们以布尔值存储在数据库中。 I attempted to use the sample code found here . 我试图使用此处找到的示例代码。 I have a short sample and my Maven dependencies to demonstrate below, but here are my two questions: 我有一个简短的示例,下面将演示我的Maven依赖关系,但这是我的两个问题:

For the sake of getting this to work, why does this not work? 为了使它起作用,为什么这不起作用?

For the sake of better understanding, how is it coming up with Boolean? 为了更好地理解,它是如何与Boolean一起使用的?

Sample code: 样例代码:

package test;

import java.math.BigInteger;
import java.util.List;

import com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializer;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import com.orientechnologies.orient.object.serialization.OObjectSerializerContext;
import com.orientechnologies.orient.object.serialization.OObjectSerializerHelper;

public class HashmapIterationTest {
    public static void main(String[] args) throws Exception{
        Runner r = new Runner();
        r.run();
    }

public static class Runner{

    private OObjectDatabaseTx db;

    public void run() throws Exception{
        db = new OObjectDatabaseTx("plocal:c:/testodb");
        if(db.exists()){
            db.open("admin", "admin");
        }else{
            db.create();
        }

        //Hack for BigInteger
        OObjectSerializerContext serializerContext = new OObjectSerializerContext();
        serializerContext.bind(new OObjectSerializer<BigInteger, Long>() {
            public Long serializeFieldValue(Class<?> itype,  BigInteger iFieldValue) {
                return iFieldValue.longValue();
            }
            public  BigInteger unserializeFieldValue(Class<?> itype, Long iFieldValue) {
                return BigInteger.valueOf(iFieldValue);
            }
        });
        OObjectSerializerHelper.bindSerializerContext(null, serializerContext);

        db.getEntityManager().registerEntityClass(Parent.class);

        db.save(new Parent(5));

        List<Parent> result = db.query(new OSQLSynchQuery<Parent>("select from parent"));
        for(Parent p: result){
            System.out.println("Parent: " + p.getBigInt());
        }
    }
}

public static class Parent{
    BigInteger bigInt;
    public Parent(){
    }
    public Parent(int test){
        this.bigInt = BigInteger.valueOf(test);
    }
    public void setBigInt(BigInteger bigInt){
        this.bigInt = bigInt;
    }
    public BigInteger getBigInt(){
        return bigInt;
    }
    public String toString(){
        return "Parent: " + getBigInt();
    }
}

} }

Maven dependencies for version info: Maven对版本信息的依赖关系:

<dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orient-commons</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-core</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-object</artifactId>
        <version>1.5.1</version>
        <type>bundle</type>
    </dependency>

I got in touch with the guys on the OrientDB Google group and they answered this question for me, so I'll just leave this here for the sake of posterity. 我与OrientDB Google小组的成员取得了联系,他们为我回答了这个问题,因此为了后代,我将其留在这里。

The documentation I was reading was incorrect. 我正在阅读的文档不正确。 BigInteger is not supported as a custom data type. 不支持将BigInteger作为自定义数据类型。 Google Groups Discussion Google网上论坛讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM