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


Java RealmFieldType.STRING属性代码示例

本文整理汇总了Java中io.realm.RealmFieldType.STRING属性的典型用法代码示例。如果您正苦于以下问题:Java RealmFieldType.STRING属性的具体用法?Java RealmFieldType.STRING怎么用?Java RealmFieldType.STRING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在io.realm.RealmFieldType的用法示例。


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

示例1: createWithPrimaryKey

/**
 * Create an object in the given table which has a primary key column defined, and set the primary key with given
 * value.
 *
 * @param table the table where the object is created. This table must be atached to {@link OsSharedRealm}.
 * @return a newly created {@code UncheckedRow}.
 */
public static UncheckedRow createWithPrimaryKey(Table table, @Nullable Object primaryKeyValue) {
    long primaryKeyColumnIndex = getAndVerifyPrimaryKeyColumnIndex(table);
    RealmFieldType type = table.getColumnType(primaryKeyColumnIndex);
    final OsSharedRealm sharedRealm = table.getSharedRealm();

    if (type == RealmFieldType.STRING) {
        if (primaryKeyValue != null && !(primaryKeyValue instanceof String)) {
            throw new IllegalArgumentException("Primary key value is not a String: " + primaryKeyValue);
        }
        return new UncheckedRow(sharedRealm.context, table,
                nativeCreateNewObjectWithStringPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
                        primaryKeyColumnIndex, (String) primaryKeyValue));

    } else if (type == RealmFieldType.INTEGER) {
        long value = primaryKeyValue == null ? 0 : Long.parseLong(primaryKeyValue.toString());
        return new UncheckedRow(sharedRealm.context, table,
                nativeCreateNewObjectWithLongPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
                        primaryKeyColumnIndex, value, primaryKeyValue == null));
    } else {
        throw new RealmException("Cannot check for duplicate rows for unsupported primary key type: " + type);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:OsObject.java

示例2: createRowWithPrimaryKey

/**
 * Create an object in the given table which has a primary key column defined, and set the primary key with given
 * value.
 * This is used for the fast bulk insertion.
 *
 * @param table the table where the object is created.
 * @param primaryKeyColumnIndex the column index of primary key field.
 * @param primaryKeyValue the primary key value.
 * @return a newly created {@code UncheckedRow}.
 */
// FIXME: Proxy could just pass the pk index here which is much faster.
public static long createRowWithPrimaryKey(Table table, long primaryKeyColumnIndex, Object primaryKeyValue) {
    RealmFieldType type = table.getColumnType(primaryKeyColumnIndex);
    final OsSharedRealm sharedRealm = table.getSharedRealm();

    if (type == RealmFieldType.STRING) {
        if (primaryKeyValue != null && !(primaryKeyValue instanceof String)) {
            throw new IllegalArgumentException("Primary key value is not a String: " + primaryKeyValue);
        }
        return nativeCreateRowWithStringPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
                primaryKeyColumnIndex, (String) primaryKeyValue);

    } else if (type == RealmFieldType.INTEGER) {
        long value = primaryKeyValue == null ? 0 : Long.parseLong(primaryKeyValue.toString());
        return nativeCreateRowWithLongPrimaryKey(sharedRealm.getNativePtr(), table.getNativePtr(),
                primaryKeyColumnIndex, value, primaryKeyValue == null);
    } else {
        throw new RealmException("Cannot check for duplicate rows for unsupported primary key type: " + type);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:OsObject.java

示例3: getInstanceForDistinct_multipleFields

@Test
public void getInstanceForDistinct_multipleFields() {
    RealmFieldType stringType = RealmFieldType.STRING;
    long stringColumn = table.addColumn(stringType, stringType.name());
    table.addSearchIndex(stringColumn);
    RealmFieldType intType = RealmFieldType.INTEGER;
    long intColumn = table.addColumn(intType, intType.name());
    table.addSearchIndex(intColumn);

    SortDescriptor sortDescriptor = SortDescriptor.getInstanceForDistinct(null, table, new String[] {
            stringType.name(), intType.name()});
    assertEquals(2, sortDescriptor.getColumnIndices().length);
    assertNull(sortDescriptor.getAscendings());
    assertEquals(1, sortDescriptor.getColumnIndices()[0].length);
    assertEquals(stringColumn, sortDescriptor.getColumnIndices()[0][0]);
    assertEquals(1, sortDescriptor.getColumnIndices()[1].length);
    assertEquals(intColumn, sortDescriptor.getColumnIndices()[1][0]);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SortDescriptorTests.java

示例4: getInstanceForSort_multipleFields

@Test
public void getInstanceForSort_multipleFields() {
    RealmFieldType stringType = RealmFieldType.STRING;
    long stringColumn = table.addColumn(stringType, stringType.name());
    RealmFieldType intType = RealmFieldType.INTEGER;
    long intColumn = table.addColumn(intType, intType.name());

    SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(null, table, new String[] {
            stringType.name(), intType.name()}, new Sort[] {Sort.ASCENDING, Sort.DESCENDING});

    assertEquals(2, sortDescriptor.getAscendings().length);
    assertEquals(2, sortDescriptor.getColumnIndices().length);

    assertEquals(1, sortDescriptor.getColumnIndices()[0].length);
    assertEquals(stringColumn, sortDescriptor.getColumnIndices()[0][0]);
    assertTrue(sortDescriptor.getAscendings()[0]);

    assertEquals(1, sortDescriptor.getColumnIndices()[1].length);
    assertEquals(intColumn, sortDescriptor.getColumnIndices()[1][0]);
    assertFalse(sortDescriptor.getAscendings()[1]);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:SortDescriptorTests.java

示例5: getInstanceForSort_numOfFeildsAndSortOrdersNotMatch

@Test
public void getInstanceForSort_numOfFeildsAndSortOrdersNotMatch() {
    RealmFieldType stringType = RealmFieldType.STRING;
    table.addColumn(stringType, stringType.name());
    RealmFieldType intType = RealmFieldType.INTEGER;
    table.addColumn(intType, intType.name());

    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Number of fields and sort orders do not match.");
    SortDescriptor.getInstanceForSort(null, table,
            new String[] {stringType.name(), intType.name()}, new Sort[] {Sort.ASCENDING});

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:SortDescriptorTests.java

示例6: getInstanceForSort_shouldThrowOnLinkListField

@Test
public void getInstanceForSort_shouldThrowOnLinkListField() {
    RealmFieldType type = RealmFieldType.STRING;
    RealmFieldType listType = RealmFieldType.LIST;
    table.addColumn(type, type.name());
    table.addColumnLink(listType, listType.name(), table);

    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Invalid query: field 'LIST' in class 'test_table' is of invalid type 'LIST'.");
    SortDescriptor.getInstanceForSort(null, table, String.format("%s.%s", listType.name(), type.name()), Sort.ASCENDING);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:SortDescriptorTests.java

示例7: convertToRealmFieldType

private static RealmFieldType convertToRealmFieldType(int propertyType) {
    // Clear the nullable flag
    switch (propertyType & ~TYPE_NULLABLE) {
        case  TYPE_OBJECT:
            return RealmFieldType.OBJECT;
        case TYPE_OBJECT | TYPE_ARRAY:
            return RealmFieldType.LIST;
        case TYPE_LINKING_OBJECTS | TYPE_ARRAY:
            return RealmFieldType.LINKING_OBJECTS;
        case TYPE_INT:
            return RealmFieldType.INTEGER;
        case TYPE_BOOL:
            return RealmFieldType.BOOLEAN;
        case TYPE_STRING:
            return RealmFieldType.STRING;
        case TYPE_DATA:
            return RealmFieldType.BINARY;
        case TYPE_DATE:
            return RealmFieldType.DATE;
        case TYPE_FLOAT:
            return RealmFieldType.FLOAT;
        case TYPE_DOUBLE:
            return RealmFieldType.DOUBLE;
        //noinspection PointlessBitwiseExpression
        case TYPE_INT | TYPE_ARRAY:
            return INTEGER_LIST;
        case TYPE_BOOL | TYPE_ARRAY:
            return BOOLEAN_LIST;
        case TYPE_STRING | TYPE_ARRAY:
            return STRING_LIST;
        case TYPE_DATA | TYPE_ARRAY:
            return BINARY_LIST;
        case TYPE_DATE | TYPE_ARRAY:
            return DATE_LIST;
        case TYPE_FLOAT | TYPE_ARRAY:
            return FLOAT_LIST;
        case TYPE_DOUBLE | TYPE_ARRAY:
            return DOUBLE_LIST;
        default:
            throw new IllegalArgumentException(
                    String.format(Locale.US, "Unsupported property type: '%d'", propertyType));

    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:44,代码来源:Property.java


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