Package io.objectbox

Class Cursor<T>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    @Beta
    @Internal
    @NotThreadSafe
    public abstract class Cursor<T>
    extends java.lang.Object
    implements java.io.Closeable
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected <TARGET> void checkApplyToManyToDb​(java.util.List<TARGET> relationField, java.lang.Class<TARGET> targetClass)  
      void close()  
      protected static long collect002033​(long cursor, long keyIfComplete, int flags, int idLong1, long valueLong1, int idLong2, long valueLong2, int idFloat1, float valueFloat1, int idFloat2, float valueFloat2, int idFloat3, float valueFloat3, int idDouble1, double valueDouble1, int idDouble2, double valueDouble2, int idDouble3, double valueDouble3)  
      protected static long collect004000​(long cursor, long keyIfComplete, int flags, int idLong1, long valueLong1, int idLong2, long valueLong2, int idLong3, long valueLong3, int idLong4, long valueLong4)  
      protected static long collect313311​(long cursor, long keyIfComplete, int flags, int idStr1, java.lang.String valueStr1, int idStr2, java.lang.String valueStr2, int idStr3, java.lang.String valueStr3, int idBA1, byte[] valueBA1, int idLong1, long valueLong1, int idLong2, long valueLong2, int idLong3, long valueLong3, int idInt1, int valueInt1, int idInt2, int valueInt2, int idInt3, int valueInt3, int idFloat1, float valueFloat1, int idDouble1, double valueDouble1)  
      protected static long collect400000​(long cursor, long keyIfComplete, int flags, int idStr1, java.lang.String valueStr1, int idStr2, java.lang.String valueStr2, int idStr3, java.lang.String valueStr3, int idStr4, java.lang.String valueStr4)  
      protected static long collect430000​(long cursor, long keyIfComplete, int flags, int idStr1, java.lang.String valueStr1, int idStr2, java.lang.String valueStr2, int idStr3, java.lang.String valueStr3, int idStr4, java.lang.String valueStr4, int idBA1, byte[] valueBA1, int idBA2, byte[] valueBA2, int idBA3, byte[] valueBA3)  
      protected static long collectCharArray​(long cursor, long keyIfComplete, int flags, int propertyId, char[] value)  
      protected static long collectDoubleArray​(long cursor, long keyIfComplete, int flags, int propertyId, double[] value)  
      protected static long collectFloatArray​(long cursor, long keyIfComplete, int flags, int propertyId, float[] value)  
      protected static long collectIntArray​(long cursor, long keyIfComplete, int flags, int propertyId, int[] value)  
      protected static long collectLongArray​(long cursor, long keyIfComplete, int flags, int propertyId, long[] value)  
      protected static long collectShortArray​(long cursor, long keyIfComplete, int flags, int propertyId, short[] value)  
      protected static long collectStringArray​(long cursor, long keyIfComplete, int flags, int idStringArray, java.lang.String[] stringArray)  
      protected static long collectStringList​(long cursor, long keyIfComplete, int flags, int idStringList, java.util.List<java.lang.String> stringList)  
      long count​(long maxCountOrZero)  
      void deleteAll()  
      boolean deleteEntity​(long key)  
      protected void finalize()
      Explicitly call close() instead to avoid expensive finalization.
      T first()  
      T get​(long key)  
      java.util.List<T> getAll()
      ~10% slower than iterating with first() and next() as done by Box.getAll().
      (package private) java.util.List<T> getBacklinkEntities​(int entityId, Property<?> relationIdProperty, long key)  
      (package private) long[] getBacklinkIds​(int entityId, Property<?> relationIdProperty, long key)  
      EntityInfo<T> getEntityInfo()  
      protected abstract long getId​(T entity)  
      int getPropertyId​(java.lang.String propertyName)  
      java.util.List<T> getRelationEntities​(int sourceEntityId, int relationId, long key, boolean backlink)  
      long[] getRelationIds​(int sourceEntityId, int relationId, long key, boolean backlink)  
      protected <TARGET> Cursor<TARGET> getRelationTargetCursor​(java.lang.Class<TARGET> targetClass)
      Note: this returns a secondary cursor, which does not survive standalone.
      Transaction getTx()  
      (package private) long internalHandle()  
      boolean isClosed()  
      boolean isObsolete()  
      (package private) long lookupKeyUsingIndex​(int propertyId, java.lang.String value)
      Deprecated.
      TODO only used in tests, remove in the future
      void modifyRelations​(int relationId, long key, long[] targetKeys, boolean remove)  
      void modifyRelationsSingle​(int relationId, long key, long targetKey, boolean remove)  
      (package private) long nativeCount​(long cursor, long maxCountOrZero)  
      (package private) void nativeDeleteAll​(long cursor)  
      (package private) static boolean nativeDeleteEntity​(long cursor, long key)  
      (package private) void nativeDestroy​(long cursor)  
      (package private) static java.lang.Object nativeFirstEntity​(long cursor)  
      (package private) java.util.List<T> nativeGetAllEntities​(long cursor)  
      (package private) java.util.List<T> nativeGetBacklinkEntities​(long cursor, int entityId, int propertyId, long key)  
      (package private) long[] nativeGetBacklinkIds​(long cursor, int entityId, int propertyId, long key)  
      (package private) long nativeGetCursorFor​(long cursor, int entityId)  
      (package private) static java.lang.Object nativeGetEntity​(long cursor, long key)  
      (package private) java.util.List<T> nativeGetRelationEntities​(long cursor, int sourceEntityId, int relationId, long key, boolean backlink)  
      (package private) long[] nativeGetRelationIds​(long cursor, int sourceEntityId, int relationId, long key, boolean backlink)  
      (package private) static long nativeLookupKeyUsingIndex​(long cursor, int propertyId, java.lang.String value)  
      (package private) void nativeModifyRelations​(long cursor, int relationId, long key, long[] targetKeys, boolean remove)  
      (package private) void nativeModifyRelationsSingle​(long cursor, int relationId, long key, long targetKey, boolean remove)  
      (package private) static java.lang.Object nativeNextEntity​(long cursor)  
      (package private) int nativePropertyId​(long cursor, java.lang.String propertyValue)  
      (package private) long nativeRenew​(long cursor)  
      (package private) static boolean nativeSeek​(long cursor, long key)  
      (package private) void nativeSetBoxStoreForEntities​(long cursor, java.lang.Object boxStore)  
      T next()  
      abstract long put​(T entity)  
      void renew()
      To be used in combination with Transaction.renew().
      boolean seek​(long key)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • TRACK_CREATION_STACK

        @Internal
        static boolean TRACK_CREATION_STACK
        May be set by tests
      • LOG_READ_NOT_CLOSED

        @Internal
        static boolean LOG_READ_NOT_CLOSED
      • cursor

        protected final long cursor
      • boxStoreForEntities

        protected final BoxStore boxStoreForEntities
      • readOnly

        protected final boolean readOnly
      • closed

        protected boolean closed
      • creationThrowable

        private final java.lang.Throwable creationThrowable
    • Method Detail

      • nativeDestroy

        void nativeDestroy​(long cursor)
      • nativeDeleteEntity

        static boolean nativeDeleteEntity​(long cursor,
                                          long key)
      • nativeDeleteAll

        void nativeDeleteAll​(long cursor)
      • nativeSeek

        static boolean nativeSeek​(long cursor,
                                  long key)
      • nativeGetAllEntities

        java.util.List<T> nativeGetAllEntities​(long cursor)
      • nativeGetEntity

        static java.lang.Object nativeGetEntity​(long cursor,
                                                long key)
      • nativeNextEntity

        static java.lang.Object nativeNextEntity​(long cursor)
      • nativeFirstEntity

        static java.lang.Object nativeFirstEntity​(long cursor)
      • nativeCount

        long nativeCount​(long cursor,
                         long maxCountOrZero)
      • nativeLookupKeyUsingIndex

        static long nativeLookupKeyUsingIndex​(long cursor,
                                              int propertyId,
                                              java.lang.String value)
      • nativeRenew

        long nativeRenew​(long cursor)
      • collect313311

        protected static long collect313311​(long cursor,
                                            long keyIfComplete,
                                            int flags,
                                            int idStr1,
                                            @Nullable
                                            java.lang.String valueStr1,
                                            int idStr2,
                                            @Nullable
                                            java.lang.String valueStr2,
                                            int idStr3,
                                            @Nullable
                                            java.lang.String valueStr3,
                                            int idBA1,
                                            @Nullable
                                            byte[] valueBA1,
                                            int idLong1,
                                            long valueLong1,
                                            int idLong2,
                                            long valueLong2,
                                            int idLong3,
                                            long valueLong3,
                                            int idInt1,
                                            int valueInt1,
                                            int idInt2,
                                            int valueInt2,
                                            int idInt3,
                                            int valueInt3,
                                            int idFloat1,
                                            float valueFloat1,
                                            int idDouble1,
                                            double valueDouble1)
      • collect430000

        protected static long collect430000​(long cursor,
                                            long keyIfComplete,
                                            int flags,
                                            int idStr1,
                                            @Nullable
                                            java.lang.String valueStr1,
                                            int idStr2,
                                            @Nullable
                                            java.lang.String valueStr2,
                                            int idStr3,
                                            @Nullable
                                            java.lang.String valueStr3,
                                            int idStr4,
                                            @Nullable
                                            java.lang.String valueStr4,
                                            int idBA1,
                                            @Nullable
                                            byte[] valueBA1,
                                            int idBA2,
                                            @Nullable
                                            byte[] valueBA2,
                                            int idBA3,
                                            @Nullable
                                            byte[] valueBA3)
      • collect400000

        protected static long collect400000​(long cursor,
                                            long keyIfComplete,
                                            int flags,
                                            int idStr1,
                                            @Nullable
                                            java.lang.String valueStr1,
                                            int idStr2,
                                            @Nullable
                                            java.lang.String valueStr2,
                                            int idStr3,
                                            @Nullable
                                            java.lang.String valueStr3,
                                            int idStr4,
                                            @Nullable
                                            java.lang.String valueStr4)
      • collect002033

        protected static long collect002033​(long cursor,
                                            long keyIfComplete,
                                            int flags,
                                            int idLong1,
                                            long valueLong1,
                                            int idLong2,
                                            long valueLong2,
                                            int idFloat1,
                                            float valueFloat1,
                                            int idFloat2,
                                            float valueFloat2,
                                            int idFloat3,
                                            float valueFloat3,
                                            int idDouble1,
                                            double valueDouble1,
                                            int idDouble2,
                                            double valueDouble2,
                                            int idDouble3,
                                            double valueDouble3)
      • collect004000

        protected static long collect004000​(long cursor,
                                            long keyIfComplete,
                                            int flags,
                                            int idLong1,
                                            long valueLong1,
                                            int idLong2,
                                            long valueLong2,
                                            int idLong3,
                                            long valueLong3,
                                            int idLong4,
                                            long valueLong4)
      • collectStringArray

        protected static long collectStringArray​(long cursor,
                                                 long keyIfComplete,
                                                 int flags,
                                                 int idStringArray,
                                                 @Nullable
                                                 java.lang.String[] stringArray)
      • collectStringList

        protected static long collectStringList​(long cursor,
                                                long keyIfComplete,
                                                int flags,
                                                int idStringList,
                                                @Nullable
                                                java.util.List<java.lang.String> stringList)
      • collectShortArray

        protected static long collectShortArray​(long cursor,
                                                long keyIfComplete,
                                                int flags,
                                                int propertyId,
                                                @Nullable
                                                short[] value)
      • collectCharArray

        protected static long collectCharArray​(long cursor,
                                               long keyIfComplete,
                                               int flags,
                                               int propertyId,
                                               @Nullable
                                               char[] value)
      • collectIntArray

        protected static long collectIntArray​(long cursor,
                                              long keyIfComplete,
                                              int flags,
                                              int propertyId,
                                              @Nullable
                                              int[] value)
      • collectLongArray

        protected static long collectLongArray​(long cursor,
                                               long keyIfComplete,
                                               int flags,
                                               int propertyId,
                                               @Nullable
                                               long[] value)
      • collectFloatArray

        protected static long collectFloatArray​(long cursor,
                                                long keyIfComplete,
                                                int flags,
                                                int propertyId,
                                                @Nullable
                                                float[] value)
      • collectDoubleArray

        protected static long collectDoubleArray​(long cursor,
                                                 long keyIfComplete,
                                                 int flags,
                                                 int propertyId,
                                                 @Nullable
                                                 double[] value)
      • nativePropertyId

        int nativePropertyId​(long cursor,
                             java.lang.String propertyValue)
      • nativeGetBacklinkEntities

        java.util.List<T> nativeGetBacklinkEntities​(long cursor,
                                                    int entityId,
                                                    int propertyId,
                                                    long key)
      • nativeGetBacklinkIds

        long[] nativeGetBacklinkIds​(long cursor,
                                    int entityId,
                                    int propertyId,
                                    long key)
      • nativeGetRelationEntities

        java.util.List<T> nativeGetRelationEntities​(long cursor,
                                                    int sourceEntityId,
                                                    int relationId,
                                                    long key,
                                                    boolean backlink)
      • nativeGetRelationIds

        long[] nativeGetRelationIds​(long cursor,
                                    int sourceEntityId,
                                    int relationId,
                                    long key,
                                    boolean backlink)
      • nativeModifyRelations

        void nativeModifyRelations​(long cursor,
                                   int relationId,
                                   long key,
                                   long[] targetKeys,
                                   boolean remove)
      • nativeModifyRelationsSingle

        void nativeModifyRelationsSingle​(long cursor,
                                         int relationId,
                                         long key,
                                         long targetKey,
                                         boolean remove)
      • nativeSetBoxStoreForEntities

        void nativeSetBoxStoreForEntities​(long cursor,
                                          java.lang.Object boxStore)
      • nativeGetCursorFor

        long nativeGetCursorFor​(long cursor,
                                int entityId)
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Explicitly call close() instead to avoid expensive finalization.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getId

        protected abstract long getId​(T entity)
      • put

        public abstract long put​(T entity)
      • get

        public T get​(long key)
      • next

        public T next()
      • first

        public T first()
      • deleteEntity

        public boolean deleteEntity​(long key)
      • deleteAll

        public void deleteAll()
      • seek

        public boolean seek​(long key)
      • count

        public long count​(long maxCountOrZero)
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getPropertyId

        public int getPropertyId​(java.lang.String propertyName)
      • lookupKeyUsingIndex

        long lookupKeyUsingIndex​(int propertyId,
                                 java.lang.String value)
        Deprecated.
        TODO only used in tests, remove in the future
        Returns:
        key or 0 if not found
      • isObsolete

        public boolean isObsolete()
      • isClosed

        public boolean isClosed()
      • getRelationTargetCursor

        protected <TARGET> Cursor<TARGET> getRelationTargetCursor​(java.lang.Class<TARGET> targetClass)
        Note: this returns a secondary cursor, which does not survive standalone. Secondary native cursors are destroyed once their hosting Cursor is destroyed. Thus, use it only locally and don't store it long term.
      • internalHandle

        @Internal
        long internalHandle()
      • getBacklinkEntities

        @Internal
        java.util.List<T> getBacklinkEntities​(int entityId,
                                              Property<?> relationIdProperty,
                                              long key)
      • getBacklinkIds

        @Internal
        long[] getBacklinkIds​(int entityId,
                              Property<?> relationIdProperty,
                              long key)
      • getRelationEntities

        @Internal
        public java.util.List<T> getRelationEntities​(int sourceEntityId,
                                                     int relationId,
                                                     long key,
                                                     boolean backlink)
      • getRelationIds

        @Internal
        public long[] getRelationIds​(int sourceEntityId,
                                     int relationId,
                                     long key,
                                     boolean backlink)
      • modifyRelations

        @Internal
        public void modifyRelations​(int relationId,
                                    long key,
                                    long[] targetKeys,
                                    boolean remove)
      • modifyRelationsSingle

        @Internal
        public void modifyRelationsSingle​(int relationId,
                                          long key,
                                          long targetKey,
                                          boolean remove)
      • checkApplyToManyToDb

        protected <TARGET> void checkApplyToManyToDb​(java.util.List<TARGET> relationField,
                                                     java.lang.Class<TARGET> targetClass)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object