基本的なアドホック クエリの例 に基づいて、基本的なアドホック クエリの例を作成しようとしました 。
しかし、整数値を挿入することはできません。このコードのせいだと思います:
private Class getStorageTypeAsClass() {
switch (getStorageType())
{
case STRING:
return String.class;
case INTEGER:
return BigInteger.class;
}
}
私のコード:
package playorm;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import com.alvazan.orm.api.base.Bootstrap;
import com.alvazan.orm.api.base.DbTypeEnum;
import com.alvazan.orm.api.base.NoSqlEntityManager;
import com.alvazan.orm.api.base.NoSqlEntityManagerFactory;
import com.alvazan.orm.api.z3api.NoSqlTypedSession;
import com.alvazan.orm.api.z8spi.KeyValue;
import com.alvazan.orm.api.z8spi.meta.DboColumnCommonMeta;
import com.alvazan.orm.api.z8spi.meta.DboColumnIdMeta;
import com.alvazan.orm.api.z8spi.meta.DboDatabaseMeta;
import com.alvazan.orm.api.z8spi.meta.DboTableMeta;
import com.alvazan.orm.api.z8spi.meta.TypedColumn;
import com.alvazan.orm.api.z8spi.meta.TypedRow;
public class PlayOrm {
private static NoSqlEntityManager mgr;
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
Map properties = new HashMap();
properties.put(Bootstrap.AUTO_CREATE_KEY, "create");
String clusterName = "Test Cluster";
String seeds = "localhost:9160";
String keyspace = "nosql";
Bootstrap.createAndAddBestCassandraConfiguration(properties, clusterName, keyspace, seeds);
NoSqlEntityManagerFactory factory = Bootstrap.create(DbTypeEnum.CASSANDRA, properties,null,null);
mgr = factory.createEntityManager();
DboDatabaseMeta metaDb = mgr.find(DboDatabaseMeta.class,
DboDatabaseMeta.META_DB_ROWKEY);
DboTableMeta meta = new DboTableMeta();
meta.setup(null, "MyEntity", false);
metaDb.addMetaClassDbo(meta);
DboColumnIdMeta idMeta = new DboColumnIdMeta();
idMeta.setup(meta, "idField", String.class, true);
mgr.put(idMeta);
DboColumnCommonMeta fieldDbo = new DboColumnCommonMeta();
fieldDbo.setup(meta, "firstname", String.class, true, false);
mgr.put(fieldDbo);
DboColumnCommonMeta fieldDbo2 = new DboColumnCommonMeta();
fieldDbo2.setup(meta, "lastname", Integer.class, true, false);
mgr.put(fieldDbo2);
mgr.put(meta);
mgr.flush();
NoSqlTypedSession session = mgr.getTypedSession();
for (int i = 0; i < 10000; i++) {
TypedRow typedRow = session.createTypedRow("MyEntity");
typedRow.addColumn("firstname", "harry");
//**THE PROBLEM**
typedRow.addColumn("lastname", new Integer(i));
typedRow.setRowKey(UUID.randomUUID().toString());
session.put("MyEntity", typedRow);
if(i > 1000 && (i % 10) == 0 ){
session.flush();
mgr.clear();
}
}
session.flush();
}
Integer.class を返すオプションはありません。したがって、整数コンバーターを構築することはできません。
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.alvazan.orm.impl.meta.data.NoSqlProxyImpl.invoke(NoSqlProxyImpl.java:96)
at com.alvazan.orm.api.z8spi.meta.DboColumnCommonMeta_$$_javassist_1.convertToStorage2(DboColumnCommonMeta_$$_javassist_1.java)
at com.alvazan.orm.api.z8spi.meta.TypedRow.addColumn(TypedRow.java:99)
at playorm.PlayOrm.main(PlayOrm.java:62)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.math.BigInteger
at com.alvazan.orm.api.z8spi.conv.Converters$BigIntegerConverter.convertToNoSqlImpl(Converters.java:89)
at com.alvazan.orm.api.z8spi.conv.Converters$BaseConverter.convertToNoSql(Converters.java:138)
at com.alvazan.orm.api.z8spi.meta.DboColumnMeta.convertToStorage2(DboColumnMeta.java:167)
at com.alvazan.orm.api.z8spi.meta.DboColumnCommonMeta_$$_javassist_1._d8convertToStorage2(DboColumnCommonMeta_$$_javassist_1.java)
... 8 more