com.bugvm.apple.coredata.NSManagedObjectContext Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2013-2015 RoboVM AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bugvm.apple.coredata;
/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
/* */
/**/
/**
* @since Available in iOS 3.0 and later.
*/
/* */
/**/@Library("CoreData") @NativeClass/* */
/**/public/* */ class /**/NSManagedObjectContext/* */
extends /**/NSObject/* */
/**/implements NSCoding, NSLocking/* */ {
public static class Notifications {
/**
* @since Available in iOS 3.0 and later.
*/
public static NSObject observeWillSave(NSManagedObject object, final VoidBlock1 block) {
return NSNotificationCenter.getDefaultCenter().addObserver(WillSaveNotification(), object, NSOperationQueue.getMainQueue(), new VoidBlock1() {
@Override
public void invoke(NSNotification a) {
block.invoke((NSManagedObject)a.getObject());
}
});
}
/**
* @since Available in iOS 3.0 and later.
*/
public static NSObject observeDidSave(NSManagedObject object, final VoidBlock2 block) {
return NSNotificationCenter.getDefaultCenter().addObserver(DidSaveNotification(), object, NSOperationQueue.getMainQueue(), new VoidBlock1() {
@Override
public void invoke(NSNotification a) {
NSDictionary, ?> userInfo = a.getUserInfo();
NSManagedObjectContextNotification data = null;
if (userInfo != null) {
data = new NSManagedObjectContextNotification(userInfo);
}
block.invoke((NSManagedObject)a.getObject(), data);
}
});
}
/**
* @since Available in iOS 3.0 and later.
*/
public static NSObject observeObjectsDidChange(NSManagedObject object, final VoidBlock3 block) {
return NSNotificationCenter.getDefaultCenter().addObserver(ObjectsDidChangeNotification(), object, NSOperationQueue.getMainQueue(), new VoidBlock1() {
@Override
public void invoke(NSNotification a) {
NSDictionary, ?> userInfo = a.getUserInfo();
NSManagedObjectContextNotification data = null;
if (userInfo != null) {
data = new NSManagedObjectContextNotification(userInfo);
}
block.invoke((NSManagedObject)a.getObject(), data, a);
}
});
}
}
/**/public static class NSManagedObjectContextPtr extends Ptr {}/* */
/**/static { ObjCRuntime.bind(NSManagedObjectContext.class); }/* */
/**//* */
/**/
public NSManagedObjectContext() {}
protected NSManagedObjectContext(SkipInit skipInit) { super(skipInit); }
/**
* @since Available in iOS 5.0 and later.
*/
public NSManagedObjectContext(NSManagedObjectContextConcurrencyType ct) { super((SkipInit) null); initObject(init(ct)); }
public NSManagedObjectContext(NSCoder aDecoder) { super((SkipInit) null); initObject(init(aDecoder)); }
/* */
/**/
@Property(selector = "persistentStoreCoordinator")
public native NSPersistentStoreCoordinator getPersistentStoreCoordinator();
@Property(selector = "setPersistentStoreCoordinator:")
public native void setPersistentStoreCoordinator(NSPersistentStoreCoordinator v);
/**
* @since Available in iOS 5.0 and later.
*/
@Property(selector = "parentContext")
public native NSManagedObjectContext getParentContext();
/**
* @since Available in iOS 5.0 and later.
*/
@Property(selector = "setParentContext:")
public native void setParentContext(NSManagedObjectContext v);
/**
* @since Available in iOS 8.0 and later.
*/
@Property(selector = "name")
public native String getName();
/**
* @since Available in iOS 8.0 and later.
*/
@Property(selector = "setName:")
public native void setName(String v);
@Property(selector = "undoManager")
public native NSUndoManager getUndoManager();
@Property(selector = "setUndoManager:")
public native void setUndoManager(NSUndoManager v);
@Property(selector = "hasChanges")
public native boolean hasChanges();
/**
* @since Available in iOS 5.0 and later.
*/
@Property(selector = "userInfo")
public native NSMutableDictionary, ?> getUserInfo();
/**
* @since Available in iOS 5.0 and later.
*/
@Property(selector = "concurrencyType")
public native NSManagedObjectContextConcurrencyType getConcurrencyType();
@Property(selector = "insertedObjects")
public native NSSet getInsertedObjects();
@Property(selector = "updatedObjects")
public native NSSet getUpdatedObjects();
@Property(selector = "deletedObjects")
public native NSSet getDeletedObjects();
@Property(selector = "registeredObjects")
public native NSSet getRegisteredObjects();
@Property(selector = "propagatesDeletesAtEndOfEvent")
public native boolean propagatesDeletesAtEndOfEvent();
@Property(selector = "setPropagatesDeletesAtEndOfEvent:")
public native void setPropagatesDeletesAtEndOfEvent(boolean v);
@Property(selector = "retainsRegisteredObjects")
public native NSSet getRetainsRegisteredObjects();
@Property(selector = "setRetainsRegisteredObjects:")
public native void setRetainsRegisteredObjects(NSSet v);
/**
* @since Available in iOS 9.0 and later.
*/
@Property(selector = "shouldDeleteInaccessibleFaults")
public native boolean shouldDeleteInaccessibleFaults();
/**
* @since Available in iOS 9.0 and later.
*/
@Property(selector = "setShouldDeleteInaccessibleFaults:")
public native void setShouldDeleteInaccessibleFaults(boolean v);
@Property(selector = "stalenessInterval")
public native double getStalenessInterval();
@Property(selector = "setStalenessInterval:")
public native void setStalenessInterval(double v);
@Property(selector = "mergePolicy")
public native NSObject getMergePolicy();
@Property(selector = "setMergePolicy:")
public native void setMergePolicy(NSObject v);
/* */
/**//* */
public void observeValue(String keyPath, NSObject object, NSKeyValueChangeInfo change) {}
@Method(selector = "observeValueForKeyPath:ofObject:change:context:")
private void observeValueForKeyPath(String keyPath, NSObject object, NSKeyValueChangeInfo change, VoidPtr context) {
observeValue(keyPath, object, change);
}
/**/
/**
* @since Available in iOS 3.0 and later.
*/
@GlobalValue(symbol="NSManagedObjectContextWillSaveNotification", optional=true)
public static native NSString WillSaveNotification();
/**
* @since Available in iOS 3.0 and later.
*/
@GlobalValue(symbol="NSManagedObjectContextDidSaveNotification", optional=true)
public static native NSString DidSaveNotification();
/**
* @since Available in iOS 3.0 and later.
*/
@GlobalValue(symbol="NSManagedObjectContextObjectsDidChangeNotification", optional=true)
public static native NSString ObjectsDidChangeNotification();
/**
* @since Available in iOS 5.0 and later.
*/
@Method(selector = "initWithConcurrencyType:")
protected native @Pointer long init(NSManagedObjectContextConcurrencyType ct);
/**
* @since Available in iOS 5.0 and later.
*/
@Method(selector = "performBlock:")
public native void performBlock(@Block Runnable block);
/**
* @since Available in iOS 5.0 and later.
*/
@Method(selector = "performBlockAndWait:")
public native void performBlockAndWait(@Block Runnable block);
@Method(selector = "objectRegisteredForID:")
public native NSManagedObject getObjectRegisteredForID(NSManagedObjectID objectID);
@Method(selector = "objectWithID:")
public native NSManagedObject getObjectWithId(NSManagedObjectID objectID);
/**
* @since Available in iOS 3.0 and later.
*/
public NSManagedObject getExistingObjectWithID(NSManagedObjectID objectID) throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
NSManagedObject result = getExistingObjectWithID(objectID, ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
/**
* @since Available in iOS 3.0 and later.
*/
@Method(selector = "existingObjectWithID:error:")
private native NSManagedObject getExistingObjectWithID(NSManagedObjectID objectID, NSError.NSErrorPtr error);
public NSArray executeFetchRequest(NSFetchRequest request) throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
NSArray result = executeFetchRequest(request, ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
@Method(selector = "executeFetchRequest:error:")
private native NSArray executeFetchRequest(NSFetchRequest request, NSError.NSErrorPtr error);
/**
* @since Available in iOS 3.0 and later.
*/
public @MachineSizedUInt long getCountForFetchRequest(NSFetchRequest request) throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
long result = getCountForFetchRequest(request, ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
/**
* @since Available in iOS 3.0 and later.
*/
@Method(selector = "countForFetchRequest:error:")
private native @MachineSizedUInt long getCountForFetchRequest(NSFetchRequest request, NSError.NSErrorPtr error);
/**
* @since Available in iOS 8.0 and later.
*/
public NSPersistentStoreResult executeRequest(NSPersistentStoreRequest request) throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
NSPersistentStoreResult result = executeRequest(request, ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
/**
* @since Available in iOS 8.0 and later.
*/
@Method(selector = "executeRequest:error:")
private native NSPersistentStoreResult executeRequest(NSPersistentStoreRequest request, NSError.NSErrorPtr error);
@Method(selector = "insertObject:")
public native void insertObject(NSManagedObject object);
@Method(selector = "deleteObject:")
public native void deleteObject(NSManagedObject object);
@Method(selector = "refreshObject:mergeChanges:")
public native void refreshObject(NSManagedObject object, boolean flag);
@Method(selector = "detectConflictsForObject:")
public native void detectConflicts(NSManagedObject object);
@Method(selector = "processPendingChanges")
public native void processPendingChanges();
@Method(selector = "assignObject:toPersistentStore:")
public native void assignObjectToPersistentStore(NSObject object, NSPersistentStore store);
@Method(selector = "undo")
public native void undo();
@Method(selector = "redo")
public native void redo();
@Method(selector = "reset")
public native void reset();
@Method(selector = "rollback")
public native void rollback();
public boolean save() throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
boolean result = save(ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
@Method(selector = "save:")
private native boolean save(NSError.NSErrorPtr error);
/**
* @since Available in iOS 8.3 and later.
*/
@Method(selector = "refreshAllObjects")
public native void refreshAllObjects();
/**
* @since Available in iOS 3.0 and later.
* @deprecated Deprecated in iOS 8.0.
*/
@Deprecated
@Method(selector = "lock")
public native void lock();
/**
* @since Available in iOS 3.0 and later.
* @deprecated Deprecated in iOS 8.0.
*/
@Deprecated
@Method(selector = "unlock")
public native void unlock();
/**
* @since Available in iOS 3.0 and later.
* @deprecated Deprecated in iOS 8.0.
*/
@Deprecated
@Method(selector = "tryLock")
public native boolean tryLock();
/**
* @since Available in iOS 9.0 and later.
*/
@Method(selector = "shouldHandleInaccessibleFault:forObjectID:triggeredByProperty:")
public native boolean shouldHandleInaccessibleFault(NSManagedObject fault, NSManagedObjectID oid, NSPropertyDescription property);
/**
* @since Available in iOS 3.0 and later.
*/
public boolean obtainPermanentIDsForObjects(NSArray objects) throws NSErrorException {
NSError.NSErrorPtr ptr = new NSError.NSErrorPtr();
boolean result = obtainPermanentIDsForObjects(objects, ptr);
if (ptr.get() != null) { throw new NSErrorException(ptr.get()); }
return result;
}
/**
* @since Available in iOS 3.0 and later.
*/
@Method(selector = "obtainPermanentIDsForObjects:error:")
private native boolean obtainPermanentIDsForObjects(NSArray objects, NSError.NSErrorPtr error);
/**
* @since Available in iOS 3.0 and later.
*/
@Method(selector = "mergeChangesFromContextDidSaveNotification:")
public native void mergeChangesFromContextDidSaveNotification(NSNotification notification);
/**
* @since Available in iOS 9.0 and later.
*/
@Method(selector = "mergeChangesFromRemoteContextSave:intoContexts:")
public static native void mergeChangesFromRemoteContextSave(NSDictionary, ?> changeNotificationData, NSArray contexts);
@Method(selector = "encodeWithCoder:")
public native void encode(NSCoder coder);
@Method(selector = "initWithCoder:")
protected native @Pointer long init(NSCoder aDecoder);
/* */
}