Docs Menu

Class DynamicRealm

io.realm.BaseRealm
io.realm.DynamicRealm

DynamicRealm is a dynamic variant of io.realm.Realm . This means that all access to data and/or queries are done using string based class names instead of class type references.

This is useful during migrations or when working with string-based data like CSV or XML files.

The same io.realm.RealmConfiguration can be used to open a Realm file in both dynamic and typed mode, but modifying the schema while having both a typed and dynamic version open is highly discouraged and will most likely crash the typed Realm. During migrations only a DynamicRealm will be open.

Dynamic Realms do not enforce schemas or schema versions and RealmMigration code is not used even if it has been defined in the RealmConfiguration .

This means that the schema is not created or validated until a Realm has been opened in typed mode. If a Realm file is opened in dynamic mode first it will not contain any information about classes and fields, and any queries for classes defined by the schema will fail.

다음도 참조하세요.

수정자 및 유형
클래스 및 설명

public static interface

public abstract static

수정자 및 유형
메서드 및 설명

public void

Realm에 변경 리스너를 추가합니다.

public <any>

이 Realm의 변경 사항을 모니터링하는 RxJava Flowable을 반환합니다.

String className,
DynamicRealmObject parentObject,
String parentProperty
)

새로운 내장된 객체를 인스턴스화하고 Realm에 추가합니다.

String className,
Object primaryKeyValue
)

Creates an object with a given primary key.

String className
)

Realm에 새 객체를 인스턴스화하고 추가합니다.

public void

String className
)

Realm에서 지정된 클래스의 모든 객체를 삭제합니다.

public void

Executes a given transaction on the DynamicRealm.

executionTransactionAsync(Transaction) 와 유사하지만 OnSuccess 및 OnError 콜백도 허용합니다.

executionTransactionAsync(Transaction) 과 유사하지만 OnError 콜백 도 허용합니다.

executionTransactionAsync(Transaction) 과 유사하지만 OnSuccess 콜백 도 허용합니다.

executionTransaction(Transaction)과 유사하지만 작업자 스레드에서 비동기적으로 실행됩니다.

현재 Realm의 동결된 스냅샷을 반환합니다.

public static DynamicRealm

Realm static constructor that returns a dynamic variant of the Realm instance defined by provided io.realm.RealmConfiguration .

public static RealmAsyncTask

The creation of the first Realm instance per RealmConfiguration in a process can take some time as all initialization code need to run at that point (Setting up the Realm, validating schemas and creating initial data).

Returns the mutable schema for this Realm.

공개 부울

io.realm.Realm 에 객체가 포함되어 있는지 확인합니다.

public void

모든 사용자 정의 변경 수신기를 제거합니다.

public void

지정된 변경 리스너를 제거합니다.

공개 RealmQuery

String className
)

Returns a RealmQuery, which can be used to query the provided class.

  • 클래스 java.lang.Object 에서 상속된 메서드 : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize

  • io.realm.BaseRealm 클래스에서 상속된 메서드: setAutoRefresh , isAutoRefresh , refresh , isInTransaction , addListener , removeListener , asFlowable , removeAllListeners , writeCopyTo , writeEncryptedCopyTo , waitForChange , stopWaitForChange , beginTransaction , commitTransaction , cancelTransaction , freeze , isFrozen , getNumberOfActiveVersions , checkIfValid , checkAllowQueriesOnUiThread , checkAllowWritesOnUiThread , checkIfInTransaction , checkIfValidAndInTransaction , getPath , getConfiguration , getVersion , close , isClosed , isEmpty , getSchema , getSubscriptions , deleteAll , migrateRealm , finalize

Realm에 변경 리스너를 추가합니다. 이 스레드 또는 다른 스레드에서 변경 사항이 커밋될 때 리스너가 실행됩니다.

Realm instances are cached per thread. For that reason it is important to remember to remove listeners again either using removeChangeListener(RealmChangeListener) or removeAllChangeListeners() . Not doing so can cause memory leaks.

매개변수

  • listener - 변경 리스너.

스로우

다음도 참조하세요.

public <any> asFlowable ()

이 Realm의 변경 사항을 모니터링하는 RxJava Flowable을 반환합니다. 구독 시 현재 상태를 방출합니다. Realm이 업데이트될 때마다 항목이 계속 방출되며 onComplete 은(는) 호출되지 않습니다.

Realm Flowable에서 방출된 항목은 동결됩니다(freeze() 참조). 즉, 변경할 수 없으며 모든 스레드에서 읽을 수 있습니다.

Realm Flowable은 항상 라이브 Realm을 보유한 스레드에서 항목을 방출합니다. 즉, 추가 처리를 수행해야 하는 경우 계산 스케줄러에서 값을 관찰하는 것이 좋습니다.

realm.asFlowable()
.observeOn(Schedulers.computation())
.map(rxRealm -> doExpensiveWork(rxRealm))
.observeOn(AndroidSchedulers.mainThread())
.subscribe( ... );

asFlowable() 에서 항목 방출을 중지하려면 first() 연산자를 사용하여 첫 번째 항목만 방출하도록 RxJava에 지시할 수 있습니다.

realm.asFlowable().first().subscribe( ... ); // You only get the results once

반환

onNext 만 호출하는 RxJava Observable입니다. 절대 onComplete 또는 OnError 를 호출하지 않습니다.

재정의

BaseRealm클래스의 asFlowable

String className,
DynamicRealmObject parentObject,
String parentProperty
)

새 내장된 객체를 인스턴스화하고 Realm에 추가합니다. 이 메서드는 내장된 것으로 표시된 유형의 객체를 생성하는 데만 사용해야 합니다.

매개변수

  • className - the class name of the object to create.

  • parentObject - The parent object which should hold a reference to the embedded object. If the parent property is a list the embedded object will be added to the end of that list.

  • parentProperty - the property in the parent class which holds the reference.

반환

새로 생성된 내장된 객체입니다.

스로우

  • 불법적인 인수 예외 - clazz 이(가) 포함된 클래스가 아니거나 상위 클래스의 속성 이 적절한 유형의 객체를 보유할 수 없는 경우.

다음도 참조하세요.

String className,
Object primaryKeyValue
)

Creates an object with a given primary key. Classes without a primary key defined must use createObject(String) } instead.

반환

the new object. All fields will have default values for their type, except for the primary key field which will have the provided value.

스로우

Realm에 새 객체를 인스턴스화하고 추가합니다.

매개변수

  • className - the class name of the object to create.

반환

새 객체.

스로우

public void delete (
String className
)

Realm에서 지정된 클래스의 모든 객체를 삭제합니다.

매개변수

  • className - the class for which all objects should be removed.

스로우

  • 불법적인 상태 예외 - Realm이 닫혔거나 잘못된 스레드에서 호출된 경우

Executes a given transaction on the DynamicRealm. beginTransaction() and commitTransaction() will be called automatically. If any exception is thrown during the transaction cancelTransaction() will be called instead of commitTransaction().

UI 스레드에서 이 메서드를 호출하면 RealmException이 발생합니다. 이렇게 하면 프레임 드롭 또는 ANR이 발생할 수 있습니다. 이 메서드를 UI 아닌 스레드에서 호출하거나 대신 executionTransactionAsync(Transaction)를 사용하는 것이 좋습니다.

매개변수

스로우

executionTransactionAsync(Transaction) 와 유사하지만 OnSuccess 및 OnError 콜백도 허용합니다.

매개변수

  • transaction - 트랜잭션 to execute.

  • onSuccess - 트랜잭션 이 성공하면 호출되는 콜백 입니다.

  • onError - 트랜잭션 이 실패할 때 호출되는 콜백 입니다.

반환

취소 가능한 작업을 나타내는 RealmAsyncTask 입니다.

스로우

executionTransactionAsync(Transaction) 과 유사하지만 OnError 콜백 도 허용합니다.

매개변수

  • transaction - 트랜잭션 to execute.

  • onError - 트랜잭션 이 실패할 때 호출되는 콜백 입니다.

반환

취소 가능한 작업을 나타내는 RealmAsyncTask 입니다.

스로우

executionTransactionAsync(Transaction) 과 유사하지만 OnSuccess 콜백 도 허용합니다.

매개변수

  • transaction - 트랜잭션 to execute.

  • onSuccess - 트랜잭션 이 성공하면 호출되는 콜백 입니다.

반환

취소 가능한 작업을 나타내는 RealmAsyncTask 입니다.

스로우

executionTransaction(Transaction)과 유사하지만 작업자 스레드에서 비동기적으로 실행됩니다.

매개변수

반환

취소 가능한 작업을 나타내는 RealmAsyncTask 입니다.

스로우

현재 Realm의 동결된 스냅샷을 반환합니다. 이 Realm은 IllegalStateException 을 발생시키지 않고 모든 스레드에서 읽고 쿼리할 수 있습니다. . 동결된 Realm에는 자체 수명 주기가 있으며 close() 를 호출하여 닫을 수 있지만 동결된 복사본을 생성한 Realm을 완전히 닫으면 동결된 Realm도 닫힙니다.

동결된 데이터는 정상적으로 쿼리할 수 있지만 어떤 방식으로든 데이터를 변경하거나 리스너를 등록하려고 하면 불법적인 상태 예외( IllegalStateException )가 발생합니다. .

참고: 버전이 다른 많은 수의 Realm을 활성 상태로 유지하면 Realm의 파일 크기에 부정적인 영향을 미칠 수 있습니다. 이러한 상황을 방지하려면 RealmConfiguration.Builder.maxNumberOfActiveVersions(long) 을 설정할 수 있습니다.

반환

이 Realm의 동결된 사본입니다.

재정의

BaseRealm클래스의 freeze

public static DynamicRealm getInstance (
RealmConfiguration configuration
)

Realm static constructor that returns a dynamic variant of the Realm instance defined by provided io.realm.RealmConfiguration . Dynamic Realms do not care about schemaVersion and schemas, so opening a DynamicRealm will never trigger a migration.

반환

the DynamicRealm defined by the configuration.

스로우

다음도 참조하세요.

The creation of the first Realm instance per RealmConfiguration in a process can take some time as all initialization code need to run at that point (Setting up the Realm, validating schemas and creating initial data). This method places the initialization work in a background thread and deliver the Realm instance to the caller thread asynchronously after the initialization is finished.

매개변수

  • configuration - Realm을 여는 데 사용되는 RealmConfiguration 입니다.

  • callback - 결과를 반환하기 위해 호출됩니다.

반환

취소 가능한 작업을 나타내는 RealmAsyncTask 입니다.

스로우

다음도 참조하세요.

Returns the mutable schema for this Realm.

반환

이 Realm의 RealmSchema 입니다.

재정의

BaseRealm클래스의 getSchema

public boolean isEmpty ()

io.realm.Realm 에 객체가 포함되어 있는지 확인합니다.

반환

비어 있으면 true , 그렇지 않으면 @{code false}.

재정의

BaseRealm클래스의 isEmpty

모든 사용자 정의 변경 수신기를 제거합니다.

스로우

  • 불법적인 상태 예외 - Looper가 아닌 스레드에서 리스너를 제거하려고 하는 경우.

다음도 참조하세요.

지정된 변경 리스너를 제거합니다.

매개변수

  • listener - 제거할 변경 리스너입니다.

스로우

다음도 참조하세요.

public RealmQuery where (
String className
)

Returns a RealmQuery, which can be used to query the provided class.

매개변수

  • className - the class of the object which is to be queried.

반환

a RealmQuery, which can be used to query for specific objects of provided type.

스로우

다음도 참조하세요.