Java 类io.realm.RealmFieldType 实例源码

项目:GitHub    文件:Table.java   
/**
 * Adds a column to the table dynamically.
 *
 * @param type the column type.
 * @param name the field/column name.
 * @param isNullable {@code true} if column can contain null values, {@code false} otherwise.
 * @return the index of the new column.
 */
public long addColumn(RealmFieldType type, String name, boolean isNullable) {
    verifyColumnName(name);
    switch (type) {
        case INTEGER:
        case BOOLEAN:
        case STRING:
        case BINARY:
        case DATE:
        case FLOAT:
        case DOUBLE:
            return nativeAddColumn(nativePtr, type.getNativeValue(), name, isNullable);

        case INTEGER_LIST:
        case BOOLEAN_LIST:
        case STRING_LIST:
        case BINARY_LIST:
        case DATE_LIST:
        case FLOAT_LIST:
        case DOUBLE_LIST:
            return nativeAddPrimitiveListColumn(nativePtr, type.getNativeValue() - 128, name, isNullable);

        default:
            throw new IllegalArgumentException("Unsupported type: " + type);
    }
}
项目:GitHub    文件:SortDescriptor.java   
private static SortDescriptor getInstance(
        FieldDescriptor.SchemaProxy proxy,
        Table table,
        String[] fieldDescriptions,
        @Nullable Sort[] sortOrders,
        Set<RealmFieldType> legalInternalTypes,
        Set<RealmFieldType> legalTerminalTypes,
        String message) {

    //noinspection ConstantConditions
    if (fieldDescriptions == null || fieldDescriptions.length == 0) {
        throw new IllegalArgumentException("You must provide at least one field name.");
    }

    long[][] columnIndices = new long[fieldDescriptions.length][];

    // Force aggressive parsing of the FieldDescriptors, so that only valid SortDescriptor objects are created.
    for (int i = 0; i < fieldDescriptions.length; i++) {
        FieldDescriptor descriptor = FieldDescriptor.createFieldDescriptor(proxy, table, fieldDescriptions[i], legalInternalTypes, null);
        checkFieldType(descriptor, legalTerminalTypes, message, fieldDescriptions[i]);
        columnIndices[i] = descriptor.getColumnIndices();
    }

    return new SortDescriptor(table, columnIndices, sortOrders);
}
项目:GitHub    文件:OsObject.java   
/**
 * 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);
    }
}
项目:GitHub    文件:OsObject.java   
/**
 * 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);
    }
}
项目:GitHub    文件:SortDescriptorTests.java   
@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]);
}
项目:GitHub    文件:SortDescriptorTests.java   
@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]);

}
项目:Hyber-SDK-Android    文件:RealmRecyclerViewAdapter.java   
private String getRealmRowIdentifier(int realmIndex, HashMap<Long, RealmFieldType> columnIndexRealmFieldTypeHashMap) {
    String rowIdentifier = "";

    RealmObjectProxy proxy = (RealmObjectProxy) adapterData.get(realmIndex);
    Row row = proxy.realmGet$proxyState().getRow$realm();

    for (Entry<Long, RealmFieldType> entry : columnIndexRealmFieldTypeHashMap.entrySet()) {
        switch (entry.getValue()) {
            case STRING:
                rowIdentifier += row.getString(entry.getKey());
                break;
            case INTEGER:
                rowIdentifier += String.valueOf(row.getLong(entry.getKey()));
                break;
            case BOOLEAN:
                rowIdentifier += String.valueOf(row.getBoolean(entry.getKey()));
                break;
            default:
                throw new IllegalStateException("Unsupported RealmFieldType, use only STRING, INTEGER or BOOLEAN field types");
        }
    }
    return rowIdentifier;
}
项目:NetKnight    文件:RealmBarDataSet.java   
@Override
public BarEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(values,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    } else {
        float value = dynamicObject.getFloat(mValuesField);
        return new BarEntry(value,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    }
}
项目:JNChartDemo    文件:RealmBarDataSet.java   
@Override
public BarEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(values,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    } else {
        float value = dynamicObject.getFloat(mValuesField);
        return new BarEntry(value,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    }
}
项目:RebDroid    文件:ViewAdapter.java   
private ArrayList<ArrayList<String>> createContent() {
    int row = mItens.size();
    int column = mTable.getColumns().size();
    ArrayList<ArrayList<String>> results = new ArrayList<>();
    for (int i = 0; i < row; i++) {
        ArrayList<String> strings = new ArrayList<>();
        DynamicRealmObject object = realm.where(mTable.getName()).findAll().get(i);
        for (int j = 0; j < column; j++) {
            String cel = "";
            try {
                if (object.get(mTable.getColumns().get(j).getName()) != null)
                    if (mTable.getColumns().get(j).getType() == RealmFieldType.LIST) {
                        cel = "RealmList<" + object.getList(mTable.getColumns().get(j).getName()).first().getType() + '>';
                    } else {
                        cel = object.get(mTable.getColumns().get(j).getName()).toString();
                    }
            } catch (NullPointerException e) {
                L.e("Except > row size: " + row + " column size: " + column + "   " + i + "/" + j);
            }
            strings.add(cel);
        }
        results.add(strings);
    }
    return results;
}
项目:MPAndroidChart-Realm    文件:RealmBarDataSet.java   
@Override
public BarEntry buildEntryFromResultObject(T realmObject, float x) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mYValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mYValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(
                mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), values);
    } else {
        float value = dynamicObject.getFloat(mYValuesField);
        return new BarEntry(mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), value);
    }
}
项目:GitHub    文件:CheckedRow.java   
@Override
public boolean isNullLink(long columnIndex) {
    RealmFieldType columnType = getColumnType(columnIndex);
    if (columnType == RealmFieldType.OBJECT || columnType == RealmFieldType.LIST) {
        return super.isNullLink(columnIndex);
    } else {
        return false; // Unsupported types always return false
    }
}
项目:GitHub    文件:CheckedRow.java   
/**
 * Sets null to a row pointer with checking if a column is nullable, except when the column type
 * is binary.
 *
 * @param columnIndex 0 based index value of the cell column.
 */
@Override
public void setNull(long columnIndex) {
    RealmFieldType columnType = getColumnType(columnIndex);
    if (columnType == RealmFieldType.BINARY) {
        super.setBinaryByteArray(columnIndex, null);
    } else {
        super.setNull(columnIndex);
    }
}
项目:GitHub    文件:CheckedRow.java   
@Override
public OsList getModelList(long columnIndex) {
    RealmFieldType fieldType = getTable().getColumnType(columnIndex);
    if (fieldType != RealmFieldType.LIST) {
        throw new IllegalArgumentException(
                String.format(Locale.US, "Field '%s' is not a 'RealmList'.",
                        getTable().getColumnName(columnIndex)));
    }
    return super.getModelList(columnIndex);
}
项目:GitHub    文件:CheckedRow.java   
@Override
public OsList getValueList(long columnIndex, RealmFieldType fieldType) {
    final RealmFieldType actualFieldType = getTable().getColumnType(columnIndex);
    if (fieldType != actualFieldType) {
        throw new IllegalArgumentException(
                String.format(Locale.US, "The type of field '%1$s' is not 'RealmFieldType.%2$s'.",
                        getTable().getColumnName(columnIndex), fieldType.name()));
    }
    return super.getValueList(columnIndex, fieldType);
}
项目:GitHub    文件:FieldDescriptor.java   
/**
 * @param fieldDescription fieldName or link path to a field name.
 * @param validInternalColumnTypes valid internal link types.
 * @param validFinalColumnTypes valid field types for the last field in a linked field
 */
protected FieldDescriptor(
        String fieldDescription, Set<RealmFieldType>
        validInternalColumnTypes,
        Set<RealmFieldType> validFinalColumnTypes) {
    this.fields = parseFieldDescription(fieldDescription);
    int nFields = fields.size();
    if (nFields <= 0) {
        throw new IllegalArgumentException("Invalid query: Empty field descriptor");
    }
    this.validInternalColumnTypes = validInternalColumnTypes;
    this.validFinalColumnTypes = validFinalColumnTypes;
}
项目:GitHub    文件:FieldDescriptor.java   
/**
 * Store the results of compiling the field description.
 * Subclasses call this as the last action in
 *
 * @param finalClassName the name of the final table in the field description.
 * @param finalColumnName the name of the final column in the field description.
 * @param finalColumnType the type of the final column in the field description: MAY NOT BE {@code null}!
 * @param columnIndices the array of columnIndices.
 * @param nativeTablePointers the array of table pointers
 */
protected final void setCompilationResults(
        String finalClassName,
        String finalColumnName,
        RealmFieldType finalColumnType,
        long[] columnIndices,
        long[] nativeTablePointers) {
    if ((validFinalColumnTypes != null) && (validFinalColumnTypes.size() > 0)) {
        verifyColumnType(finalClassName, finalColumnName, finalColumnType, validFinalColumnTypes);
    }
    this.finalColumnName = finalColumnName;
    this.finalColumnType = finalColumnType;
    this.columnIndices = columnIndices;
    this.nativeTablePointers = nativeTablePointers;
}
项目:GitHub    文件:FieldDescriptor.java   
private void verifyColumnType(String className, String columnName, RealmFieldType columnType, Set<RealmFieldType> validTypes) {
    if (!validTypes.contains(columnType)) {
        throw new IllegalArgumentException(String.format(Locale.US,
                "Invalid query: field '%s' in class '%s' is of invalid type '%s'.",
                columnName, className, columnType.toString()));
    }
}
项目:GitHub    文件:DynamicFieldDescriptor.java   
@Override
protected void compileFieldDescription(List<String> fields) {
    final int nFields = fields.size();
    long[] columnIndices = new long[nFields];

    Table currentTable = table;
    String currentClassName = null;
    String currentColumnName = null;
    RealmFieldType currentColumnType = null;
    for (int i = 0; i < nFields; i++) {
        currentColumnName = fields.get(i);
        if ((currentColumnName == null) || (currentColumnName.length() <= 0)) {
            throw new IllegalArgumentException(
                    "Invalid query: Field descriptor contains an empty field.  A field description may not begin with or contain adjacent periods ('.').");
        }

        currentClassName = currentTable.getClassName();

        final long columnIndex = currentTable.getColumnIndex(currentColumnName);
        if (columnIndex < 0) {
            throw new IllegalArgumentException(
                    String.format(Locale.US, "Invalid query: field '%s' not found in table '%s'.", currentColumnName, currentClassName));
        }

        currentColumnType = currentTable.getColumnType(columnIndex);
        if (i < nFields - 1) {
            verifyInternalColumnType(currentClassName, currentColumnName, currentColumnType);
            currentTable = currentTable.getLinkTarget(columnIndex);
        }

        columnIndices[i] = columnIndex;
    }

    setCompilationResults(currentClassName, currentColumnName, currentColumnType, columnIndices, new long[nFields]);
}
项目:GitHub    文件:PrimaryKeyTests.java   
private Table getTableWithStringPrimaryKey() {
    sharedRealm = OsSharedRealm.getInstance(config);
    sharedRealm.beginTransaction();
    OsObjectStore.setSchemaVersion(sharedRealm,0); // Create meta table
    Table t = sharedRealm.createTable(Table.getTableNameForClass("TestTable"));
    long column = t.addColumn(RealmFieldType.STRING, "colName", true);
    t.addSearchIndex(column);
    OsObjectStore.setPrimaryKeyForObject(sharedRealm, "TestTable", "colName");
    return t;
}
项目:GitHub    文件:PrimaryKeyTests.java   
private Table getTableWithIntegerPrimaryKey() {
    sharedRealm = OsSharedRealm.getInstance(config);
    sharedRealm.beginTransaction();
    OsObjectStore.setSchemaVersion(sharedRealm,0); // Create meta table
    Table t = sharedRealm.createTable(Table.getTableNameForClass("TestTable"));
    long column = t.addColumn(RealmFieldType.INTEGER, "colName");
    t.addSearchIndex(column);
    OsObjectStore.setPrimaryKeyForObject(sharedRealm, "TestTable", "colName");
    return t;
}
项目:GitHub    文件:PrimaryKeyTests.java   
@Test
public void migratePrimaryKeyTableIfNeeded_first() throws IOException {
    configFactory.copyRealmFromAssets(context, "080_annotationtypes.realm", "default.realm");
    sharedRealm = OsSharedRealm.getInstance(config);
    Table.migratePrimaryKeyTableIfNeeded(sharedRealm);
    Table t = sharedRealm.getTable("class_AnnotationTypes");
    assertEquals("id", OsObjectStore.getPrimaryKeyForObject(sharedRealm, "AnnotationTypes"));
    assertEquals(RealmFieldType.STRING, sharedRealm.getTable("pk").getColumnType(0));
}
项目:GitHub    文件:JNIRowTest.java   
@Test
public void nullValues() {

    Table table = TestHelper.createTable(sharedRealm, "temp");
    long colStringIndex = table.addColumn(RealmFieldType.STRING, "string", true);
    long colIntIndex = table.addColumn(RealmFieldType.INTEGER, "integer", true);
    table.addColumn(RealmFieldType.FLOAT, "float");
    table.addColumn(RealmFieldType.DOUBLE, "double");
    long colBoolIndex = table.addColumn(RealmFieldType.BOOLEAN, "boolean", true);
    table.addColumn(RealmFieldType.DATE, "date");
    table.addColumn(RealmFieldType.BINARY, "binary");
    long rowIndex = OsObject.createRow(table);

    UncheckedRow row = table.getUncheckedRow(rowIndex);

    row.setString(colStringIndex, "test");
    assertEquals("test", row.getString(colStringIndex));
    row.setNull(colStringIndex);
    assertNull(row.getString(colStringIndex));

    row.setLong(colIntIndex, 1);
    assertFalse(row.isNull(colIntIndex));
    row.setNull(colIntIndex);
    assertTrue(row.isNull(colIntIndex));

    row.setBoolean(colBoolIndex, true);
    assertFalse(row.isNull(colBoolIndex));
    row.setNull(colBoolIndex);
    assertTrue(row.isNull(colBoolIndex));
}
项目:GitHub    文件:OsListTests.java   
@Before
public void setUp() {
    OsObjectSchemaInfo objectSchemaInfo = new OsObjectSchemaInfo.Builder("TestModel",14, 0)
            .addPersistedValueListProperty("longList", RealmFieldType.INTEGER_LIST, !Property.REQUIRED)
            .addPersistedValueListProperty("doubleList", RealmFieldType.DOUBLE_LIST,  !Property.REQUIRED)
            .addPersistedValueListProperty("floatList", RealmFieldType.FLOAT_LIST, !Property.REQUIRED)
            .addPersistedValueListProperty("booleanList", RealmFieldType.BOOLEAN_LIST, !Property.REQUIRED)
            .addPersistedValueListProperty("binaryList", RealmFieldType.BINARY_LIST, !Property.REQUIRED)
            .addPersistedValueListProperty("dateList", RealmFieldType.DATE_LIST, !Property.REQUIRED)
            .addPersistedValueListProperty("stringList", RealmFieldType.STRING_LIST, !Property.REQUIRED)

            .addPersistedValueListProperty("requiredLongList", RealmFieldType.INTEGER_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredDoubleList", RealmFieldType.DOUBLE_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredFloatList", RealmFieldType.FLOAT_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredBooleanList", RealmFieldType.BOOLEAN_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredBinaryList", RealmFieldType.BINARY_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredDateList", RealmFieldType.DATE_LIST, Property.REQUIRED)
            .addPersistedValueListProperty("requiredStringList", RealmFieldType.STRING_LIST, Property.REQUIRED)

            .build();
    List<OsObjectSchemaInfo> objectSchemaInfoList = new ArrayList<OsObjectSchemaInfo>();
    objectSchemaInfoList.add(objectSchemaInfo);

    OsSchemaInfo schemaInfo = new OsSchemaInfo(objectSchemaInfoList);

    RealmConfiguration config = configFactory.createConfiguration();
    OsRealmConfig.Builder configBuilder = new OsRealmConfig.Builder(config)
            .autoUpdateNotification(true)
            .schemaInfo(schemaInfo);
    sharedRealm = OsSharedRealm.getInstance(configBuilder);
    sharedRealm.beginTransaction();
    Table table = sharedRealm.getTable(Table.getTableNameForClass("TestModel"));
    row = table.getUncheckedRow(OsObject.createRow(table));
    sharedRealm.commitTransaction();

    schemaInfo = sharedRealm.getSchemaInfo();
    testObjectSchemaInfo = schemaInfo.getObjectSchemaInfo("TestModel");

    sharedRealm.beginTransaction();
}
项目:GitHub    文件:OsResultsTests.java   
private void populateData(OsSharedRealm sharedRealm) {
    sharedRealm.beginTransaction();
    table = sharedRealm.createTable(Table.getTableNameForClass("test_table"));
    // Specify the column types and names
    long columnIdx = table.addColumn(RealmFieldType.STRING, "firstName");
    table.addSearchIndex(columnIdx);
    table.addColumn(RealmFieldType.STRING, "lastName");
    table.addColumn(RealmFieldType.INTEGER, "age");

    // Add data to the table
    long row = OsObject.createRow(table);
    table.setString(0, row, "John", false);
    table.setString(1, row, "Lee", false);
    table.setLong(2, row, 4, false);

    row = OsObject.createRow(table);
    table.setString(0, row, "John", false);
    table.setString(1, row, "Anderson", false);
    table.setLong(2, row, 3, false);

    row = OsObject.createRow(table);
    table.setString(0, row, "Erik", false);
    table.setString(1, row, "Lee", false);
    table.setLong(2, row, 1, false);

    row = OsObject.createRow(table);
    table.setString(0, row, "Henry", false);
    table.setString(1, row, "Anderson", false);
    table.setLong(2, row, 1, false);
    sharedRealm.commitTransaction();
}
项目:GitHub    文件:SortDescriptorTests.java   
@Test
public void getInstanceForDistinct_shouldThrowOnInvalidField() {
    Set<RealmFieldType> types = getValidFieldTypes(SortDescriptor.DISTINCT_VALID_FIELD_TYPES);

    for (RealmFieldType type : types) {
        try {
            SortDescriptor.getInstanceForDistinct(null, table, type.name());
            fail();
        } catch (IllegalArgumentException ignored) {
            assertTrue(ignored.getMessage().contains("Distinct is not supported"));
        }
    }
}
项目:GitHub    文件:SortDescriptorTests.java   
@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});

}
项目:GitHub    文件:SortDescriptorTests.java   
@Test
public void getInstanceForSort_shouldThrowOnInvalidField() {
    Set<RealmFieldType> types = getValidFieldTypes(SortDescriptor.SORT_VALID_FIELD_TYPES);

    for (RealmFieldType type : types) {
        try {
            SortDescriptor.getInstanceForSort(null, table, type.name(), Sort.ASCENDING);
            fail();
        } catch (IllegalArgumentException ignored) {
            assertTrue(ignored.getMessage().contains("Sort is not supported"));
        }
    }
}
项目:GitHub    文件:SortDescriptorTests.java   
@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);
}
项目:GitHub    文件:SortDescriptorTests.java   
private Set<RealmFieldType> getValidFieldTypes(Set<RealmFieldType> filter) {
    Set<RealmFieldType> types = new HashSet<>();
    for (RealmFieldType type : RealmFieldType.values()) {
        if (!filter.contains(type)) {
            switch (type) {
                case LINKING_OBJECTS: // TODO: should be supported?s
                case INTEGER_LIST: // FIXME zaki50 revisit this once Primitive List query is implemented
                case BOOLEAN_LIST:
                case STRING_LIST:
                case BINARY_LIST:
                case DATE_LIST:
                case FLOAT_LIST:
                case DOUBLE_LIST:
                    break;
                case LIST:
                case OBJECT:
                    table.addColumnLink(type, type.name(), table);
                    types.add(type);
                    break;
                default:
                    table.addColumn(type, type.name());
                    types.add(type);
            }
        }
    }
    return types;
}
项目:GitHub    文件:JNITableTest.java   
@Test
public void columnName() {
    TestHelper.createTable(sharedRealm, "temp", new TestHelper.AdditionalTableSetup() {
        @Override
        public void execute(Table t) {
            try {
                t.addColumn(RealmFieldType.STRING, "I am 64 characters..............................................");
                fail("Only 63 characters supported");
            } catch (IllegalArgumentException ignored) { }
            t.addColumn(RealmFieldType.STRING, "I am 63 characters.............................................");
        }
    });
}
项目:Rebro    文件:RealmManager.java   
@Nullable
private static Object getValue(@NonNull final Table table, final int columnIdx, final int rowIdx) {
    final RealmFieldType columnType = table.getColumnType(columnIdx);
    Object value = null;
    switch (columnType) {
        case BINARY:
            value = table.getBinaryByteArray(columnIdx, rowIdx);
            break;
        case BOOLEAN:
            value = table.getBoolean(columnIdx, rowIdx);
            break;
        case DATE:
            value = table.getDate(columnIdx, rowIdx);
            break;
        case DOUBLE:
            value = table.getDouble(columnIdx, rowIdx);
            break;
        case FLOAT:
            value = table.getFloat(columnIdx, rowIdx);
            break;
        case INTEGER:
            value = table.getLong(columnIdx, rowIdx);
            break;
        case STRING:
            value = table.getString(columnIdx, rowIdx);
            break;
        case OBJECT:
            value = table.getLink(columnIdx, rowIdx);
            break;
        default:
            //TODO throw an exception?
            break;
    }

    return value;
}
项目:Rebro    文件:RealmManager.java   
@NonNull
private static RType toRebroType(@NonNull final RealmFieldType columnType) {
    RType type;

    switch (columnType) {
        case BINARY:
            type = RType.BINARY;
            break;
        case BOOLEAN:
            type = RType.BOOLEAN;
            break;
        case DATE:
            type = RType.DATE;
            break;
        case DOUBLE:
            type = RType.DOUBLE;
            break;
        case FLOAT:
            type = RType.FLOAT;
            break;
        case INTEGER:
            type = RType.INTEGER;
            break;
        case STRING:
            type = RType.STRING;
            break;
        case OBJECT:
            type = RType.OBJECT;
            break;
        default:
            type = RType.UNSUPPORTED;
            break;
    }

    return type;
}
项目:Hyber-SDK-Android    文件:RealmRecyclerViewAdapter.java   
private List<String> getIdentifiersOfRealmResults(HashMap<Long, RealmFieldType> columnIndexRealmFieldTypeHashMap) {
    if (adapterData == null || adapterData.size() == 0
            || columnIndexRealmFieldTypeHashMap == null || columnIndexRealmFieldTypeHashMap.isEmpty()) {
        return EMPTY_LIST;
    }
    List<String> ids = new ArrayList<>(adapterData.size());
    for (int i = 0; i < adapterData.size(); i++) {
        ids.add(getRealmRowIdentifier(i, columnIndexRealmFieldTypeHashMap));
    }
    return ids;
}
项目:realm-browser-android    文件:HtmlBuilder.java   
public void showTableStructure(DynamicRealm dynamicRealm) {
    RealmObjectSchema realmObjectSchema = dynamicRealm.getSchema().get(simpleTableName);
    Set<String> fieldNames = realmObjectSchema.getFieldNames();
    stringBuilder.append("<div class=\"content\">").append("<table class=\"dataTable\">")
            .append("<th>Column Name</th><th>Type</th>");
    for (String fieldName : fieldNames) {
        RealmFieldType realmFieldType = realmObjectSchema.getFieldType(fieldName);
        stringBuilder.append("<tr>")
                .append("<td>").append(fieldName).append("</td>")
                .append("<td>").append(realmFieldType.name()).append("</td>")
                .append("</tr>");
    }
    stringBuilder.append("</table></div>");
}
项目:GitHub    文件:ColumnInfo.java   
private ColumnDetails(long columnIndex, RealmFieldType columnType, @Nullable String linkedClassName) {
    // invariant: (columnType == OBJECT || columnType == LIST || columnType == LINKING_OBJECTS) == (linkedClassName != null)
    this.columnIndex = columnIndex;
    this.columnType = columnType;
    this.linkedClassName = linkedClassName;
}
项目:GitHub    文件:Property.java   
static int convertFromRealmFieldType(RealmFieldType fieldType, boolean isRequired) {
    int type;
    switch (fieldType) {
        case OBJECT:
            type = TYPE_OBJECT | TYPE_NULLABLE;
            return type;
        case LIST:
            type = TYPE_OBJECT | TYPE_ARRAY;
            return type;
        case LINKING_OBJECTS:
            type = TYPE_LINKING_OBJECTS | TYPE_ARRAY;
            return type;
        case INTEGER:
            type = TYPE_INT;
            break;
        case BOOLEAN:
            type = TYPE_BOOL;
            break;
        case STRING:
            type = TYPE_STRING;
            break;
        case BINARY:
            type = TYPE_DATA;
            break;
        case DATE:
            type = TYPE_DATE;
            break;
        case FLOAT:
            type = TYPE_FLOAT;
            break;
        case DOUBLE:
            type = TYPE_DOUBLE;
            break;
        case INTEGER_LIST:
            //noinspection PointlessBitwiseExpression
            type = TYPE_INT | TYPE_ARRAY;
            break;
        case BOOLEAN_LIST:
            type = TYPE_BOOL | TYPE_ARRAY;
            break;
        case STRING_LIST:
            type = TYPE_STRING | TYPE_ARRAY;
            break;
        case BINARY_LIST:
            type = TYPE_DATA | TYPE_ARRAY;
            break;
        case DATE_LIST:
            type = TYPE_DATE | TYPE_ARRAY;
            break;
        case FLOAT_LIST:
            type = TYPE_FLOAT | TYPE_ARRAY;
            break;
        case DOUBLE_LIST:
            type = TYPE_DOUBLE | TYPE_ARRAY;
            break;
        default:
            throw new IllegalArgumentException(
                    String.format(Locale.US, "Unsupported filed type: '%s'.", fieldType.name()));

    }
    int requiredFlag = isRequired ? TYPE_REQUIRED : TYPE_NULLABLE;
    return type | requiredFlag;
}
项目:GitHub    文件:Property.java   
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));

    }
}
项目:GitHub    文件:Property.java   
public RealmFieldType getType() {
    return convertToRealmFieldType(nativeGetType(nativePtr));
}
项目:GitHub    文件:Table.java   
/**
 * Inserts a column at the given {@code columnIndex}.
 * WARNING: This is only for internal testing purpose. Don't expose this to public API.
 */
public void insertColumn(long columnIndex, RealmFieldType type, String name) {
    verifyColumnName(name);
    nativeInsertColumn(nativePtr, columnIndex, type.getNativeValue(), name);
}