• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java RealmPrimaryKeyConstraintException类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中io.realm.exceptions.RealmPrimaryKeyConstraintException的典型用法代码示例。如果您正苦于以下问题:Java RealmPrimaryKeyConstraintException类的具体用法?Java RealmPrimaryKeyConstraintException怎么用?Java RealmPrimaryKeyConstraintException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

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

示例1: createObject_duplicatedNullPrimaryKeyThrows

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
@Test
public void createObject_duplicatedNullPrimaryKeyThrows() throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    addPrimaryKeyObjectToTestRealm(realm);

    realm.beginTransaction();
    try {
        realm.createObject(testClazz, null);
        fail("Null value as primary key already exists.");
    } catch (RealmPrimaryKeyConstraintException expected) {
        assertTrue("Exception message is: " + expected.getMessage(),
                expected.getMessage().contains("Primary key value already exists: 'null' ."));
    } finally {
        realm.cancelTransaction();
    }
}
 

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

示例2: copyToRealm_duplicatedNullPrimaryKeyThrows

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
@Test
public void copyToRealm_duplicatedNullPrimaryKeyThrows() {
    final String[] PRIMARY_KEY_TYPES = {"String", "BoxedByte", "BoxedShort", "BoxedInteger", "BoxedLong"};

    TestHelper.addStringPrimaryKeyObjectToTestRealm(realm, (String) null, 0);
    TestHelper.addBytePrimaryKeyObjectToTestRealm(realm, (Byte) null, (String) null);
    TestHelper.addShortPrimaryKeyObjectToTestRealm(realm, (Short) null, (String) null);
    TestHelper.addIntegerPrimaryKeyObjectToTestRealm(realm, (Integer) null, (String) null);
    TestHelper.addLongPrimaryKeyObjectToTestRealm(realm, (Long) null, (String) null);

    for (String className : PRIMARY_KEY_TYPES) {
        try {
            realm.beginTransaction();
            switch (className) {
                case "String":
                    realm.copyToRealm(new PrimaryKeyAsString());
                    break;
                case "BoxedByte":
                    realm.copyToRealm(new PrimaryKeyAsBoxedByte());
                    break;
                case "BoxedShort":
                    realm.copyToRealm(new PrimaryKeyAsBoxedShort());
                    break;
                case "BoxedInteger":
                    realm.copyToRealm(new PrimaryKeyAsBoxedInteger());
                    break;
                case "BoxedLong":
                    realm.copyToRealm(new PrimaryKeyAsBoxedLong());
                    break;
                default:
            }
            fail("Null value as primary key already exists.");
        } catch (RealmPrimaryKeyConstraintException expected) {
            assertTrue("Exception message is: " + expected.getMessage(),
                    expected.getMessage().contains("Primary key value already exists: 'null' ."));
        } finally {
            realm.cancelTransaction();
        }
    }
}
 

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

示例3: createObjectWithPrimaryKey_valueAlreadyExists

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
@Test
public void createObjectWithPrimaryKey_valueAlreadyExists() {
    realm.beginTransaction();
    realm.createObject(AllJavaTypes.class, 42);
    try {
        realm.createObject(AllJavaTypes.class, 42);
        fail();
    } catch (RealmPrimaryKeyConstraintException ignored) {
    }
}
 

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

示例4: primaryKey_checkPrimaryKeyOnCreate

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
@Test
public void primaryKey_checkPrimaryKeyOnCreate() {
    realm.beginTransaction();
    try {
        realm.createObject(AnnotationTypes.class, 0);
        fail("Two empty objects cannot be created on the same table if a primary key is defined");
    } catch (RealmPrimaryKeyConstraintException ignored) {
    } finally {
        realm.cancelTransaction();
    }
}
 

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

示例5: primaryKey_errorOnInsertingSameObject

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
@Test
public void primaryKey_errorOnInsertingSameObject() {
    try {
        realm.beginTransaction();
        realm.createObject(AnnotationTypes.class, 1);
        realm.createObject(AnnotationTypes.class, 1);
        fail("Inserting two objects with same primary key should fail");
    } catch (RealmPrimaryKeyConstraintException ignored) {
    } finally {
        realm.cancelTransaction();
    }
}
 

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

示例6: create

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
public int create(Friend friend) {

        mRealm.beginTransaction();

        try {


        } catch (IllegalArgumentException | RealmPrimaryKeyConstraintException e) {

            mRealm.cancelTransaction();
            throw e;
        }

        mRealm.commitTransaction();

        return SUCCESS_OPERATION;
    }
 

开发者ID:orogersilva,
项目名称:racha-conta-android,
代码行数:18,
代码来源:FriendDal.java

示例7: create

点赞 2

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
public int create(Product product) {

        mRealm.beginTransaction();

        try {


        } catch (IllegalArgumentException | RealmPrimaryKeyConstraintException e) {

            mRealm.cancelTransaction();
            throw e;
        }

        mRealm.commitTransaction();

        return SUCCESS_OPERATION;
    }
 

开发者ID:orogersilva,
项目名称:racha-conta-android,
代码行数:18,
代码来源:ProductDal.java

示例8: throwDuplicatePrimaryKeyException

点赞 1

import io.realm.exceptions.RealmPrimaryKeyConstraintException; //导入依赖的package包/类
/**
 * Throws a properly formatted exception when multiple objects with the same primary key
 * value is detected.
 *
 * @param value the primary key value.
 */
public static void throwDuplicatePrimaryKeyException(Object value) {
    throw new RealmPrimaryKeyConstraintException("Value already exists: " + value);
}
 

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


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)