本文整理汇总了Java中io.realm.internal.Table类的典型用法代码示例。如果您正苦于以下问题:Java Table类的具体用法?Java Table怎么用?Java Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Table类属于io.realm.internal包,在下文中一共展示了Table类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import io.realm.internal.Table; //导入依赖的package包/类
public static long insert(Realm realm, some.test.Simple object, Map<RealmModel,Long> cache) {
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
return ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex();
}
Table table = realm.getTable(some.test.Simple.class);
long tableNativePtr = table.getNativePtr();
SimpleColumnInfo columnInfo = (SimpleColumnInfo) realm.getSchema().getColumnInfo(some.test.Simple.class);
long rowIndex = OsObject.createRow(table);
cache.put(object, rowIndex);
String realmGet$name = ((SimpleRealmProxyInterface) object).realmGet$name();
if (realmGet$name != null) {
Table.nativeSetString(tableNativePtr, columnInfo.nameIndex, rowIndex, realmGet$name, false);
}
Table.nativeSetLong(tableNativePtr, columnInfo.ageIndex, rowIndex, ((SimpleRealmProxyInterface) object).realmGet$age(), false);
return rowIndex;
}
示例2: insertOrUpdate
import io.realm.internal.Table; //导入依赖的package包/类
public static long insertOrUpdate(Realm realm, some.test.Simple object, Map<RealmModel,Long> cache) {
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
return ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex();
}
Table table = realm.getTable(some.test.Simple.class);
long tableNativePtr = table.getNativePtr();
SimpleColumnInfo columnInfo = (SimpleColumnInfo) realm.getSchema().getColumnInfo(some.test.Simple.class);
long rowIndex = OsObject.createRow(table);
cache.put(object, rowIndex);
String realmGet$name = ((SimpleRealmProxyInterface) object).realmGet$name();
if (realmGet$name != null) {
Table.nativeSetString(tableNativePtr, columnInfo.nameIndex, rowIndex, realmGet$name, false);
} else {
Table.nativeSetNull(tableNativePtr, columnInfo.nameIndex, rowIndex, false);
}
Table.nativeSetLong(tableNativePtr, columnInfo.ageIndex, rowIndex, ((SimpleRealmProxyInterface) object).realmGet$age(), false);
return rowIndex;
}
示例3: insert
import io.realm.internal.Table; //导入依赖的package包/类
public static void insert(Realm realm, Iterator<? extends RealmModel> objects, Map<RealmModel,Long> cache) {
Table table = realm.getTable(some.test.Booleans.class);
long tableNativePtr = table.getNativePtr();
BooleansColumnInfo columnInfo = (BooleansColumnInfo) realm.getSchema().getColumnInfo(some.test.Booleans.class);
some.test.Booleans object = null;
while (objects.hasNext()) {
object = (some.test.Booleans) objects.next();
if (cache.containsKey(object)) {
continue;
}
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
cache.put(object, ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex());
continue;
}
long rowIndex = OsObject.createRow(table);
cache.put(object, rowIndex);
Table.nativeSetBoolean(tableNativePtr, columnInfo.doneIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$done(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.isReadyIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$isReady(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.mCompletedIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$mCompleted(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.anotherBooleanIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$anotherBoolean(), false);
}
}
示例4: insertOrUpdate
import io.realm.internal.Table; //导入依赖的package包/类
public static void insertOrUpdate(Realm realm, Iterator<? extends RealmModel> objects, Map<RealmModel,Long> cache) {
Table table = realm.getTable(some.test.Booleans.class);
long tableNativePtr = table.getNativePtr();
BooleansColumnInfo columnInfo = (BooleansColumnInfo) realm.getSchema().getColumnInfo(some.test.Booleans.class);
some.test.Booleans object = null;
while (objects.hasNext()) {
object = (some.test.Booleans) objects.next();
if (cache.containsKey(object)) {
continue;
}
if (object instanceof RealmObjectProxy && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm() != null && ((RealmObjectProxy) object).realmGet$proxyState().getRealm$realm().getPath().equals(realm.getPath())) {
cache.put(object, ((RealmObjectProxy) object).realmGet$proxyState().getRow$realm().getIndex());
continue;
}
long rowIndex = OsObject.createRow(table);
cache.put(object, rowIndex);
Table.nativeSetBoolean(tableNativePtr, columnInfo.doneIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$done(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.isReadyIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$isReady(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.mCompletedIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$mCompleted(), false);
Table.nativeSetBoolean(tableNativePtr, columnInfo.anotherBooleanIndex, rowIndex, ((BooleansRealmProxyInterface) object).realmGet$anotherBoolean(), false);
}
}
示例5: get
import io.realm.internal.Table; //导入依赖的package包/类
<E extends RealmModel> E get(@Nullable Class<E> clazz, @Nullable String dynamicClassName, long rowIndex) {
final boolean isDynamicRealmObject = dynamicClassName != null;
// 'clazz' is non-null when 'dynamicClassName' is null.
//noinspection ConstantConditions
final Table table = isDynamicRealmObject ? getSchema().getTable(dynamicClassName) : getSchema().getTable(clazz);
E result;
if (isDynamicRealmObject) {
@SuppressWarnings("unchecked")
E dynamicObj = (E) new DynamicRealmObject(this,
(rowIndex != Table.NO_MATCH) ? table.getCheckedRow(rowIndex) : InvalidRow.INSTANCE);
result = dynamicObj;
} else {
result = configuration.getSchemaMediator().newInstance(clazz, this,
(rowIndex != Table.NO_MATCH) ? table.getUncheckedRow(rowIndex) : InvalidRow.INSTANCE,
getSchema().getColumnInfo(clazz), false, Collections.<String>emptyList());
}
return result;
}
示例6: Realm
import io.realm.internal.Table; //导入依赖的package包/类
/**
* The constructor is private to enforce the use of the static one.
*
* @param cache the {@link RealmCache} associated to this Realm instance.
* @throws IllegalArgumentException if trying to open an encrypted Realm with the wrong key.
*/
private Realm(RealmCache cache) {
super(cache, createExpectedSchemaInfo(cache.getConfiguration().getSchemaMediator()));
schema = new ImmutableRealmSchema(this,
new ColumnIndices(configuration.getSchemaMediator(), sharedRealm.getSchemaInfo()));
// FIXME: This is to work around the different behaviour between the read only Realms in the Object Store and
// in current java implementation. Opening a read only Realm with some missing schemas is allowed by Object
// Store and realm-cocoa. In that case, any query based on the missing schema should just return an empty
// results. Fix this together with https://github.com/realm/realm-java/issues/2953
if (configuration.isReadOnly()) {
RealmProxyMediator mediator = configuration.getSchemaMediator();
Set<Class<? extends RealmModel>> classes = mediator.getModelClasses();
for (Class<? extends RealmModel> clazz : classes) {
String tableName = Table.getTableNameForClass(mediator.getSimpleClassName(clazz));
if (!sharedRealm.hasTable(tableName)) {
sharedRealm.close();
throw new RealmMigrationNeededException(configuration.getPath(),
String.format(Locale.US, "Cannot open the read only Realm. '%s' is missing.",
Table.getClassNameForTable(tableName)));
}
}
}
}
示例7: createObjectInternal
import io.realm.internal.Table; //导入依赖的package包/类
/**
* Same as {@link #createObject(Class)} but this does not check the thread.
*
* @param clazz the Class of the object to create.
* @param acceptDefaultValue if {@code true}, default value of the object will be applied and
* if {@code false}, it will be ignored.
* @return the new object.
* @throws RealmException if the primary key is defined in the model class or an object cannot be created.
*/
// Called from proxy classes.
<E extends RealmModel> E createObjectInternal(
Class<E> clazz,
boolean acceptDefaultValue,
List<String> excludeFields) {
Table table = schema.getTable(clazz);
// Checks and throws the exception earlier for a better exception message.
if (OsObjectStore.getPrimaryKeyForObject(
sharedRealm, configuration.getSchemaMediator().getSimpleClassName(clazz)) != null) {
throw new RealmException(String.format(Locale.US, "'%s' has a primary key, use" +
" 'createObject(Class<E>, Object)' instead.", table.getClassName()));
}
return configuration.getSchemaMediator().newInstance(clazz, this,
OsObject.create(table),
schema.getColumnInfo(clazz),
acceptDefaultValue, excludeFields);
}
示例8: setObject
import io.realm.internal.Table; //导入依赖的package包/类
/**
* Sets a reference to another object on the given field.
*
* @param fieldName field name.
* @param value object to link to.
* @throws IllegalArgumentException if field name doesn't exist, it doesn't link to other Realm objects, the type
* of DynamicRealmObject doesn't match or it belongs to a different Realm.
*/
public void setObject(String fieldName, @Nullable DynamicRealmObject value) {
proxyState.getRealm$realm().checkIfValid();
long columnIndex = proxyState.getRow$realm().getColumnIndex(fieldName);
if (value == null) {
proxyState.getRow$realm().nullifyLink(columnIndex);
} else {
if (value.proxyState.getRealm$realm() == null || value.proxyState.getRow$realm() == null) {
throw new IllegalArgumentException("Cannot link to objects that are not part of the Realm.");
}
if (proxyState.getRealm$realm() != value.proxyState.getRealm$realm()) {
throw new IllegalArgumentException("Cannot add an object from another Realm instance.");
}
Table table = proxyState.getRow$realm().getTable().getLinkTarget(columnIndex);
Table inputTable = value.proxyState.getRow$realm().getTable();
if (!table.hasSameSchema(inputTable)) {
throw new IllegalArgumentException(String.format(Locale.US,
"Type of object is wrong. Was %s, expected %s",
inputTable.getName(), table.getName()));
}
proxyState.getRow$realm().setLink(columnIndex, value.proxyState.getRow$realm().getIndex());
}
}
示例9: getTable
import io.realm.internal.Table; //导入依赖的package包/类
Table getTable(Class<? extends RealmModel> clazz) {
Table table = classToTable.get(clazz);
if (table != null) { return table; }
Class<? extends RealmModel> originalClass = Util.getOriginalModelClass(clazz);
if (isProxyClass(originalClass, clazz)) {
// If passed 'clazz' is the proxy, try again with model class.
table = classToTable.get(originalClass);
}
if (table == null) {
String tableName = Table.getTableNameForClass(
realm.getConfiguration().getSchemaMediator().getSimpleClassName(originalClass));
table = realm.getSharedRealm().getTable(tableName);
classToTable.put(originalClass, table);
}
if (isProxyClass(originalClass, clazz)) {
// 'clazz' is the proxy class for 'originalClass'.
classToTable.put(clazz, table);
}
return table;
}
示例10: getSchemaForClass
import io.realm.internal.Table; //导入依赖的package包/类
RealmObjectSchema getSchemaForClass(Class<? extends RealmModel> clazz) {
RealmObjectSchema classSchema = classToSchema.get(clazz);
if (classSchema != null) { return classSchema; }
Class<? extends RealmModel> originalClass = Util.getOriginalModelClass(clazz);
if (isProxyClass(originalClass, clazz)) {
// If passed 'clazz' is the proxy, try again with model class.
classSchema = classToSchema.get(originalClass);
}
if (classSchema == null) {
Table table = getTable(clazz);
classSchema = new ImmutableRealmObjectSchema(realm, this, table, getColumnInfo(originalClass));
classToSchema.put(originalClass, classSchema);
}
if (isProxyClass(originalClass, clazz)) {
// 'clazz' is the proxy class for 'originalClass'.
classToSchema.put(clazz, classSchema);
}
return classSchema;
}
示例11: setGetClassName
import io.realm.internal.Table; //导入依赖的package包/类
@Test
public void setGetClassName() {
final String[] validClassNames = {
TestHelper.getRandomString(1),
"Darby",
TestHelper.getRandomString(Table.CLASS_NAME_MAX_LENGTH)
};
if (type == ObjectSchemaType.IMMUTABLE) {
thrown.expect(UnsupportedOperationException.class);
DOG_SCHEMA.setClassName(validClassNames[0]);
return;
}
assertEquals("Dog", DOG_SCHEMA.getClassName());
for (String validClassName : validClassNames) {
DOG_SCHEMA.setClassName(validClassName);
assertEquals(validClassName, DOG_SCHEMA.getClassName());
assertTrue(realmSchema.contains(validClassName));
}
}
示例12: index
import io.realm.internal.Table; //导入依赖的package包/类
@Test
public void index() {
Table table = realm.getTable(AnnotationIndexTypes.class);
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexString")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexString")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexInt")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexInt")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexByte")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexByte")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexShort")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexShort")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexLong")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexLong")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexBoolean")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexBoolean")));
assertTrue(table.hasSearchIndex(table.getColumnIndex("indexDate")));
assertFalse(table.hasSearchIndex(table.getColumnIndex("notIndexDate")));
}
示例13: createTable
import io.realm.internal.Table; //导入依赖的package包/类
public static Table createTable(OsSharedRealm sharedRealm, String name, AdditionalTableSetup additionalSetup) {
boolean wasInTransaction = sharedRealm.isInTransaction();
if (!wasInTransaction) {
sharedRealm.beginTransaction();
}
try {
Table table = sharedRealm.createTable(name);
if (additionalSetup != null) {
additionalSetup.execute(table);
}
return table;
} catch (RuntimeException e) {
if (!wasInTransaction) {
sharedRealm.cancelTransaction();
}
throw e;
} finally {
if (!wasInTransaction && sharedRealm.isInTransaction()) {
sharedRealm.commitTransaction();
}
}
}
示例14: create
import io.realm.internal.Table; //导入依赖的package包/类
@Test
public void create() {
final String[] validClassNames = {
TestHelper.getRandomString(1),
"Darby",
TestHelper.getRandomString(Table.CLASS_NAME_MAX_LENGTH)
};
if (type == SchemaType.IMMUTABLE) {
thrown.expect(UnsupportedOperationException.class);
realmSchema.create(validClassNames[0]);
return;
}
for (String validClassName : validClassNames) {
realmSchema.create(validClassName);
assertTrue(realmSchema.contains(validClassName));
}
}
示例15: createWithPrimaryKeyField_invalidClassNameThrows
import io.realm.internal.Table; //导入依赖的package包/类
@Test
public void createWithPrimaryKeyField_invalidClassNameThrows() {
if (type == SchemaType.IMMUTABLE) {
return;
}
String[] invalidNames = { null, "", TestHelper.getRandomString(Table.CLASS_NAME_MAX_LENGTH + 1) };
for (String name : invalidNames) {
try {
realmSchema.createWithPrimaryKeyField(name, "pkField", int.class);
fail();
} catch (IllegalArgumentException ignored) {
}
assertFalse(String.format("'%s' failed", name), realmSchema.contains(name));
}
}