use of io.realm.internal.Table in project realm-java by realm.
the class RealmSchema method getAll.
/**
* Returns the {@link RealmObjectSchema} for all RealmObject classes that can be saved in this Realm.
*
* @return the set of all classes in this Realm or no RealmObject classes can be saved in the Realm.
*/
public Set<RealmObjectSchema> getAll() {
if (realm == null) {
long[] ptrs = nativeGetAll(nativePtr);
Set<RealmObjectSchema> schemas = new LinkedHashSet<RealmObjectSchema>(ptrs.length);
for (int i = 0; i < ptrs.length; i++) {
schemas.add(new RealmObjectSchema(ptrs[i]));
}
return schemas;
} else {
int tableCount = (int) realm.sharedRealm.size();
Set<RealmObjectSchema> schemas = new LinkedHashSet<RealmObjectSchema>(tableCount);
for (int i = 0; i < tableCount; i++) {
String tableName = realm.sharedRealm.getTableName(i);
if (!Table.isModelTable(tableName)) {
continue;
}
Table table = realm.sharedRealm.getTable(tableName);
RealmObjectSchema.DynamicColumnMap columnIndices = new RealmObjectSchema.DynamicColumnMap(table);
schemas.add(new RealmObjectSchema(realm, table, columnIndices));
}
return schemas;
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmSchema method get.
/**
* Returns the Realm schema for a given class.
*
* @param className name of the class
* @return schema object for that class or {@code null} if the class doesn't exists.
*/
public RealmObjectSchema get(String className) {
checkEmpty(className, EMPTY_STRING_MSG);
if (realm == null) {
if (contains(className)) {
return dynamicClassToSchema.get(className);
} else {
return null;
}
} else {
String internalClassName = TABLE_PREFIX + className;
if (realm.sharedRealm.hasTable(internalClassName)) {
Table table = realm.sharedRealm.getTable(internalClassName);
RealmObjectSchema.DynamicColumnMap columnIndices = new RealmObjectSchema.DynamicColumnMap(table);
return new RealmObjectSchema(realm, table, columnIndices);
} else {
return null;
}
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmSchema method create.
/**
* Adds a new class to the Realm.
*
* @param className name of the class.
* @return a Realm schema object for that class.
*/
public RealmObjectSchema create(String className) {
// Adding a class is always permitted.
checkEmpty(className, EMPTY_STRING_MSG);
if (realm == null) {
RealmObjectSchema realmObjectSchema = new RealmObjectSchema(className);
dynamicClassToSchema.put(className, realmObjectSchema);
return realmObjectSchema;
} else {
String internalTableName = TABLE_PREFIX + className;
if (internalTableName.length() > Table.TABLE_MAX_LENGTH) {
throw new IllegalArgumentException("Class name is too long. Limit is 56 characters: " + className.length());
}
if (realm.sharedRealm.hasTable(internalTableName)) {
throw new IllegalArgumentException("Class already exists: " + className);
}
Table table = realm.sharedRealm.getTable(internalTableName);
RealmObjectSchema.DynamicColumnMap columnIndices = new RealmObjectSchema.DynamicColumnMap(table);
return new RealmObjectSchema(realm, table, columnIndices);
}
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmSchema method getTable.
Table getTable(String className) {
className = Table.TABLE_PREFIX + className;
Table table = dynamicClassToTable.get(className);
if (table == null) {
if (!realm.sharedRealm.hasTable(className)) {
throw new IllegalArgumentException("The class " + className + " doesn't exist in this Realm.");
}
table = realm.sharedRealm.getTable(className);
dynamicClassToTable.put(className, table);
}
return table;
}
use of io.realm.internal.Table in project realm-java by realm.
the class RealmSchema method rename.
/**
* Renames a class already in the Realm.
*
* @param oldClassName old class name.
* @param newClassName new class name.
* @return a schema object for renamed class.
*/
public RealmObjectSchema rename(String oldClassName, String newClassName) {
// Destructive modifications are not permitted.
realm.checkNotInSync();
checkEmpty(oldClassName, "Class names cannot be empty or null");
checkEmpty(newClassName, "Class names cannot be empty or null");
String oldInternalName = TABLE_PREFIX + oldClassName;
String newInternalName = TABLE_PREFIX + newClassName;
checkHasTable(oldClassName, "Cannot rename class because it doesn't exist in this Realm: " + oldClassName);
if (realm.sharedRealm.hasTable(newInternalName)) {
throw new IllegalArgumentException(oldClassName + " cannot be renamed because the new class already exists: " + newClassName);
}
// Checks if there is a primary key defined for the old class.
Table oldTable = getTable(oldClassName);
String pkField = null;
if (oldTable.hasPrimaryKey()) {
pkField = oldTable.getColumnName(oldTable.getPrimaryKey());
oldTable.setPrimaryKey(null);
}
realm.sharedRealm.renameTable(oldInternalName, newInternalName);
Table table = realm.sharedRealm.getTable(newInternalName);
// Sets the primary key for the new class if necessary.
if (pkField != null) {
table.setPrimaryKey(pkField);
}
RealmObjectSchema.DynamicColumnMap columnIndices = new RealmObjectSchema.DynamicColumnMap(table);
return new RealmObjectSchema(realm, table, columnIndices);
}
Aggregations