├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ └── feature_request.md ├── dependabot.yml └── workflows │ └── close-no-response.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitlab └── merge_request_templates │ └── Default.md ├── CHANGELOG.md ├── Jenkinsfile ├── LICENSE.txt ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── objectbox-publish.gradle.kts ├── ci ├── Jenkinsfile-Windows └── send-to-gchat.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── logo.png ├── objectbox-java-api ├── LICENSE ├── NOTICE ├── build.gradle └── src │ └── main │ └── java │ └── io │ └── objectbox │ ├── annotation │ ├── Backlink.java │ ├── BaseEntity.java │ ├── ConflictStrategy.java │ ├── Convert.java │ ├── DatabaseType.java │ ├── DefaultValue.java │ ├── Entity.java │ ├── ExternalPropertyType.java │ ├── ExternalType.java │ ├── HnswFlags.java │ ├── HnswIndex.java │ ├── Id.java │ ├── IdCompanion.java │ ├── Index.java │ ├── IndexType.java │ ├── NameInDb.java │ ├── NotNull.java │ ├── OrderBy.java │ ├── Sync.java │ ├── TargetIdProperty.java │ ├── Transient.java │ ├── Type.java │ ├── Uid.java │ ├── Unique.java │ ├── Unsigned.java │ ├── VectorDistanceType.java │ ├── apihint │ │ ├── Beta.java │ │ ├── Experimental.java │ │ ├── Internal.java │ │ └── package-info.java │ └── package-info.java │ └── converter │ ├── PropertyConverter.java │ └── package-info.java ├── objectbox-java ├── build.gradle ├── spotbugs-exclude.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── objectbox │ │ │ ├── Box.java │ │ │ ├── BoxStore.java │ │ │ ├── BoxStoreBuilder.java │ │ │ ├── Cursor.java │ │ │ ├── DebugFlags.java │ │ │ ├── EntityInfo.java │ │ │ ├── Factory.java │ │ │ ├── InternalAccess.java │ │ │ ├── KeyValueCursor.java │ │ │ ├── ModelBuilder.java │ │ │ ├── ObjectClassPublisher.java │ │ │ ├── Property.java │ │ │ ├── Transaction.java │ │ │ ├── TxCallback.java │ │ │ ├── config │ │ │ ├── DebugFlags.java │ │ │ ├── FlatStoreOptions.java │ │ │ ├── TreeOptionFlags.java │ │ │ ├── ValidateOnOpenModeKv.java │ │ │ └── ValidateOnOpenModePages.java │ │ │ ├── converter │ │ │ ├── FlexObjectConverter.java │ │ │ ├── IntegerFlexMapConverter.java │ │ │ ├── IntegerLongMapConverter.java │ │ │ ├── LongFlexMapConverter.java │ │ │ ├── LongLongMapConverter.java │ │ │ ├── NullToEmptyStringConverter.java │ │ │ ├── StringFlexMapConverter.java │ │ │ ├── StringLongMapConverter.java │ │ │ └── StringMapConverter.java │ │ │ ├── exception │ │ │ ├── ConstraintViolationException.java │ │ │ ├── DbDetachedException.java │ │ │ ├── DbException.java │ │ │ ├── DbExceptionListener.java │ │ │ ├── DbFullException.java │ │ │ ├── DbMaxDataSizeExceededException.java │ │ │ ├── DbMaxReadersExceededException.java │ │ │ ├── DbSchemaException.java │ │ │ ├── DbShutdownException.java │ │ │ ├── FeatureNotAvailableException.java │ │ │ ├── FileCorruptException.java │ │ │ ├── NonUniqueResultException.java │ │ │ ├── NumericOverflowException.java │ │ │ ├── PagesCorruptException.java │ │ │ ├── UniqueViolationException.java │ │ │ └── package-info.java │ │ │ ├── flatbuffers │ │ │ ├── ArrayReadWriteBuf.java │ │ │ ├── BaseVector.java │ │ │ ├── BooleanVector.java │ │ │ ├── ByteBufferReadWriteBuf.java │ │ │ ├── ByteBufferUtil.java │ │ │ ├── ByteVector.java │ │ │ ├── Constants.java │ │ │ ├── DoubleVector.java │ │ │ ├── FlatBufferBuilder.java │ │ │ ├── FlexBuffers.java │ │ │ ├── FlexBuffersBuilder.java │ │ │ ├── FloatVector.java │ │ │ ├── IntVector.java │ │ │ ├── LICENSE.txt │ │ │ ├── LongVector.java │ │ │ ├── README.md │ │ │ ├── ReadBuf.java │ │ │ ├── ReadWriteBuf.java │ │ │ ├── ShortVector.java │ │ │ ├── StringVector.java │ │ │ ├── Struct.java │ │ │ ├── Table.java │ │ │ ├── UnionVector.java │ │ │ ├── Utf8.java │ │ │ ├── Utf8Old.java │ │ │ └── Utf8Safe.java │ │ │ ├── ideasonly │ │ │ ├── ModelModifier.java │ │ │ └── ModelUpdate.java │ │ │ ├── internal │ │ │ ├── CallWithHandle.java │ │ │ ├── CursorFactory.java │ │ │ ├── DebugCursor.java │ │ │ ├── Feature.java │ │ │ ├── IdGetter.java │ │ │ ├── JniTest.java │ │ │ ├── NativeLibraryLoader.java │ │ │ ├── ObjectBoxThreadPool.java │ │ │ ├── ReflectionCache.java │ │ │ ├── ToManyGetter.java │ │ │ ├── ToOneGetter.java │ │ │ └── package-info.java │ │ │ ├── model │ │ │ ├── EntityFlags.java │ │ │ ├── ExternalPropertyType.java │ │ │ ├── HnswDistanceType.java │ │ │ ├── HnswFlags.java │ │ │ ├── HnswParams.java │ │ │ ├── IdUid.java │ │ │ ├── Model.java │ │ │ ├── ModelEntity.java │ │ │ ├── ModelProperty.java │ │ │ ├── ModelRelation.java │ │ │ ├── PropertyFlags.java │ │ │ ├── PropertyType.java │ │ │ └── ValidateOnOpenMode.java │ │ │ ├── package-info.java │ │ │ ├── query │ │ │ ├── BreakForEach.java │ │ │ ├── EagerRelation.java │ │ │ ├── IdWithScore.java │ │ │ ├── InternalAccess.java │ │ │ ├── LazyList.java │ │ │ ├── LogicQueryCondition.java │ │ │ ├── ObjectWithScore.java │ │ │ ├── OrderFlags.java │ │ │ ├── PropertyQuery.java │ │ │ ├── PropertyQueryCondition.java │ │ │ ├── PropertyQueryConditionImpl.java │ │ │ ├── Query.java │ │ │ ├── QueryBuilder.java │ │ │ ├── QueryCondition.java │ │ │ ├── QueryConditionImpl.java │ │ │ ├── QueryConsumer.java │ │ │ ├── QueryFilter.java │ │ │ ├── QueryPublisher.java │ │ │ ├── QueryThreadLocal.java │ │ │ ├── RelationCountCondition.java │ │ │ └── package-info.java │ │ │ ├── reactive │ │ │ ├── DataObserver.java │ │ │ ├── DataPublisher.java │ │ │ ├── DataPublisherUtils.java │ │ │ ├── DataSubscription.java │ │ │ ├── DataSubscriptionImpl.java │ │ │ ├── DataSubscriptionList.java │ │ │ ├── DataTransformer.java │ │ │ ├── DelegatingObserver.java │ │ │ ├── ErrorObserver.java │ │ │ ├── RunWithParam.java │ │ │ ├── Scheduler.java │ │ │ ├── Schedulers.java │ │ │ ├── SubscriptionBuilder.java │ │ │ ├── WeakDataObserver.java │ │ │ └── package-info.java │ │ │ ├── relation │ │ │ ├── ListFactory.java │ │ │ ├── RelationInfo.java │ │ │ ├── ToMany.java │ │ │ ├── ToOne.java │ │ │ └── package-info.java │ │ │ ├── sync │ │ │ ├── ConnectivityMonitor.java │ │ │ ├── Credentials.java │ │ │ ├── CredentialsType.java │ │ │ ├── ObjectsMessageBuilder.java │ │ │ ├── Sync.java │ │ │ ├── SyncBuilder.java │ │ │ ├── SyncChange.java │ │ │ ├── SyncClient.java │ │ │ ├── SyncClientImpl.java │ │ │ ├── SyncCredentials.java │ │ │ ├── SyncCredentialsToken.java │ │ │ ├── SyncCredentialsUserPassword.java │ │ │ ├── SyncFlags.java │ │ │ ├── SyncHybrid.java │ │ │ ├── SyncHybridBuilder.java │ │ │ ├── SyncLoginCodes.java │ │ │ ├── SyncState.java │ │ │ ├── internal │ │ │ │ └── Platform.java │ │ │ ├── listener │ │ │ │ ├── AbstractSyncListener.java │ │ │ │ ├── SyncChangeListener.java │ │ │ │ ├── SyncCompletedListener.java │ │ │ │ ├── SyncConnectionListener.java │ │ │ │ ├── SyncListener.java │ │ │ │ ├── SyncLoginListener.java │ │ │ │ └── SyncTimeListener.java │ │ │ ├── package-info.java │ │ │ └── server │ │ │ │ ├── ClusterFlags.java │ │ │ │ ├── ClusterPeerConfig.java │ │ │ │ ├── ClusterPeerInfo.java │ │ │ │ ├── JwtConfig.java │ │ │ │ ├── SyncServer.java │ │ │ │ ├── SyncServerBuilder.java │ │ │ │ ├── SyncServerFlags.java │ │ │ │ ├── SyncServerImpl.java │ │ │ │ └── SyncServerOptions.java │ │ │ └── tree │ │ │ ├── Branch.java │ │ │ ├── Leaf.java │ │ │ ├── LeafNode.java │ │ │ ├── Tree.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── proguard │ │ └── objectbox-java.pro │ └── web │ └── overview.html ├── objectbox-kotlin ├── build.gradle └── src │ └── main │ └── kotlin │ └── io │ └── objectbox │ └── kotlin │ ├── Box.kt │ ├── BoxStore.kt │ ├── Flow.kt │ ├── Property.kt │ ├── PropertyQueryCondition.kt │ ├── QueryBuilder.kt │ ├── QueryCondition.kt │ └── ToMany.kt ├── objectbox-rxjava ├── README.md ├── build.gradle └── src │ ├── main │ └── java │ │ └── io │ │ └── objectbox │ │ └── rx │ │ ├── RxBoxStore.java │ │ └── RxQuery.java │ └── test │ └── java │ └── io │ └── objectbox │ ├── query │ ├── FakeQueryPublisher.java │ └── MockQuery.java │ └── rx │ └── QueryObserverTest.java ├── objectbox-rxjava3 ├── README.md ├── build.gradle └── src │ ├── main │ └── java │ │ └── io │ │ └── objectbox │ │ └── rx3 │ │ ├── Query.kt │ │ ├── RxBoxStore.java │ │ └── RxQuery.java │ └── test │ └── java │ └── io │ └── objectbox │ ├── query │ ├── FakeQueryPublisher.java │ └── MockQuery.java │ └── rx3 │ ├── QueryKtxTest.kt │ └── QueryObserverTest.java ├── scripts ├── test-with-asan.sh └── update-flatbuffers.sh ├── settings.gradle.kts └── tests ├── README.md ├── objectbox-java-test ├── build.gradle.kts └── src │ ├── main │ └── java │ │ └── io │ │ └── objectbox │ │ ├── TestEntity.java │ │ ├── TestEntityCursor.java │ │ ├── TestEntityMinimal.java │ │ ├── TestEntityMinimalCursor.java │ │ ├── TestEntityMinimal_.java │ │ ├── TestEntity_.java │ │ ├── index │ │ └── model │ │ │ ├── EntityLongIndex.java │ │ │ ├── EntityLongIndexCursor.java │ │ │ ├── EntityLongIndex_.java │ │ │ └── MyObjectBox.java │ │ └── relation │ │ ├── Customer.java │ │ ├── CustomerCursor.java │ │ ├── Customer_.java │ │ ├── MyObjectBox.java │ │ ├── Order.java │ │ ├── OrderCursor.java │ │ └── Order_.java │ └── test │ ├── java │ └── io │ │ └── objectbox │ │ ├── AbstractObjectBoxTest.java │ │ ├── BoxStoreBuilderTest.java │ │ ├── BoxStoreTest.java │ │ ├── BoxStoreTestK.kt │ │ ├── BoxStoreValidationTest.java │ │ ├── BoxTest.java │ │ ├── CursorBytesTest.java │ │ ├── CursorTest.java │ │ ├── DebugCursorTest.java │ │ ├── FlowTest.kt │ │ ├── JniBasicsTest.java │ │ ├── NonArgConstructorTest.java │ │ ├── ObjectClassObserverTest.java │ │ ├── TestUtils.java │ │ ├── TransactionTest.java │ │ ├── Utf8HashIndexTest.java │ │ ├── Utf8Test.java │ │ ├── Utf8ValueIndexTest.java │ │ ├── converter │ │ ├── FlexMapConverterTest.java │ │ ├── FlexObjectConverterTest.java │ │ └── StringMapConverterTest.java │ │ ├── exception │ │ └── ExceptionTest.java │ │ ├── index │ │ └── IndexReaderRenewTest.java │ │ ├── query │ │ ├── AbstractQueryTest.java │ │ ├── FlexQueryTest.java │ │ ├── LazyListTest.java │ │ ├── PropertyQueryTest.java │ │ ├── QueryCopyTest.java │ │ ├── QueryFilterComparatorTest.java │ │ ├── QueryObserverTest.java │ │ ├── QueryRelationCountTest.java │ │ ├── QueryScalarVectorTest.java │ │ ├── QueryTest.java │ │ ├── QueryTest2.java │ │ └── QueryTestK.kt │ │ ├── relation │ │ ├── AbstractRelationTest.java │ │ ├── ExternalTypeTest.java │ │ ├── LinkQueryTest.java │ │ ├── MultithreadedRelationTest.java │ │ ├── RelationEagerTest.java │ │ ├── RelationTest.java │ │ ├── ToManyStandaloneTest.java │ │ ├── ToManyTest.java │ │ └── ToOneTest.java │ │ ├── sync │ │ ├── ConnectivityMonitorTest.java │ │ ├── PlatformTest.java │ │ └── SyncTest.java │ │ └── tree │ │ ├── DataBranch.java │ │ ├── DataBranchCursor.java │ │ ├── DataBranch_.java │ │ ├── DataLeaf.java │ │ ├── DataLeafCursor.java │ │ ├── DataLeaf_.java │ │ ├── MetaBranch.java │ │ ├── MetaBranchCursor.java │ │ ├── MetaBranch_.java │ │ ├── MetaLeaf.java │ │ ├── MetaLeafCursor.java │ │ ├── MetaLeaf_.java │ │ ├── MyTreeModel.java │ │ └── TreeTest.java │ └── resources │ └── io │ └── objectbox │ ├── corrupt-keysize0-data.mdb │ └── corrupt-pageno-in-branch-data.mdb └── test-proguard ├── build.gradle.kts ├── proguard-android-optimize.txt └── src ├── main └── java │ └── io │ └── objectbox │ └── test │ └── proguard │ ├── MyObjectBox.java │ ├── ObfuscatedEntity.java │ ├── ObfuscatedEntityCursor.java │ └── ObfuscatedEntity_.java └── test └── java └── io └── objectbox └── test └── proguard └── ObfuscatedEntityTest.java /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Question 4 | url: https://stackoverflow.com/questions/tagged/objectbox 5 | about: Ask how to do something, or why it isn't working on Stack Overflow. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an improvement for ObjectBox. 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 18 | 19 | ### Is there an existing issue? 20 | 21 | - [ ] I have searched [existing issues](https://github.com/objectbox/objectbox-java/issues) 22 | 23 | ### Use case 24 | 25 | _TODO Describe what problem you are trying to solve._ 26 | 27 | ### Proposed solution 28 | 29 | _TODO Describe what you want to be able to do with ObjectBox._ 30 | 31 | ### Alternatives 32 | 33 | _TODO Describe any alternative solutions or features you've considered._ 34 | 35 | ### Additional context 36 | 37 | _TODO Add any other context (e.g. platform or language) about the feature request here._ 38 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Please see the documentation for all configuration options: 2 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 3 | 4 | version: 2 5 | updates: 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | interval: "weekly" 10 | -------------------------------------------------------------------------------- /.github/workflows/close-no-response.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "15 1 * * *" # “At 01:15.” 5 | workflow_dispatch: # To support running manually. 6 | 7 | # Minimal access by default 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | close-issues: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | issues: write 16 | pull-requests: write 17 | steps: 18 | # https://github.com/marketplace/actions/close-stale-issues 19 | - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9.0.0 20 | with: 21 | days-before-stale: -1 # Add the stale label manually. 22 | days-before-close: 21 23 | only-labels: "more info required" 24 | stale-issue-label: "more info required" 25 | close-issue-message: "Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue." 26 | close-pr-message: "Without additional information, we are unfortunately not sure how to address this pull request. Therefore this pull request has been automatically closed. Feel free to comment with additional details or submit a new pull request." 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # IntelliJ Idea 4 | .idea/ 5 | *.iml 6 | 7 | # Gradle & Java build 8 | .gradle 9 | build/ 10 | bin/ 11 | gen/ 12 | target/ 13 | out/ 14 | classes/ 15 | 16 | # Local build properties 17 | build.properties 18 | local.properties 19 | 20 | # Native libs 21 | objectbox*.dll 22 | libobjectbox*.so 23 | libobjectbox*.dylib 24 | 25 | ### Test DB files 26 | data.mdb 27 | lock.mdb 28 | test-db/ 29 | jni-unit-test-db/ 30 | test-db64/ 31 | perf-test-db/ 32 | perf-test-db64/ 33 | 34 | ## Backups 35 | .gitignore~ 36 | *.txt~ 37 | default.json.bak 38 | 39 | # Java crash reports 40 | hs_err_pid*.log 41 | -------------------------------------------------------------------------------- /.gitlab/merge_request_templates/Default.md: -------------------------------------------------------------------------------- 1 | ## What does this merge request do? 2 | 3 | TODO Link associated issue from title, like: ` #NUMBER` 4 | 5 | TODO Briefly list what this merge request is about 6 | 7 | ## Author's checklist 8 | 9 | - [ ] This merge request fully addresses the requirements of the associated task 10 | - [ ] I did a self-review of the changes and did not spot any issues, among others: 11 | - I added unit tests for new or changed behavior; existing and new tests pass 12 | - My code conforms to our coding standards and guidelines 13 | - My changes are prepared (focused commits, good messages) so reviewing them is easy for the reviewer 14 | - [ ] I amended the [changelog](/CHANGELOG.md) if this affects users in any way 15 | - [ ] I assigned a reviewer to request review 16 | 17 | ## Reviewer's checklist 18 | 19 | - [ ] I reviewed all changes line-by-line and addressed relevant issues. However: 20 | - for quickly resolved issues, I considered creating a fixup commit and discussing that, and 21 | - instead of many or long comments, I considered a meeting with or a draft commit for the author. 22 | - [ ] The requirements of the associated task are fully met 23 | - [ ] I can confirm that: 24 | - CI passes 25 | - If applicable, coverage percentages do not decrease 26 | - New code conforms to standards and guidelines 27 | - If applicable, additional checks were done for special code changes (e.g. core performance, binary size, OSS licenses) 28 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | // Recommended to create, but keep empty 2 | // https://docs.gradle.org/current/userguide/custom_plugins.html#sec:precompiled_plugins -------------------------------------------------------------------------------- /ci/send-to-gchat.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | if [[ "$#" -lt "2" ]]; then 5 | echo "Please supply at least 2 parameters: gchat-webhook-url [--thread threadID] text" 6 | echo "Text formatting: https://developers.google.com/chat/reference/message-formats/basic" 7 | exit 1 8 | fi 9 | 10 | gchat_url=$1 11 | shift 12 | 13 | if [[ "$1" == "--thread" ]]; then 14 | if [[ "$#" -lt "3" ]]; then 15 | echo "Not enough parameters supplied" 16 | exit 1 17 | fi 18 | #https://developers.google.com/chat/reference/rest/v1/spaces.messages/create 19 | gchat_url="$gchat_url&threadKey=$2" 20 | shift 2 21 | fi 22 | 23 | #https://developers.google.com/chat/reference/rest/v1/spaces.messages 24 | gchat_json="{\"text\": \"$*\"}" 25 | 26 | curl -X POST -H 'Content-Type: application/json' "$gchat_url" -d "${gchat_json}" || true 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Gradle configuration 2 | # https://docs.gradle.org/current/userguide/build_environment.html 3 | 4 | # To support Unicode characters in source code, set UTF-8 as the file encoding for the Gradle daemon, 5 | # which will make most Java tools use it instead of the default system file encoding. Note that for API docs, 6 | # the javadoc tool must be configured separately, see the root build script. 7 | # https://docs.gradle.org/current/userguide/common_caching_problems.html#system_file_encoding 8 | org.gradle.jvmargs=-Dfile.encoding=UTF-8 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-java/c84c0822c6d8e50ad9008794a3aa5e9913bc4a83/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-java/c84c0822c6d8e50ad9008794a3aa5e9913bc4a83/logo.png -------------------------------------------------------------------------------- /objectbox-java-api/NOTICE: -------------------------------------------------------------------------------- 1 | ObjectBox (c) Copyright 2017 by ObjectBox Ltd 2 | All rights reserved 3 | 4 | This product includes software developed at objectbox.io -------------------------------------------------------------------------------- /objectbox-java-api/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | id("objectbox-publish") 4 | } 5 | 6 | // Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used. 7 | // https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation 8 | tasks.withType(JavaCompile).configureEach { 9 | options.release.set(8) 10 | } 11 | 12 | tasks.register('javadocJar', Jar) { 13 | dependsOn javadoc 14 | archiveClassifier.set('javadoc') 15 | from 'build/docs/javadoc' 16 | } 17 | 18 | tasks.register('sourcesJar', Jar) { 19 | from sourceSets.main.allSource 20 | archiveClassifier.set('sources') 21 | } 22 | 23 | // Set project-specific properties. 24 | publishing.publications { 25 | mavenJava(MavenPublication) { 26 | from components.java 27 | artifact sourcesJar 28 | artifact javadocJar 29 | pom { 30 | name = 'ObjectBox API' 31 | description = 'ObjectBox is a fast NoSQL database for Objects' 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Backlink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import io.objectbox.annotation.apihint.Beta; 25 | 26 | /** 27 | * Defines a backlink relation, which is based on another relation reversing the direction. 28 | * <p> 29 | * Example (to-one relation): one "Order" references one "Customer". 30 | * The backlink to this is a to-many in the reverse direction: one "Customer" has a number of "Order"s. 31 | * <p> 32 | * Example (to-many relation): one "Teacher" references multiple "Student"s. 33 | * The backlink to this: one "Student" has a number of "Teacher"s. 34 | * <p> 35 | * Note: changes made to a backlink relation based on a to-many relation are ignored. 36 | */ 37 | @Retention(RetentionPolicy.CLASS) 38 | @Target(ElementType.FIELD) 39 | @Beta 40 | public @interface Backlink { 41 | /** 42 | * Name of the relation the backlink should be based on (e.g. name of a ToOne or ToMany property in the target entity). 43 | * Can be left empty if there is just a single relation from the target to the source entity. 44 | */ 45 | String to() default ""; 46 | } 47 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/BaseEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Marks a class as an ObjectBox Entity super class. 26 | * ObjectBox will store properties of this class as part of an Entity that inherits from this class. 27 | * See <a href="https://docs.objectbox.io/advanced/entity-inheritance">the Entity Inheritance documentation</a> for details. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target(ElementType.TYPE) 31 | public @interface BaseEntity { 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/ConflictStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | /** 20 | * Used with {@link Unique} to specify the conflict resolution strategy. 21 | */ 22 | public enum ConflictStrategy { 23 | 24 | /** 25 | * Throws UniqueViolationException if any property violates a {@link Unique} constraint. 26 | */ 27 | FAIL, 28 | /** 29 | * Any conflicting objects are deleted before the object is inserted. 30 | */ 31 | REPLACE 32 | 33 | } 34 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Convert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | import io.objectbox.converter.PropertyConverter; 25 | 26 | /** 27 | * Supplies a {@link PropertyConverter converter} to store custom Property types as a supported {@link #dbType()}. 28 | * See the <a href="https://docs.objectbox.io/advanced/custom-types">Custom Types documentation</a> for details. 29 | */ 30 | @Retention(RetentionPolicy.CLASS) 31 | @Target(ElementType.FIELD) 32 | public @interface Convert { 33 | /** 34 | * The converter class that ObjectBox should use. See {@link PropertyConverter} for implementation guidelines. 35 | */ 36 | Class<? extends PropertyConverter> converter(); 37 | 38 | /** 39 | * The Property type the Java field value is converted to/from. 40 | * See the <a href="https://docs.objectbox.io/advanced/custom-types">Custom Types documentation</a> for a list 41 | * of supported types. 42 | */ 43 | Class dbType(); 44 | } 45 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/DatabaseType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | /** 20 | * Use with {@link Type @Type} to override how a property value is stored and interpreted in the database. 21 | */ 22 | public enum DatabaseType { 23 | 24 | /** 25 | * Use with 64-bit long properties to store them as high precision time 26 | * representing nanoseconds since 1970-01-01 (unix epoch). 27 | * <p> 28 | * By default, a 64-bit long value is interpreted as time in milliseconds (a Date). 29 | */ 30 | DateNano 31 | 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/DefaultValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Defines the Java code of the default value to use for a property, when getting an existing entity and the database 26 | * value for the property is null. 27 | * <p> 28 | * Currently only {@code @DefaultValue("")} is supported. 29 | */ 30 | @Retention(RetentionPolicy.CLASS) 31 | @Target({ElementType.FIELD}) 32 | public @interface DefaultValue { 33 | String value(); 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/ExternalType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * Sets the type of a property or the type of object IDs of a ToMany in an external system (like another database). 27 | * <p> 28 | * This is useful if there is no default mapping of the ObjectBox type to the type in the external system. 29 | * <p> 30 | * Carefully look at the documentation of the external type to ensure it is compatible with the ObjectBox type. 31 | */ 32 | @Retention(RetentionPolicy.CLASS) 33 | @Target({ElementType.FIELD}) 34 | public @interface ExternalType { 35 | 36 | ExternalPropertyType value(); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/HnswFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | /** 20 | * Flags as a part of the {@link HnswIndex} configuration. 21 | */ 22 | public @interface HnswFlags { 23 | 24 | /** 25 | * Enables debug logs. 26 | */ 27 | boolean debugLogs() default false; 28 | 29 | /** 30 | * Enables "high volume" debug logs, e.g. individual gets/puts. 31 | */ 32 | boolean debugLogsDetailed() default false; 33 | 34 | /** 35 | * Padding for SIMD is enabled by default, which uses more memory but may be faster. This flag turns it off. 36 | */ 37 | boolean vectorCacheSimdPaddingOff() default false; 38 | 39 | /** 40 | * If the speed of removing nodes becomes a concern in your use case, you can speed it up by setting this flag. By 41 | * default, repairing the graph after node removals creates more connections to improve the graph's quality. The 42 | * extra costs for this are relatively low (e.g. vs. regular indexing), and thus the default is recommended. 43 | */ 44 | boolean reparationLimitCandidates() default false; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Marks the ID property of an {@link Entity @Entity}. 26 | * The property must be of type long (or Long in Kotlin) and have not-private visibility 27 | * (or a not-private getter and setter method). 28 | * <p> 29 | * ID properties are unique and indexed by default. 30 | */ 31 | @Retention(RetentionPolicy.CLASS) 32 | @Target(ElementType.FIELD) 33 | public @interface Id { 34 | // /** 35 | // * Specifies that id should increase monotonic without reusing IDs. This decreases performance a little bit for 36 | // * putting new objects (inserts) because the state needs to be persisted. Gaps between two IDs may still occur, 37 | // * e.g. if inserts are rollbacked. 38 | // */ 39 | // boolean monotonic() default false; 40 | 41 | /** 42 | * Allows IDs of new entities to be assigned manually. 43 | * Warning: This has side effects, check the online documentation on self-assigned object IDs for details. 44 | * <p> 45 | * This may allow re-use of IDs assigned elsewhere, e.g. by a server. 46 | */ 47 | boolean assignable() default false; 48 | } 49 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/IdCompanion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Marks a property as a companion to an @Id property. There can only be one companion property. 26 | * <p> 27 | * By defining an @Id companion property, the entity type uses a special ID encoding scheme involving this property 28 | * in addition to the ID. 29 | * <p> 30 | * For Time Series IDs, a companion property of type Date or DateNano represents the exact timestamp. 31 | */ 32 | @Retention(RetentionPolicy.CLASS) 33 | @Target(ElementType.FIELD) 34 | public @interface IdCompanion { 35 | } 36 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Index.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2018 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Specifies that the property should be indexed. 26 | * <p> 27 | * It is highly recommended to index properties that are used in a query to improve query performance. 28 | * When building a query, make sure to use case sensitive String conditions to utilize the index. 29 | * <p> 30 | * To fine tune indexing of a property you can override the default index {@link #type()}. 31 | * <p> 32 | * Note: indexes are currently not supported for string array, byte array, float or double properties. 33 | */ 34 | @Retention(RetentionPolicy.CLASS) 35 | @Target(ElementType.FIELD) 36 | public @interface Index { 37 | /** 38 | * Sets the {@link IndexType}, defaults to {@link IndexType#DEFAULT}. 39 | */ 40 | IndexType type() default IndexType.DEFAULT; 41 | } 42 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/IndexType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | /** 20 | * ObjectBox offers a value and two hash index types, from which it chooses a reasonable default (see {@link #DEFAULT}). 21 | * <p> 22 | * For some queries/use cases it might make sense to override the default choice for optimization purposes. 23 | * <p> 24 | * Note: hash indexes are currently only supported for string properties. 25 | */ 26 | public enum IndexType { 27 | /** 28 | * Use the default index type depending on the property type: 29 | * {@link #VALUE} for scalars and {@link #HASH} for Strings. 30 | */ 31 | DEFAULT, 32 | 33 | /** 34 | * Use the property value to build the index. 35 | * For Strings this may occupy more space than the default setting. 36 | */ 37 | VALUE, 38 | 39 | /** 40 | * Use a (fast non-cryptographic) hash of the property value to build the index. 41 | * Internally, it uses a 32 bit hash with a decent hash collision behavior. 42 | * Because occasional collisions do not really impact performance, this is usually a better choice than 43 | * {@link #HASH64} as it takes less space. 44 | */ 45 | HASH, 46 | 47 | /** 48 | * Use a long (fast non-cryptographic) hash of the property value to build the index. 49 | */ 50 | HASH64 51 | } 52 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/NameInDb.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Allows to specify a simple name mapping for entities and properties. 26 | * If names have diverged on the Java side (vs. the DB), you can specify the name used in the database here. 27 | * This allows simple renames in Java. For more advanced renames you should consider @{@link Uid} instead. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ElementType.FIELD, ElementType.TYPE}) 31 | public @interface NameInDb { 32 | /** 33 | * Name used in the database. 34 | */ 35 | String value(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/NotNull.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Specifies that property is not null 26 | * <p> 27 | * You can also use any another NotNull or NonNull annotation (from any library or your own), 28 | * they are equal to using this 29 | * </p> 30 | */ 31 | @Retention(RetentionPolicy.CLASS) 32 | @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) 33 | /* TODO public */ @interface NotNull { 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/OrderBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Specifies ordering of related collection of {@link Relation} relation 26 | * E.g.: @OrderBy("name, age DESC") List collection; 27 | * If used as marker (@OrderBy List collection), then collection is ordered by primary key 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target(ElementType.FIELD) 31 | /* TODO public */ @interface OrderBy { 32 | /** 33 | * Comma-separated list of properties, e.g. "propertyA, propertyB, propertyC" 34 | * To specify direction, add ASC or DESC after property name, e.g.: "propertyA DESC, propertyB ASC" 35 | * Default direction for each property is ASC 36 | * If value is omitted, then collection is ordered by primary key 37 | */ 38 | String value() default ""; 39 | } 40 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/TargetIdProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Defines the property serving as the target ID of a ToOne. 26 | * This allows exposing an explicit property, which may be convenient for other parsers/serializers (e.g. JSON). 27 | */ 28 | @Retention(RetentionPolicy.CLASS) 29 | @Target({ElementType.FIELD, ElementType.TYPE}) 30 | public @interface TargetIdProperty { 31 | /** 32 | * Name used in the database. 33 | */ 34 | String value(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Transient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | 24 | import static java.lang.annotation.RetentionPolicy.CLASS; 25 | 26 | /** 27 | * Transient fields are not persisted in the database. 28 | */ 29 | @Retention(CLASS) 30 | @Target(ElementType.FIELD) 31 | public @interface Transient { 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Type.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Use on a property to override how its value is stored and interpreted in the database. 26 | * <p> 27 | * For example to change a long to be interpreted as nanoseconds instead of milliseconds: 28 | * <pre> 29 | * @Type(DatabaseType.DateNano) 30 | * public long timeInNanos; 31 | * </pre> 32 | */ 33 | @Retention(RetentionPolicy.CLASS) 34 | @Target({ElementType.FIELD}) 35 | public @interface Type { 36 | 37 | DatabaseType value(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Uid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | 25 | /** 26 | * UIDs identify entities (and properties) uniquely in the meta object model file (objectbox-model/default.json). 27 | * With UIDs you can map entities to their meta model representation in a stable way without its name. 28 | * Once a UID is set, you can rename the entity as often as you like - ObjectBox keeps track of it automatically. 29 | * Thus, it is advisable to lookup the UID in objectbox-model/default.json and use it here before renaming a entity. 30 | */ 31 | @Retention(RetentionPolicy.CLASS) 32 | @Target({ElementType.FIELD, ElementType.TYPE}) 33 | public @interface Uid { 34 | /** 35 | * The UID associated with an entity/property. 36 | * <p> 37 | * Special values: 38 | * <ul> 39 | * <li>empty (or zero): and the ObjectBox Gradle plugin will set it automatically to the current value.</li> 40 | * <li>-1: will assign a new ID and UID forcing the property/entity to be treated as new 41 | * (for entities: all property IDs and UIDs will be renewed too)</li> 42 | * </ul> 43 | */ 44 | long value() default 0; 45 | } 46 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Unique.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Enforces that the value of a property is unique among all objects in a box before an object can be put. 26 | * <p> 27 | * Trying to put an object with offending values will result in a UniqueViolationException (see {@link ConflictStrategy#FAIL}). 28 | * Set {@link #onConflict()} to change this strategy. 29 | * <p> 30 | * Note: Unique properties are based on an {@link Index @Index}, so the same restrictions apply. 31 | * It is supported to explicitly add the {@link Index @Index} annotation to configure the index. 32 | */ 33 | @Retention(RetentionPolicy.CLASS) 34 | @Target(ElementType.FIELD) 35 | public @interface Unique { 36 | 37 | /** 38 | * The strategy to use when a conflict is detected when an object is put. 39 | */ 40 | ConflictStrategy onConflict() default ConflictStrategy.FAIL; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/Unsigned.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Indicates that values of an integer property (e.g. int and long in Java) 26 | * should be treated as unsigned when doing queries or creating indexes. 27 | * <p> 28 | * For example consider a set of integers sorted by the default order: [-2, -1, 0, 1, 2]. 29 | * If all values are treated as unsigned, the order would be [0, 1, 2, -2, -1] instead. 30 | */ 31 | @Retention(RetentionPolicy.CLASS) 32 | @Target(ElementType.FIELD) 33 | public @interface Unsigned { 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/apihint/Beta.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation.apihint; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * APIs annotated with @Beta may change and may be even removed in a future release (but is somewhat less likely 27 | * compared to {@link Experimental}). You can still use this API - just be aware that a future version may require 28 | * changes of your code. This is intended for getting feedback on planned features. 29 | */ 30 | @Retention(RetentionPolicy.CLASS) 31 | @Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) 32 | @Documented 33 | public @interface Beta { 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/apihint/Experimental.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation.apihint; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * APIs annotated with @Experimental are likely to change and may be even removed in a future release. 27 | * You can use this API - just be aware that a future version may require changes of your code. 28 | * This is intended for getting feedback on planned features. 29 | */ 30 | @Retention(RetentionPolicy.CLASS) 31 | @Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) 32 | @Documented 33 | public @interface Experimental { 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/apihint/Internal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.annotation.apihint; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | /** 26 | * APIs annotated with @Internal must NOT be used. 27 | * Internal APIs must only be used by ObjectBox and may change or be removed in a future release. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.TYPE}) 31 | @Internal 32 | @Documented 33 | public @interface Internal { 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/apihint/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Annotations to mark APIs as for example {@link io.objectbox.annotation.apihint.Internal @Internal} 19 | * or {@link io.objectbox.annotation.apihint.Experimental @Experimental}. 20 | */ 21 | package io.objectbox.annotation.apihint; -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Annotations to mark a class as an {@link io.objectbox.annotation.Entity @Entity}, 19 | * to specify the {@link io.objectbox.annotation.Id @Id} Property, 20 | * to create an {@link io.objectbox.annotation.Index @Index} or 21 | * a {@link io.objectbox.annotation.Transient @Transient} Property. 22 | * <p> 23 | * For more details look at the documentation of individual classes and 24 | * <a href="https://docs.objectbox.io/entity-annotations">docs.objectbox.io/entity-annotations</a>. 25 | */ 26 | package io.objectbox.annotation; -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/converter/PropertyConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | /** 20 | * To use custom types in your entity, implement this to convert db values to entity values and back. 21 | * <p> 22 | * Notes for implementations: 23 | * <ul> 24 | * <li>Converters are created by the default constructor</li> 25 | * <li>Converters must be implemented thread-safe</li> 26 | * <li>Converters must not interact with the database (such as using Box or BoxStore)</li> 27 | * <li>Converters must handle null values</li> 28 | * </ul> 29 | */ 30 | public interface PropertyConverter<P, D> { 31 | P convertToEntityProperty(D databaseValue); 32 | 33 | D convertToDatabaseValue(P entityProperty); 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java-api/src/main/java/io/objectbox/converter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * For use with {@link io.objectbox.annotation.Convert @Convert}: {@link io.objectbox.converter.PropertyConverter} 19 | * to convert custom Property types. 20 | * <p> 21 | * For more details look at the documentation of individual classes and 22 | * <a href="https://docs.objectbox.io/advanced/custom-types">docs.objectbox.io/advanced/custom-types</a>. 23 | */ 24 | package io.objectbox.converter; -------------------------------------------------------------------------------- /objectbox-java/spotbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <FindBugsFilter> 3 | <!-- Hint: to use regex, prefix with ~. https://spotbugs.readthedocs.io/en/stable/filter.html --> 4 | <!-- Exclude FlatBuffers generated code, compare with /scripts/flatc-idls.sh of core project. --> 5 | <Match> 6 | <Class name="io.objectbox.DebugFlags" /> 7 | </Match> 8 | <Match> 9 | <Package name="io.objectbox.config" /> 10 | </Match> 11 | <Match> 12 | <Package name="io.objectbox.model" /> 13 | </Match> 14 | <Match> 15 | <Class name="io.objectbox.query.OrderFlags" /> 16 | </Match> 17 | <!-- Exclude FlatBuffers source code. --> 18 | <Match> 19 | <Package name="io.objectbox.flatbuffers" /> 20 | </Match> 21 | </FindBugsFilter> -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/EntityInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox; 18 | 19 | import java.io.Serializable; 20 | 21 | import io.objectbox.annotation.apihint.Internal; 22 | import io.objectbox.internal.CursorFactory; 23 | import io.objectbox.internal.IdGetter; 24 | 25 | @Internal 26 | public interface EntityInfo<T> extends Serializable { 27 | String getEntityName(); 28 | 29 | String getDbName(); 30 | 31 | Class<T> getEntityClass(); 32 | 33 | int getEntityId(); 34 | 35 | Property<T>[] getAllProperties(); 36 | 37 | Property<T> getIdProperty(); 38 | 39 | IdGetter<T> getIdGetter(); 40 | 41 | CursorFactory<T> getCursorFactory(); 42 | 43 | // TODO replace reflection: BoxGetter<T> getBoxGetter(); 44 | } 45 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/Factory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox; 18 | 19 | import io.objectbox.annotation.apihint.Experimental; 20 | 21 | 22 | /** 23 | * Generic Factory that provides a resource on demand (if and when it is required). 24 | */ 25 | @Experimental 26 | public interface Factory<T> { 27 | T provide() throws Exception; 28 | } 29 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/TxCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox; 18 | 19 | import java.util.concurrent.Callable; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | /** 24 | * Callback to be used for {@link BoxStore#runInTxAsync(Runnable, TxCallback)} and 25 | * {@link BoxStore#callInTxAsync(Callable, TxCallback)}. 26 | */ 27 | public interface TxCallback<T> { 28 | /** 29 | * Called when an asynchronous transaction finished. 30 | * 31 | * @param result Result of the callable {@link BoxStore#callInTxAsync(Callable, TxCallback)} 32 | * @param error non-null if an exception was thrown 33 | */ 34 | void txFinished(@Nullable T result, @Nullable Throwable error); 35 | } 36 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/config/ValidateOnOpenModeKv.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.config; 20 | 21 | /** 22 | * Defines if and how the database is checked for valid key/value (KV) entries when opening it. 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class ValidateOnOpenModeKv { 26 | private ValidateOnOpenModeKv() { } 27 | /** 28 | * Not a real type, just best practice (e.g. forward compatibility). 29 | */ 30 | public static final short Unknown = 0; 31 | /** 32 | * Performs standard checks. 33 | */ 34 | public static final short Regular = 1; 35 | 36 | public static final String[] names = { "Unknown", "Regular", }; 37 | 38 | public static String name(int e) { return names[e]; } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/IntegerFlexMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | /** 20 | * A {@link FlexObjectConverter} that uses {@link Integer} as map keys. 21 | * <p> 22 | * Used by default to convert {@code Map<Integer, V>}. 23 | */ 24 | public class IntegerFlexMapConverter extends FlexObjectConverter { 25 | 26 | @Override 27 | protected void checkMapKeyType(Object rawKey) { 28 | if (!(rawKey instanceof Integer)) { 29 | throw new IllegalArgumentException("Map keys must be Integer"); 30 | } 31 | } 32 | 33 | @Override 34 | Integer convertToKey(String keyValue) { 35 | return Integer.valueOf(keyValue); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/IntegerLongMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | import io.objectbox.flatbuffers.FlexBuffers; 20 | 21 | /** 22 | * Like {@link IntegerFlexMapConverter}, but always restores integer map values as {@link Long}. 23 | * <p> 24 | * Used by default to convert {@code Map<Integer, Long>}. 25 | */ 26 | public class IntegerLongMapConverter extends IntegerFlexMapConverter { 27 | @Override 28 | protected boolean shouldRestoreAsLong(FlexBuffers.Reference reference) { 29 | return true; // Restore all integers as java.lang.Long. 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/LongFlexMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | /** 20 | * A {@link FlexObjectConverter} that uses {@link Long} as map keys. 21 | * <p> 22 | * Used by default to convert {@code Map<Long, V>}. 23 | */ 24 | public class LongFlexMapConverter extends FlexObjectConverter { 25 | 26 | @Override 27 | protected void checkMapKeyType(Object rawKey) { 28 | if (!(rawKey instanceof Long)) { 29 | throw new IllegalArgumentException("Map keys must be Long"); 30 | } 31 | } 32 | 33 | @Override 34 | Object convertToKey(String keyValue) { 35 | return Long.valueOf(keyValue); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/LongLongMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | import io.objectbox.flatbuffers.FlexBuffers; 20 | 21 | /** 22 | * Like {@link LongFlexMapConverter}, but always restores integer map values as {@link Long}. 23 | * <p> 24 | * Used by default to convert {@code Map<Long, Long>}. 25 | */ 26 | public class LongLongMapConverter extends LongFlexMapConverter { 27 | @Override 28 | protected boolean shouldRestoreAsLong(FlexBuffers.Reference reference) { 29 | return true; // Restore all integers as java.lang.Long. 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/NullToEmptyStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | /** 22 | * Used as a converter if a property is annotated with {@link io.objectbox.annotation.DefaultValue @DefaultValue("")}. 23 | */ 24 | public class NullToEmptyStringConverter implements PropertyConverter<String, String> { 25 | 26 | @Override 27 | public String convertToDatabaseValue(String entityProperty) { 28 | return entityProperty; 29 | } 30 | 31 | @Override 32 | public String convertToEntityProperty(@Nullable String databaseValue) { 33 | if (databaseValue == null) { 34 | return ""; 35 | } 36 | return databaseValue; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/StringFlexMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | /** 20 | * A {@link FlexObjectConverter}. 21 | * <p> 22 | * Used by default to convert {@code Map<String, V>}. 23 | */ 24 | public class StringFlexMapConverter extends FlexObjectConverter { 25 | } 26 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/converter/StringLongMapConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.converter; 18 | 19 | import io.objectbox.flatbuffers.FlexBuffers; 20 | 21 | /** 22 | * Like {@link StringFlexMapConverter}, but always restores integer map values as {@link Long}. 23 | * <p> 24 | * Used by default to convert {@code Map<String, Long>}. 25 | */ 26 | public class StringLongMapConverter extends StringFlexMapConverter { 27 | @Override 28 | protected boolean shouldRestoreAsLong(FlexBuffers.Reference reference) { 29 | return true; // Restore all integers as java.lang.Long. 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/ConstraintViolationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** Base class for exceptions thrown when a constraint would be violated during a put operation. */ 20 | public class ConstraintViolationException extends DbException { 21 | public ConstraintViolationException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbDetachedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * This exception occurs while working with a {@link io.objectbox.relation.ToMany ToMany} or 21 | * {@link io.objectbox.relation.ToOne ToOne} of an object and the object is not attached to a 22 | * {@link io.objectbox.Box Box} (technically a {@link io.objectbox.BoxStore BoxStore}). 23 | * <p> 24 | * If your code uses <a href="https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids">manually assigned 25 | * IDs</a> make sure it takes care of some things that ObjectBox would normally do by itself. This includes 26 | * {@link io.objectbox.Box#attach(Object) attaching} the Box to an object before modifying a ToMany. 27 | * <p> 28 | * Also see the documentation about <a href="https://docs.objectbox.io/relations#updating-relations">Updating 29 | * Relations</a> and <a href="https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids">manually assigned 30 | * IDs</a> for details. 31 | */ 32 | public class DbDetachedException extends DbException { 33 | 34 | public DbDetachedException() { 35 | this("Entity must be attached to a Box."); 36 | } 37 | 38 | public DbDetachedException(String message) { 39 | super(message); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * General exception for things that may go wrong with the database. 21 | * Also base class for more concrete exceptions. 22 | */ 23 | public class DbException extends RuntimeException { 24 | private final int errorCode; 25 | 26 | public DbException(String message) { 27 | super(message); 28 | errorCode = 0; 29 | } 30 | 31 | public DbException(String message, Throwable cause) { 32 | super(message, cause); 33 | errorCode = 0; 34 | } 35 | 36 | public DbException(String message, int errorCode) { 37 | super(message); 38 | this.errorCode = errorCode; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return errorCode == 0 ? super.toString() : 44 | super.toString() + " (error code " + errorCode + ")"; 45 | } 46 | 47 | /** 0 == no error code available */ 48 | public int getErrorCode() { 49 | return errorCode; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbFullException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown when applying a database operation would exceed the (default) 21 | * {@link io.objectbox.BoxStoreBuilder#maxSizeInKByte(long) maxSizeInKByte} configured for the Store. 22 | * <p> 23 | * This can occur for operations like when an Object is {@link io.objectbox.Box#put(Object) put}, at the point when the 24 | * (internal) transaction is committed. Or when the Store is opened with a max size too small for the existing database. 25 | */ 26 | public class DbFullException extends DbException { 27 | public DbFullException(String message) { 28 | super(message); 29 | } 30 | 31 | public DbFullException(String message, int errorCode) { 32 | super(message, errorCode); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbMaxDataSizeExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown when applying a transaction would exceed the {@link io.objectbox.BoxStoreBuilder#maxDataSizeInKByte(long) maxDataSizeInKByte} 21 | * configured for the store. 22 | */ 23 | public class DbMaxDataSizeExceededException extends DbException { 24 | public DbMaxDataSizeExceededException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbMaxReadersExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | import io.objectbox.BoxStore; 20 | import io.objectbox.BoxStoreBuilder; 21 | 22 | /** 23 | * Thrown when the maximum of readers (read transactions) was exceeded. 24 | * Verify that your code only uses a reasonable amount of threads. 25 | * <p> 26 | * If a very high number of threads (>100) needs to be used, consider increasing the number of maximum readers 27 | * using {@link BoxStoreBuilder#maxReaders(int)} and enabling query retries using 28 | * {@link BoxStoreBuilder#queryAttempts(int)}. 29 | * <p> 30 | * For debugging issues related to this exception, check {@link BoxStore#diagnose()}. 31 | */ 32 | public class DbMaxReadersExceededException extends DbException { 33 | public DbMaxReadersExceededException(String message) { 34 | super(message); 35 | } 36 | 37 | public DbMaxReadersExceededException(String message, int errorCode) { 38 | super(message, errorCode); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbSchemaException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown when there is an error with the data schema (data model). 21 | * <p> 22 | * Typically, there is a conflict between the data model defined in your code (using {@link io.objectbox.annotation.Entity @Entity} 23 | * classes) and the data model of the existing database file. 24 | * <p> 25 | * Read the <a href="https://docs.objectbox.io/advanced/meta-model-ids-and-uids#resolving-meta-model-conflicts">meta model docs</a> 26 | * on why this can happen and how to resolve such conflicts. 27 | */ 28 | public class DbSchemaException extends DbException { 29 | public DbSchemaException(String message) { 30 | super(message); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/DbShutdownException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown when an error occurred that requires the store to be closed. 21 | * <p> 22 | * This may be an I/O error. Regular operations won't be possible. 23 | * To handle this exit the app or try to reopen the store. 24 | */ 25 | public class DbShutdownException extends DbException { 26 | public DbShutdownException(String message) { 27 | super(message); 28 | } 29 | 30 | public DbShutdownException(String message, int errorCode) { 31 | super(message, errorCode); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/FeatureNotAvailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown when a special feature was used, which is not part of the native library. 21 | * <p> 22 | * This typically indicates a developer error. Check that the correct dependencies for the native ObjectBox library are 23 | * included. 24 | */ 25 | public class FeatureNotAvailableException extends DbException { 26 | 27 | // Note: this constructor is called by JNI, check before modifying/removing it. 28 | public FeatureNotAvailableException(String message) { 29 | super(message); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/FileCorruptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.objectbox.exception; 17 | 18 | import io.objectbox.BoxStoreBuilder; 19 | 20 | /** 21 | * Errors were detected in a database file, e.g. illegal values or structural inconsistencies. 22 | * <p> 23 | * It may be possible to re-open the store with {@link BoxStoreBuilder#usePreviousCommit()} to restore 24 | * to a working state. 25 | */ 26 | public class FileCorruptException extends DbException { 27 | public FileCorruptException(String message) { 28 | super(message); 29 | } 30 | 31 | public FileCorruptException(String message, int errorCode) { 32 | super(message, errorCode); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/NonUniqueResultException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown if {@link io.objectbox.query.Query#findUnique() Query.findUnique()} or 21 | * {@link io.objectbox.query.Query#findUniqueId() Query.findUniqueId()} is called, 22 | * but the query matches more than one object. 23 | */ 24 | public class NonUniqueResultException extends DbException { 25 | public NonUniqueResultException(String message) { 26 | super(message); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/NumericOverflowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** 20 | * Thrown if a property query aggregate function can not compute a result due to a number type overflowing. 21 | */ 22 | public class NumericOverflowException extends DbException { 23 | 24 | public NumericOverflowException(String message) { 25 | super(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/PagesCorruptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.objectbox.exception; 17 | 18 | /** 19 | * Errors related to pages were detected in a database file, e.g. bad page refs outside of the file. 20 | */ 21 | public class PagesCorruptException extends FileCorruptException { 22 | public PagesCorruptException(String message) { 23 | super(message); 24 | } 25 | 26 | public PagesCorruptException(String message, int errorCode) { 27 | super(message, errorCode); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/UniqueViolationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2018 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.exception; 18 | 19 | /** Thrown when a @{@link io.objectbox.annotation.Unique} constraint would be violated during a put operation. */ 20 | public class UniqueViolationException extends ConstraintViolationException { 21 | public UniqueViolationException(String message) { 22 | super(message); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Various exceptions thrown by ObjectBox. 19 | */ 20 | package io.objectbox.exception; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/BooleanVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of booleans. 26 | */ 27 | public final class BooleanVector extends BaseVector { 28 | /** 29 | * Assigns vector access object to vector data. 30 | * 31 | * @param _vector Start data of a vector. 32 | * @param _bb Table's ByteBuffer. 33 | * @return Returns current vector access object assigned to vector data whose offset is stored at 34 | * `vector`. 35 | */ 36 | public BooleanVector __assign(int _vector, ByteBuffer _bb) { 37 | __reset(_vector, Constants.SIZEOF_BYTE, _bb); return this; 38 | } 39 | 40 | /** 41 | * Reads the boolean at the given index. 42 | * 43 | * @param j The index from which the boolean will be read. 44 | * @return the boolean value at the given index. 45 | */ 46 | public boolean get(int j) { 47 | return 0 != bb.get(__element(j)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/ByteBufferUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | /// @file 24 | /// @addtogroup flatbuffers_java_api 25 | /// @{ 26 | 27 | /** 28 | * Class that collects utility functions around `ByteBuffer`. 29 | */ 30 | public class ByteBufferUtil { 31 | 32 | /** 33 | * Extract the size prefix from a `ByteBuffer`. 34 | * 35 | * @param bb a size-prefixed buffer 36 | * @return the size prefix 37 | */ 38 | public static int getSizePrefix(ByteBuffer bb) { 39 | return bb.getInt(bb.position()); 40 | } 41 | 42 | /** 43 | * Create a duplicate of a size-prefixed `ByteBuffer` that has its position 44 | * advanced just past the size prefix. 45 | * 46 | * @param bb a size-prefixed buffer 47 | * @return a new buffer on the same underlying data that has skipped the 48 | * size prefix 49 | */ 50 | public static ByteBuffer removeSizePrefix(ByteBuffer bb) { 51 | ByteBuffer s = bb.duplicate(); 52 | s.position(s.position() + SIZE_PREFIX_LENGTH); 53 | return s; 54 | } 55 | 56 | } 57 | 58 | /// @} 59 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/DoubleVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of double values. 26 | */ 27 | public final class DoubleVector extends BaseVector { 28 | /** 29 | * Assigns vector access object to vector data. 30 | * 31 | * @param _vector Start data of a vector. 32 | * @param _bb Table's ByteBuffer. 33 | * @return Returns current vector access object assigned to vector data whose offset is stored at 34 | * `vector`. 35 | */ 36 | public DoubleVector __assign(int _vector, ByteBuffer _bb) { 37 | __reset(_vector, Constants.SIZEOF_DOUBLE, _bb); return this; 38 | } 39 | 40 | /** 41 | * Reads the double value at the given index. 42 | * 43 | * @param j The index from which the double value will be read. 44 | * @return the double value at the given index. 45 | */ 46 | public double get(int j) { 47 | return bb.getDouble(__element(j)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/FloatVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of float values. 26 | */ 27 | public final class FloatVector extends BaseVector { 28 | /** 29 | * Assigns vector access object to vector data. 30 | * 31 | * @param _vector Start data of a vector. 32 | * @param _bb Table's ByteBuffer. 33 | * @return Returns current vector access object assigned to vector data whose offset is stored at 34 | * `vector`. 35 | */ 36 | public FloatVector __assign(int _vector, ByteBuffer _bb) { 37 | __reset(_vector, Constants.SIZEOF_FLOAT, _bb); return this; 38 | } 39 | 40 | /** 41 | * Reads the float value at the given index. 42 | * 43 | * @param j The index from which the float value will be read. 44 | * @return the float value at the given index. 45 | */ 46 | public float get(int j) { 47 | return bb.getFloat(__element(j)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/LongVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of long values. 26 | */ 27 | public final class LongVector extends BaseVector { 28 | /** 29 | * Assigns vector access object to vector data. 30 | * 31 | * @param _vector Start data of a vector. 32 | * @param _bb Table's ByteBuffer. 33 | * @return Returns current vector access object assigned to vector data whose offset is stored at 34 | * `vector`. 35 | */ 36 | public LongVector __assign(int _vector, ByteBuffer _bb) { 37 | __reset(_vector, Constants.SIZEOF_LONG, _bb); return this; 38 | } 39 | 40 | /** 41 | * Reads the long value at the given index. 42 | * 43 | * @param j The index from which the long value will be read. 44 | * @return the signed 64-bit value at the given index. 45 | */ 46 | public long get(int j) { 47 | return bb.getLong(__element(j)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/README.md: -------------------------------------------------------------------------------- 1 | # FlatBuffers 2 | 3 | This is a copy of the [FlatBuffers](https://github.com/google/flatbuffers) for Java source code in a custom package 4 | to avoid conflicts with FlatBuffers generated Java code from users of this library. 5 | 6 | Current version: `23.5.26` (Note: version in `Constants.java` may be lower). 7 | 8 | Copy a different version using the script in `scripts\update-flatbuffers.sh`. 9 | It expects FlatBuffers source files in the `../flatbuffers` directory (e.g. check out 10 | the desired FlatBuffers tag from https://github.com/objectbox/flatbuffers next to this repo). 11 | The Java library is expected in `objectbox-java`, e.g. run the script from the root of this repo. 12 | 13 | ## Licensing 14 | 15 | Flatbuffers is licensed under the Apache License, Version 2.0. 16 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/StringVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of String. 26 | */ 27 | public final class StringVector extends BaseVector { 28 | private Utf8 utf8 = Utf8.getDefault(); 29 | 30 | /** 31 | * Assigns vector access object to vector data. 32 | * 33 | * @param _vector Start data of a vector. 34 | * @param _element_size Size of a vector element. 35 | * @param _bb Table's ByteBuffer. 36 | * @return Returns current vector access object assigned to vector data whose offset is stored at 37 | * `vector`. 38 | */ 39 | public StringVector __assign(int _vector, int _element_size, ByteBuffer _bb) { 40 | __reset(_vector, _element_size, _bb); return this; 41 | } 42 | 43 | /** 44 | * Reads the String at the given index. 45 | * 46 | * @param j The index from which the String value will be read. 47 | * @return the String at the given index. 48 | */ 49 | public String get(int j) { 50 | return Table.__string(__element(j), bb, utf8); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/flatbuffers/UnionVector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.flatbuffers; 18 | 19 | import static io.objectbox.flatbuffers.Constants.*; 20 | import java.nio.ByteBuffer; 21 | import java.nio.ByteOrder; 22 | import java.nio.charset.Charset; 23 | 24 | /** 25 | * Helper type for accessing vector of unions. 26 | */ 27 | public final class UnionVector extends BaseVector { 28 | /** 29 | * Assigns vector access object to vector data. 30 | * 31 | * @param _vector Start data of a vector. 32 | * @param _element_size Size of a vector element. 33 | * @param _bb Table's ByteBuffer. 34 | * @return Returns current vector access object assigned to vector data whose offset is stored at 35 | * `vector`. 36 | */ 37 | public UnionVector __assign(int _vector, int _element_size, ByteBuffer _bb) { 38 | __reset(_vector, _element_size, _bb); return this; 39 | } 40 | 41 | 42 | /** 43 | * Initialize any Table-derived type to point to the union at the given `index`. 44 | * 45 | * @param obj A `Table`-derived type that should point to the union at `index`. 46 | * @param j An `int` index into the union vector. 47 | * @return Returns the Table that points to the union at `index`. 48 | */ 49 | public Table get(Table obj, int j) { 50 | return Table.__union(obj, __element(j), bb); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/ideasonly/ModelUpdate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.ideasonly; 18 | 19 | public interface ModelUpdate { 20 | void updateModel(ModelModifier modifier, long oldVersion, long newVersion); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/CallWithHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | 21 | @Internal 22 | public interface CallWithHandle<RESULT> { 23 | RESULT call(long handle); 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/CursorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | import io.objectbox.BoxStore; 22 | import io.objectbox.Cursor; 23 | import io.objectbox.Transaction; 24 | import io.objectbox.annotation.apihint.Internal; 25 | 26 | @Internal 27 | public interface CursorFactory<T> { 28 | Cursor<T> createCursor(Transaction tx, long cursorHandle, @Nullable BoxStore boxStore); 29 | } 30 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/Feature.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.internal; 2 | 3 | /** 4 | * Use with {@link io.objectbox.BoxStore#hasFeature(Feature)}. 5 | */ 6 | public enum Feature { 7 | 8 | /** Internal feature, not relevant if using ObjectBox through JNI. */ 9 | RESULT_ARRAY(1), 10 | 11 | /** TimeSeries support (date/date-nano companion ID and other time-series functionality). */ 12 | TIME_SERIES(2), 13 | 14 | /** Sync client availability. Visit <a href="https://objectbox.io/sync">the ObjectBox Sync website</a> for more details. */ 15 | SYNC(3), 16 | 17 | /** Check whether debug log can be enabled during runtime. */ 18 | DEBUG_LOG(4), 19 | 20 | /** HTTP server with a database browser. */ 21 | ADMIN(5), 22 | 23 | /** Trees & GraphQL support */ 24 | TREES(6), 25 | 26 | /** Embedded Sync server availability. */ 27 | SYNC_SERVER(7); 28 | 29 | public final int id; 30 | 31 | Feature(int id) { 32 | this.id = id; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/IdGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | public interface IdGetter<T> { 20 | /** Given object must be non-null and have a non-null ID. */ 21 | long getId(T object); 22 | } 23 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/JniTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | public class JniTest { 20 | public static native boolean createAndDeleteIntArray(); 21 | 22 | public static native int[] returnIntArray(); 23 | } 24 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/ReflectionCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | import java.lang.reflect.Field; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | import javax.annotation.Nonnull; 24 | 25 | import io.objectbox.annotation.apihint.Internal; 26 | 27 | @Internal 28 | public class ReflectionCache { 29 | private static final ReflectionCache instance = new ReflectionCache(); 30 | 31 | public static ReflectionCache getInstance() { 32 | return instance; 33 | } 34 | 35 | private final Map<Class<?>, Map<String, Field>> fields = new HashMap<>(); 36 | 37 | @Nonnull 38 | public synchronized Field getField(Class<?> clazz, String name) { 39 | Map<String, Field> fieldsForClass = fields.get(clazz); 40 | if (fieldsForClass == null) { 41 | fieldsForClass = new HashMap<>(); 42 | fields.put(clazz, fieldsForClass); 43 | } 44 | Field field = fieldsForClass.get(name); 45 | if (field == null) { 46 | try { 47 | field = clazz.getDeclaredField(name); 48 | field.setAccessible(true); 49 | } catch (NoSuchFieldException e) { 50 | throw new IllegalStateException(e); 51 | } 52 | fieldsForClass.put(name, field); 53 | } 54 | return field; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/ToManyGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | import java.io.Serializable; 20 | import java.util.List; 21 | 22 | import io.objectbox.annotation.apihint.Internal; 23 | 24 | @Internal 25 | public interface ToManyGetter<SOURCE, TARGET> extends Serializable { 26 | List<TARGET> getToMany(SOURCE object); 27 | } 28 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/ToOneGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.internal; 18 | 19 | import java.io.Serializable; 20 | 21 | import io.objectbox.annotation.apihint.Internal; 22 | import io.objectbox.relation.ToOne; 23 | 24 | @Internal 25 | public interface ToOneGetter<SOURCE, TARGET> extends Serializable { 26 | ToOne<TARGET> getToOne(SOURCE object); 27 | } 28 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/internal/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | @ParametersAreNonnullByDefault 18 | package io.objectbox.internal; 19 | 20 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/model/HnswFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.model; 20 | 21 | /** 22 | * Flags as a part of the HNSW configuration. 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class HnswFlags { 26 | private HnswFlags() { } 27 | /** 28 | * Enables debug logs. 29 | */ 30 | public static final int DebugLogs = 1; 31 | /** 32 | * Enables "high volume" debug logs, e.g. individual gets/puts. 33 | */ 34 | public static final int DebugLogsDetailed = 2; 35 | /** 36 | * Padding for SIMD is enabled by default, which uses more memory but may be faster. This flag turns it off. 37 | */ 38 | public static final int VectorCacheSimdPaddingOff = 4; 39 | /** 40 | * If the speed of removing nodes becomes a concern in your use case, you can speed it up by setting this flag. 41 | * By default, repairing the graph after node removals creates more connections to improve the graph's quality. 42 | * The extra costs for this are relatively low (e.g. vs. regular indexing), and thus the default is recommended. 43 | */ 44 | public static final int ReparationLimitCandidates = 8; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * ObjectBox is an an easy to use, object-oriented lightweight database and a full alternative to SQLite. 19 | * <p> 20 | * The following core classes are the essential interface to ObjectBox: 21 | * <ul> 22 | * <li>MyObjectBox: Generated by the Gradle plugin, supplies a {@link io.objectbox.BoxStoreBuilder} 23 | * to build a BoxStore for your app.</li> 24 | * <li>{@link io.objectbox.BoxStore}: The database interface, allows to manage Boxes.</li> 25 | * <li>{@link io.objectbox.Box}: Persists and queries for Objects, there is one for each Entity class.</li> 26 | * </ul> 27 | * <p> 28 | * For more details look at the documentation of individual classes and 29 | * <a href="https://docs.objectbox.io">docs.objectbox.io</a>. 30 | */ 31 | @ParametersAreNonnullByDefault 32 | package io.objectbox; 33 | 34 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/BreakForEach.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | /** 20 | * You can throw this inside a {@link QueryConsumer} to signal {@link Query#forEach(QueryConsumer)} should "break". 21 | * This will stop consuming any further data. 22 | */ 23 | public class BreakForEach extends RuntimeException { 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/EagerRelation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.relation.RelationInfo; 20 | 21 | class EagerRelation<S, T> { 22 | public final int limit; 23 | public final RelationInfo<S, T> relationInfo; 24 | 25 | EagerRelation(int limit, RelationInfo<S, T> relationInfo) { 26 | this.limit = limit; 27 | this.relationInfo = relationInfo; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/IdWithScore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | /** 20 | * Wraps the ID of a matching object and a score when using {@link Query#findIdsWithScores}. 21 | */ 22 | public class IdWithScore { 23 | 24 | private final long id; 25 | private final double score; 26 | 27 | // Note: this constructor is called by JNI, check before modifying/removing it. 28 | public IdWithScore(long id, double score) { 29 | this.id = id; 30 | this.score = score; 31 | } 32 | 33 | /** 34 | * Returns the object ID. 35 | */ 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | /** 41 | * Returns the query score for the {@link #getId() id}. 42 | * <p> 43 | * The query score indicates some quality measurement. E.g. for vector nearest neighbor searches, the score is the 44 | * distance to the given vector. 45 | */ 46 | public double getScore() { 47 | return score; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/InternalAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | 21 | /** 22 | * Exposes internal APIs to tests and code in other packages. 23 | */ 24 | @Internal 25 | public class InternalAccess { 26 | 27 | @Internal 28 | public static <T> void nativeFindFirst(Query<T> query, long cursorHandle) { 29 | query.nativeFindFirst(query.handle, cursorHandle); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/ObjectWithScore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | /** 20 | * Wraps a matching object and a score when using {@link Query#findWithScores}. 21 | */ 22 | public class ObjectWithScore<T> { 23 | 24 | private final T object; 25 | private final double score; 26 | 27 | // Note: this constructor is called by JNI, check before modifying/removing it. 28 | public ObjectWithScore(T object, double score) { 29 | this.object = object; 30 | this.score = score; 31 | } 32 | 33 | // Do not use getObject() to avoid having to escape the name in Kotlin 34 | /** 35 | * Returns the matching object. 36 | */ 37 | public T get() { 38 | return object; 39 | } 40 | 41 | /** 42 | * Returns the query score for the {@link #get() object}. 43 | * <p> 44 | * The query score indicates some quality measurement. E.g. for vector nearest neighbor searches, the score is the 45 | * distance to the given vector. 46 | */ 47 | public double getScore() { 48 | return score; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/OrderFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.query; 20 | 21 | /** 22 | * Not really an enum, but binary flags to use across languages 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class OrderFlags { 26 | private OrderFlags() { } 27 | /** 28 | * Reverts the order from ascending (default) to descending. 29 | */ 30 | public static final int DESCENDING = 1; 31 | /** 32 | * Makes upper case letters (e.g. "Z") be sorted before lower case letters (e.g. "a"). 33 | * If not specified, the default is case insensitive for ASCII characters. 34 | */ 35 | public static final int CASE_SENSITIVE = 2; 36 | /** 37 | * For scalars only: changes the comparison to unsigned (default is signed). 38 | */ 39 | public static final int UNSIGNED = 4; 40 | /** 41 | * null values will be put last. 42 | * If not specified, by default null values will be put first. 43 | */ 44 | public static final int NULLS_LAST = 8; 45 | /** 46 | * null values should be treated equal to zero (scalars only). 47 | */ 48 | public static final int NULLS_ZERO = 16; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/PropertyQueryCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.Property; 20 | 21 | /** 22 | * A condition on a {@link Property}, which can have an alias to allow referring to it later. 23 | */ 24 | public interface PropertyQueryCondition<T> extends QueryCondition<T> { 25 | 26 | /** 27 | * Assigns an alias to this condition that can later be used with the {@link Query} setParameter methods. 28 | */ 29 | QueryCondition<T> alias(String name); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/QueryCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.Property; 20 | 21 | /** 22 | * Allows building queries with a fluent interface. Use through {@link io.objectbox.Box#query(QueryCondition)} 23 | * and build a condition with {@link Property} methods. 24 | */ 25 | public interface QueryCondition<T> { 26 | 27 | /** 28 | * Combines this condition using AND with the given condition. 29 | * 30 | * @see #or(QueryCondition) 31 | */ 32 | QueryCondition<T> and(QueryCondition<T> queryCondition); 33 | 34 | /** 35 | * Combines this condition using OR with the given condition. 36 | * 37 | * @see #and(QueryCondition) 38 | */ 39 | QueryCondition<T> or(QueryCondition<T> queryCondition); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/QueryConditionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.query.LogicQueryCondition.AndCondition; 20 | import io.objectbox.query.LogicQueryCondition.OrCondition; 21 | 22 | /** 23 | * Hides the {@link #apply(QueryBuilder)} method from the public API ({@link QueryCondition}). 24 | */ 25 | abstract class QueryConditionImpl<T> implements QueryCondition<T> { 26 | 27 | @Override 28 | public QueryCondition<T> and(QueryCondition<T> queryCondition) { 29 | return new AndCondition<>(this, (QueryConditionImpl<T>) queryCondition); 30 | } 31 | 32 | @Override 33 | public QueryCondition<T> or(QueryCondition<T> queryCondition) { 34 | return new OrCondition<>(this, (QueryConditionImpl<T>) queryCondition); 35 | } 36 | 37 | abstract void apply(QueryBuilder<T> builder); 38 | } 39 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/QueryConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | public interface QueryConsumer<T> { 20 | void accept(T data); 21 | } 22 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/QueryFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | /** 20 | * Decides which entities to keep as a query result. 21 | * 22 | * @param <T> The entity 23 | */ 24 | public interface QueryFilter<T> { 25 | boolean keep(T entity); 26 | } 27 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/QueryThreadLocal.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.query; 2 | 3 | /** 4 | * A {@link ThreadLocal} that, given an original {@link Query} object, 5 | * returns a {@link Query#copy() copy}, for each thread. 6 | */ 7 | public class QueryThreadLocal<T> extends ThreadLocal<Query<T>> { 8 | 9 | private final Query<T> original; 10 | 11 | /** 12 | * See {@link QueryThreadLocal}. 13 | */ 14 | public QueryThreadLocal(Query<T> original) { 15 | this.original = original; 16 | } 17 | 18 | @Override 19 | protected Query<T> initialValue() { 20 | return original.copy(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/RelationCountCondition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import io.objectbox.relation.RelationInfo; 20 | 21 | public class RelationCountCondition<T> extends QueryConditionImpl<T> { 22 | 23 | private final RelationInfo<T, ?> relationInfo; 24 | private final int relationCount; 25 | 26 | 27 | public RelationCountCondition(RelationInfo<T, ?> relationInfo, int relationCount) { 28 | this.relationInfo = relationInfo; 29 | this.relationCount = relationCount; 30 | } 31 | 32 | @Override 33 | void apply(QueryBuilder<T> builder) { 34 | builder.relationCount(relationInfo, relationCount); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/query/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Classes related to {@link io.objectbox.query.QueryBuilder building} 19 | * a {@link io.objectbox.query.Query} or {@link io.objectbox.query.PropertyQuery}. 20 | * <p> 21 | * For more details look at the documentation of individual classes and 22 | * <a href="https://docs.objectbox.io/queries">docs.objectbox.io/queries</a>. 23 | */ 24 | @ParametersAreNonnullByDefault 25 | package io.objectbox.query; 26 | 27 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DataObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | /** 20 | * Observer that can be subscribed to publishers (e.g. @{@link io.objectbox.BoxStore} and 21 | * {@link io.objectbox.query.Query}). 22 | * 23 | * @param <T> type of data that is observed 24 | * {@link io.objectbox.query.Query}) to receive data changes. 25 | */ 26 | public interface DataObserver<T> { 27 | /** 28 | * Called when data changed. 29 | * <p> 30 | * Exception note: if this method throws an exception, it can be reacted on via 31 | * {@link SubscriptionBuilder#onError(ErrorObserver)}. 32 | */ 33 | void onData(T data); 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DataPublisher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | import io.objectbox.annotation.apihint.Internal; 22 | 23 | @Internal 24 | public interface DataPublisher<T> { 25 | void subscribe(DataObserver<T> observer, @Nullable Object param); 26 | 27 | void publishSingle(DataObserver<T> observer, @Nullable Object param); 28 | 29 | void unsubscribe(DataObserver<T> observer, @Nullable Object param); 30 | } 31 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DataSubscription.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | /** 20 | * The result of subscribing an @{@link DataObserver} using @{@link SubscriptionBuilder#observer(DataObserver)}. 21 | * Used to cancel the subscription (unsubscribe). 22 | */ 23 | public interface DataSubscription { 24 | /** The Observer shall not receive anymore updates. */ 25 | void cancel(); 26 | 27 | /** Current cancellation state of the subscription. */ 28 | boolean isCanceled(); 29 | } 30 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DataSubscriptionImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | import javax.annotation.Nullable; 20 | 21 | class DataSubscriptionImpl<T> implements DataSubscription { 22 | private volatile boolean canceled; 23 | private DataPublisher<T> publisher; 24 | private Object publisherParam; 25 | private DataObserver<T> observer; 26 | 27 | DataSubscriptionImpl(DataPublisher<T> publisher, @Nullable Object publisherParam, DataObserver<T> observer) { 28 | this.publisher = publisher; 29 | this.publisherParam = publisherParam; 30 | this.observer = observer; 31 | } 32 | 33 | @Override 34 | public synchronized void cancel() { 35 | canceled = true; 36 | if (publisher != null) { 37 | publisher.unsubscribe(observer, publisherParam); 38 | 39 | // Clear out all references, so apps can hold on to subscription object without leaking 40 | publisher = null; 41 | observer = null; 42 | publisherParam = null; 43 | } 44 | } 45 | 46 | public boolean isCanceled() { 47 | return canceled; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DataTransformer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | /** 20 | * Transforms or processes data before it is given to subscribed {@link DataObserver}s. A transformer is set via 21 | * {@link SubscriptionBuilder#transform(DataTransformer)}. 22 | * <p> 23 | * Note that a transformer is not required to actually "transform" any data. 24 | * Technically, it's fine to return the same data it received and just do some processing with it. 25 | * <p> 26 | * Threading notes: transformations are executed sequentially on a background thread 27 | * owned by the subscription publisher. It is OK to perform long lasting operations, 28 | * however this will block notifications to all other observers until finished. 29 | * 30 | * @param <FROM> Data type this transformer receives 31 | * @param <TO> Type of transformed data 32 | */ 33 | public interface DataTransformer<FROM, TO> { 34 | /** 35 | * Transforms/processes the given data. 36 | * 37 | * @param source data to be transformed 38 | * @return transformed data 39 | * @throws Exception Transformers may throw any exceptions, which can be reacted on via 40 | * {@link SubscriptionBuilder#onError(ErrorObserver)}. 41 | */ 42 | TO transform(FROM source) throws Exception; 43 | } 44 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/DelegatingObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | 21 | @Internal 22 | public interface DelegatingObserver<T> { 23 | DataObserver<T> getObserverDelegate(); 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/ErrorObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | /** 20 | * Exceptions thrown in {@link DataObserver} and @{@link DataTransformer} can be observed by an error observer set via 21 | * {@link SubscriptionBuilder#onError(ErrorObserver)}. 22 | */ 23 | public interface ErrorObserver { 24 | /** Called when an exception was thrown. */ 25 | void onError(Throwable th); 26 | } 27 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/RunWithParam.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | 21 | @Internal 22 | public interface RunWithParam<T> { 23 | void run(T param); 24 | } 25 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/Scheduler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | public interface Scheduler { 20 | <T> void run(RunWithParam<T> runnable, T param); 21 | } 22 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/Schedulers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.reactive; 18 | 19 | // How to get to BoxStore thread pool? 20 | class Schedulers { 21 | static Scheduler async() { 22 | return null; 23 | } 24 | 25 | static Scheduler singleThreadSequential() { 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/reactive/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Classes to {@link io.objectbox.reactive.SubscriptionBuilder configure} 19 | * a {@link io.objectbox.reactive.DataSubscription} for observing Box or Query changes. 20 | * <p> 21 | * For more details look at the documentation of individual classes and 22 | * <a href="https://docs.objectbox.io/data-observers-and-rx">docs.objectbox.io/data-observers-and-rx</a>. 23 | */ 24 | @ParametersAreNonnullByDefault 25 | package io.objectbox.reactive; 26 | 27 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/relation/ListFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.relation; 18 | 19 | import java.io.Serializable; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.concurrent.CopyOnWriteArrayList; 23 | 24 | import io.objectbox.annotation.apihint.Experimental; 25 | 26 | @Experimental 27 | public interface ListFactory extends Serializable { 28 | <T> List<T> createList(); 29 | 30 | class ArrayListFactory implements ListFactory { 31 | private static final long serialVersionUID = 8247662514375611729L; 32 | 33 | @Override 34 | public <T> List<T> createList() { 35 | return new ArrayList<>(); 36 | } 37 | } 38 | 39 | class CopyOnWriteArrayListFactory implements ListFactory { 40 | private static final long serialVersionUID = 1888039726372206411L; 41 | 42 | @Override 43 | public <T> List<T> createList() { 44 | return new CopyOnWriteArrayList<>(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/relation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Classes to manage {@link io.objectbox.relation.ToOne} and {@link io.objectbox.relation.ToMany} 19 | * relations between Entities. 20 | * <p> 21 | * For more details look at the documentation of individual classes and 22 | * <a href="https://docs.objectbox.io/relations">docs.objectbox.io/relations</a>. 23 | */ 24 | @ParametersAreNonnullByDefault 25 | package io.objectbox.relation; 26 | 27 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/ObjectsMessageBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync; 18 | 19 | /** 20 | * @see SyncClient#startObjectsMessage 21 | */ 22 | public interface ObjectsMessageBuilder { 23 | 24 | ObjectsMessageBuilder addString(long optionalId, String value); 25 | 26 | ObjectsMessageBuilder addBytes(long optionalId, byte[] value, boolean isFlatBuffers); 27 | 28 | /** 29 | * Sends the message, returns true if successful. 30 | */ 31 | boolean send(); 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/SyncCredentialsUserPassword.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | 21 | /** 22 | * Internal credentials implementation for user and password authentication. 23 | * Use {@link SyncCredentials} to build credentials. 24 | */ 25 | @Internal 26 | public final class SyncCredentialsUserPassword extends SyncCredentials { 27 | 28 | private final String username; 29 | private final String password; 30 | 31 | SyncCredentialsUserPassword(CredentialsType type, String username, String password) { 32 | super(type); 33 | this.username = username; 34 | this.password = password; 35 | } 36 | 37 | public String getUsername() { 38 | return username; 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | @Override 46 | SyncCredentials createClone() { 47 | return new SyncCredentialsUserPassword(getType(), this.username, this.password); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/SyncFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.sync; 20 | 21 | /** 22 | * Flags to adjust sync behavior like additional logging. 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class SyncFlags { 26 | private SyncFlags() { } 27 | /** 28 | * Enable (rather extensive) logging on how IDs are mapped (local <-> global) 29 | */ 30 | public static final int DebugLogIdMapping = 1; 31 | /** 32 | * If the client gets in a state that does not allow any further synchronization, this flag instructs Sync to 33 | * keep local data nevertheless. While this preserves data, you need to resolve the situation manually. 34 | * For example, you could backup the data and start with a fresh database. 35 | * Note that the default behavior (this flag is not set) is to wipe existing data from all sync-enabled types and 36 | * sync from scratch from the server. 37 | * Client-only: setting this flag for Sync server has no effect. 38 | */ 39 | public static final int ClientKeepDataOnSyncError = 2; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/SyncLoginCodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync; 18 | 19 | import io.objectbox.annotation.apihint.Experimental; 20 | import io.objectbox.sync.listener.SyncListener; 21 | 22 | /** 23 | * Codes used by {@link SyncListener#onLoginFailed(long)}. 24 | */ 25 | @Experimental 26 | public class SyncLoginCodes { 27 | 28 | public static final long OK = 20; 29 | public static final long REQ_REJECTED = 40; 30 | public static final long CREDENTIALS_REJECTED = 43; 31 | public static final long UNKNOWN = 50; 32 | public static final long AUTH_UNREACHABLE = 53; 33 | public static final long BAD_VERSION = 55; 34 | public static final long CLIENT_ID_TAKEN = 61; 35 | public static final long TX_VIOLATED_UNIQUE = 71; 36 | 37 | private SyncLoginCodes() { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/SyncState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync; 18 | 19 | /** 20 | * Returned by {@link io.objectbox.sync.SyncClientImpl#getSyncState()}. 21 | */ 22 | public enum SyncState { 23 | 24 | UNKNOWN(0), 25 | CREATED(1), 26 | STARTED(2), 27 | CONNECTED(3), 28 | LOGGED_IN(4), 29 | DISCONNECTED(5), 30 | STOPPED(6), 31 | DEAD(7); 32 | 33 | public final int id; 34 | 35 | SyncState(int id) { 36 | this.id = id; 37 | } 38 | 39 | public static SyncState fromId(int id) { 40 | for (SyncState value : values()) { 41 | if (value.id == id) return value; 42 | } 43 | return UNKNOWN; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/AbstractSyncListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | import io.objectbox.annotation.apihint.Experimental; 20 | import io.objectbox.sync.SyncChange; 21 | 22 | /** 23 | * A {@link SyncListener} with empty implementations of all interface methods. 24 | * This is helpful if you only want to override some methods. 25 | */ 26 | @Experimental 27 | public abstract class AbstractSyncListener implements SyncListener { 28 | 29 | @Override 30 | public void onLoggedIn() { 31 | } 32 | 33 | @Override 34 | public void onLoginFailed(long syncLoginCode) { 35 | } 36 | 37 | @Override 38 | public void onUpdatesCompleted() { 39 | } 40 | 41 | @Override 42 | public void onSyncChanges(SyncChange[] syncChanges) { 43 | } 44 | 45 | @Override 46 | public void onServerTimeUpdate(long serverTimeNanos) { 47 | } 48 | 49 | @Override 50 | public void onDisconnected() { 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | import io.objectbox.annotation.apihint.Experimental; 20 | import io.objectbox.sync.SyncChange; 21 | 22 | /** 23 | * Notifies of fine granular changes on the object level happening during sync. 24 | * Register your listener using {@link io.objectbox.sync.SyncBuilder#changeListener(SyncChangeListener) SyncBuilder.changesListener(SyncChangesListener)}. 25 | * Note that enabling fine granular notification can slightly reduce performance. 26 | * <p> 27 | * See also {@link SyncListener} for the general sync listener. 28 | */ 29 | @SuppressWarnings({"unused"}) 30 | @Experimental 31 | public interface SyncChangeListener { 32 | 33 | // Note: this method is expected by JNI, check before modifying/removing it. 34 | 35 | /** 36 | * Called each time when data from sync was applied locally. 37 | * 38 | * @param syncChanges This contains the entity type (schema) ID, the removed IDs and the put IDs for that entity. 39 | */ 40 | void onSyncChanges(SyncChange[] syncChanges); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncCompletedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | /** 20 | * Listens to sync completed events. 21 | */ 22 | public interface SyncCompletedListener { 23 | 24 | /** 25 | * Called each time a sync was "completed", in the sense that the client caught up with the current server state. 26 | * The client is "up-to-date". 27 | */ 28 | void onUpdatesCompleted(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncConnectionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | /** 20 | * Listens to sync connection events. 21 | */ 22 | public interface SyncConnectionListener { 23 | 24 | /** 25 | * Called when the client is disconnected from the sync server, e.g. due to a network error. 26 | * <p> 27 | * Depending on the configuration, the sync client typically tries to reconnect automatically, 28 | * triggering a {@link SyncLoginListener} again. 29 | */ 30 | void onDisconnected(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | import io.objectbox.annotation.apihint.Experimental; 20 | import io.objectbox.sync.SyncBuilder; 21 | import io.objectbox.sync.SyncClient; 22 | 23 | /** 24 | * This listener has callback methods invoked by all fundamental synchronization events. 25 | * Set via {@link SyncBuilder#listener(SyncListener)} or {@link SyncClient#setSyncListener(SyncListener)}. 26 | * <p> 27 | * See {@link AbstractSyncListener} for a no-op convenience implementation. 28 | * <p> 29 | * Use more specific listeners, like {@link SyncLoginListener}, to only receive a sub-set of events. 30 | */ 31 | @Experimental 32 | public interface SyncListener extends SyncLoginListener, SyncCompletedListener, SyncChangeListener, SyncConnectionListener, SyncTimeListener { 33 | } 34 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncLoginListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | import io.objectbox.sync.SyncLoginCodes; 20 | 21 | /** 22 | * Listens to login events. 23 | */ 24 | public interface SyncLoginListener { 25 | 26 | /** 27 | * Called on a successful login. 28 | * <p> 29 | * At this point the connection to the sync destination was established and 30 | * entered an operational state, in which data can be sent both ways. 31 | */ 32 | void onLoggedIn(); 33 | 34 | /** 35 | * Called on a login failure. One of {@link SyncLoginCodes}, but never {@link SyncLoginCodes#OK}. 36 | */ 37 | void onLoginFailed(long syncLoginCode); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/listener/SyncTimeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.listener; 18 | 19 | public interface SyncTimeListener { 20 | 21 | /** 22 | * Called when server time information is received on the client. 23 | */ 24 | void onServerTimeUpdate(long serverTimeNanos); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/server/ClusterFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.sync.server; 20 | 21 | /** 22 | * Special bit flags used in cluster mode only. 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class ClusterFlags { 26 | private ClusterFlags() { } 27 | /** 28 | * Indicates that this cluster always stays in the "follower" cluster role. 29 | * Thus, it does not participate in leader elections. 30 | * This is useful e.g. for weaker cluster nodes that should not become leaders. 31 | */ 32 | public static final int FixedFollower = 1; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/server/ClusterPeerInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.sync.server; 18 | 19 | import io.objectbox.annotation.apihint.Internal; 20 | import io.objectbox.sync.SyncCredentialsToken; 21 | 22 | /** 23 | * Internal class to keep configuration for a cluster peer. 24 | */ 25 | @Internal 26 | final class ClusterPeerInfo { 27 | String url; 28 | SyncCredentialsToken credentials; 29 | 30 | ClusterPeerInfo(String url, SyncCredentialsToken credentials) { 31 | this.url = url; 32 | this.credentials = credentials; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/sync/server/SyncServerFlags.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // automatically generated by the FlatBuffers compiler, do not modify 18 | 19 | package io.objectbox.sync.server; 20 | 21 | /** 22 | * Bit flags to configure the Sync Server. 23 | */ 24 | @SuppressWarnings("unused") 25 | public final class SyncServerFlags { 26 | private SyncServerFlags() { } 27 | /** 28 | * By default, if the Sync Server allows logins without credentials, it logs a warning message. 29 | * If this flag is set, the message is logged only as "info". 30 | */ 31 | public static final int AuthenticationNoneLogInfo = 1; 32 | /** 33 | * By default, the Admin server is enabled; this flag disables it. 34 | */ 35 | public static final int AdminDisabled = 2; 36 | /** 37 | * By default, the Sync Server logs messages when it starts and stops; this flag disables it. 38 | */ 39 | public static final int LogStartStopDisabled = 4; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /objectbox-java/src/main/java/io/objectbox/tree/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * APIs to interact with tree structures stored in ObjectBox. 19 | */ 20 | @ParametersAreNonnullByDefault 21 | package io.objectbox.tree; 22 | 23 | import javax.annotation.ParametersAreNonnullByDefault; -------------------------------------------------------------------------------- /objectbox-java/src/main/resources/META-INF/proguard/objectbox-java.pro: -------------------------------------------------------------------------------- 1 | # When editing this file, also look at consumer-proguard-rules.pro of objectbox-android. 2 | 3 | -keepattributes *Annotation* 4 | 5 | # Native methods 6 | -keepclasseswithmembernames class io.objectbox.** { 7 | native <methods>; 8 | } 9 | 10 | # For __boxStore field in entities 11 | -keep class io.objectbox.BoxStore 12 | 13 | -keep class * extends io.objectbox.Cursor { 14 | <init>(...); 15 | } 16 | 17 | # Native code expects names to match 18 | -keep class io.objectbox.relation.ToOne { 19 | void setTargetId(long); 20 | } 21 | -keep class io.objectbox.relation.ToMany 22 | -keep class io.objectbox.tree.LeafNode 23 | 24 | -keep @interface io.objectbox.annotation.Entity 25 | 26 | # Keep entity constructors 27 | -keep @io.objectbox.annotation.Entity class * { <init>(...); } 28 | 29 | # For relation ID fields 30 | -keepclassmembers @io.objectbox.annotation.Entity class * { 31 | <fields>; 32 | } 33 | 34 | -keep interface io.objectbox.converter.PropertyConverter {*;} 35 | -keep class * implements io.objectbox.converter.PropertyConverter {*;} 36 | 37 | -keep class io.objectbox.exception.DbException {*;} 38 | -keep class * extends io.objectbox.exception.DbException {*;} 39 | 40 | -keep class io.objectbox.exception.DbExceptionListener {*;} 41 | -keep class * implements io.objectbox.exception.DbExceptionListener {*;} 42 | 43 | # for essentials 44 | -dontwarn sun.misc.Unsafe 45 | # SpotBugs annotations 46 | -dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings 47 | -------------------------------------------------------------------------------- /objectbox-java/src/web/overview.html: -------------------------------------------------------------------------------- 1 | <HTML> 2 | <BODY> 3 | <p> 4 | Welcome to the JavaDocs for <a href="https://objectbox.io">ObjectBox</a>, the super-fast database for objects. 5 | On these pages, you will find the API reference for the ObjectBox Java library. 6 | </p> 7 | <p> 8 | The <b>main documentation</b> is available at <a href="https://docs.objectbox.io">docs.objectbox.io</a> and offers 9 | a changelog, a <a href="https://docs.objectbox.io/getting-started">getting started guide</a>, and many more topics. 10 | </p> 11 | <p> 12 | GitHub links: <a href="https://github.com/objectbox/objectbox-java">ObjectBox Java</a>, 13 | <a href="https://github.com/objectbox/objectbox-examples">Examples for Java, Kotlin and Android</a> 14 | </p> 15 | 16 | </BODY> 17 | </HTML> -------------------------------------------------------------------------------- /objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Box.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.kotlin 18 | 19 | import io.objectbox.Box 20 | import io.objectbox.query.Query 21 | import io.objectbox.query.QueryBuilder 22 | 23 | 24 | /** 25 | * Note: new code should use the [Box.query] functions directly, including the new query API. 26 | * 27 | * Allows building a query for this Box instance with a call to [build][QueryBuilder.build] to return a [Query] instance. 28 | * 29 | * ``` 30 | * val query = box.query { 31 | * equal(Entity_.property, value) 32 | * } 33 | * ``` 34 | */ 35 | @Deprecated("New code should use query(queryCondition).build() instead.") 36 | inline fun <T> Box<T>.query(block: QueryBuilder<T>.() -> Unit): Query<T> { 37 | val builder = query() 38 | block(builder) 39 | return builder.build() 40 | } 41 | -------------------------------------------------------------------------------- /objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Flow.kt: -------------------------------------------------------------------------------- 1 | package io.objectbox.kotlin 2 | 3 | import io.objectbox.BoxStore 4 | import io.objectbox.query.Query 5 | import io.objectbox.reactive.SubscriptionBuilder 6 | import kotlinx.coroutines.ExperimentalCoroutinesApi 7 | import kotlinx.coroutines.channels.awaitClose 8 | import kotlinx.coroutines.channels.trySendBlocking 9 | import kotlinx.coroutines.flow.Flow 10 | import kotlinx.coroutines.flow.callbackFlow 11 | 12 | 13 | /** 14 | * Like [SubscriptionBuilder.observer], but emits data changes to the returned flow. 15 | * Automatically cancels the subscription when the flow is canceled. 16 | * 17 | * For example to create a flow to listen to all changes to a box: 18 | * ``` 19 | * store.subscribe(TestEntity::class.java).toFlow() 20 | * ``` 21 | * 22 | * Or to get the latest query results on any changes to a box: 23 | * ``` 24 | * box.query().subscribe().toFlow() 25 | * ``` 26 | */ 27 | @ExperimentalCoroutinesApi 28 | fun <T> SubscriptionBuilder<T>.toFlow(): Flow<T> = callbackFlow { 29 | val subscription = this@toFlow.observer { 30 | trySendBlocking(it) 31 | } 32 | awaitClose { subscription.cancel() } 33 | } 34 | 35 | /** 36 | * Shortcut for `BoxStore.subscribe(forClass).toFlow()`, see [BoxStore.subscribe] and [toFlow] for details. 37 | */ 38 | @ExperimentalCoroutinesApi 39 | fun <T> BoxStore.flow(forClass: Class<T>): Flow<Class<T>> = this.subscribe(forClass).toFlow() 40 | 41 | /** 42 | * Shortcut for `query.subscribe().toFlow()`, see [Query.subscribe] and [toFlow] for details. 43 | */ 44 | @ExperimentalCoroutinesApi 45 | fun <T> Query<T>.flow(): Flow<MutableList<T>> = this@flow.subscribe().toFlow() -------------------------------------------------------------------------------- /objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/PropertyQueryCondition.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.kotlin 18 | 19 | import io.objectbox.query.PropertyQueryCondition 20 | import io.objectbox.query.QueryCondition 21 | 22 | 23 | /** 24 | * Assigns an alias to this condition that can later be used with the [io.objectbox.query.Query] setParameter methods. 25 | */ 26 | infix fun <T> PropertyQueryCondition<T>.alias(name: String): QueryCondition<T> { 27 | return alias(name) 28 | } -------------------------------------------------------------------------------- /objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/QueryCondition.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.kotlin 18 | 19 | import io.objectbox.query.QueryCondition 20 | 21 | 22 | /** 23 | * Combines the left hand side condition using AND with the right hand side condition. 24 | * 25 | * @see or 26 | */ 27 | infix fun <T> QueryCondition<T>.and(queryCondition: QueryCondition<T>): QueryCondition<T> { 28 | return and(queryCondition) 29 | } 30 | 31 | /** 32 | * Combines the left hand side condition using OR with the right hand side condition. 33 | * 34 | * @see and 35 | */ 36 | infix fun <T> QueryCondition<T>.or(queryCondition: QueryCondition<T>): QueryCondition<T> { 37 | return or(queryCondition) 38 | } -------------------------------------------------------------------------------- /objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/ToMany.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.kotlin 18 | 19 | import io.objectbox.relation.ToMany 20 | 21 | /** 22 | * Allows making changes (adding and removing entities) to this ToMany with a call to 23 | * [apply][ToMany.applyChangesToDb] the changes to the database. 24 | * Can [reset][ToMany.reset] the ToMany before making changes. 25 | * ``` 26 | * toMany.applyChangesToDb { 27 | * add(entity) 28 | * } 29 | * ``` 30 | */ 31 | @Suppress("unused") // Tested in integration tests 32 | inline fun <T> ToMany<T>.applyChangesToDb(resetFirst: Boolean = false, body: ToMany<T>.() -> Unit) { 33 | if (resetFirst) reset() 34 | body() 35 | applyChangesToDb() 36 | } 37 | -------------------------------------------------------------------------------- /objectbox-rxjava/README.md: -------------------------------------------------------------------------------- 1 | :information_source: This library will receive no new features. 2 | Development will continue with the [RxJava 3 APIs for ObjectBox](/objectbox-rxjava3). 3 | 4 | RxJava 2 APIs for ObjectBox 5 | =========================== 6 | While ObjectBox has [data observers and reactive extensions](https://docs.objectbox.io/data-observers-and-rx) built-in, 7 | this project adds RxJava 2 support. 8 | 9 | For general object changes, you can use `RxBoxStore` to create an `Observable`. 10 | 11 | `RxQuery` allows you to interact with ObjectBox `Query` objects using: 12 | * Flowable 13 | * Observable 14 | * Single 15 | 16 | For example to get query results and subscribe to future updates (Object changes will automatically emmit new data): 17 | 18 | ```java 19 | Query<User> query = box.query().build(); 20 | RxQuery.observable(query).subscribe(this); 21 | ``` 22 | 23 | Adding the library to your project 24 | ----------------- 25 | Grab via Gradle: 26 | ```gradle 27 | implementation "io.objectbox:objectbox-rxjava:$objectboxVersion" 28 | ``` 29 | 30 | Links 31 | ----- 32 | [Data Observers and Rx Documentation](https://docs.objectbox.io/data-observers-and-rx) 33 | -------------------------------------------------------------------------------- /objectbox-rxjava/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | id("objectbox-publish") 4 | } 5 | 6 | // Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used. 7 | // https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation 8 | tasks.withType(JavaCompile).configureEach { 9 | options.release.set(8) 10 | } 11 | 12 | dependencies { 13 | api project(':objectbox-java') 14 | api 'io.reactivex.rxjava2:rxjava:2.2.21' 15 | 16 | testImplementation "junit:junit:$junitVersion" 17 | testImplementation "org.mockito:mockito-core:$mockitoVersion" 18 | } 19 | 20 | tasks.register('javadocJar', Jar) { 21 | dependsOn javadoc 22 | archiveClassifier.set('javadoc') 23 | from 'build/docs/javadoc' 24 | } 25 | 26 | tasks.register('sourcesJar', Jar) { 27 | archiveClassifier.set('sources') 28 | from sourceSets.main.allSource 29 | } 30 | 31 | // Set project-specific properties. 32 | publishing.publications { 33 | mavenJava(MavenPublication) { 34 | from components.java 35 | artifact sourcesJar 36 | artifact javadocJar 37 | pom { 38 | name = 'ObjectBox RxJava API' 39 | description = 'RxJava extension for ObjectBox' 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /objectbox-rxjava/src/main/java/io/objectbox/rx/RxBoxStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.rx; 18 | 19 | import io.objectbox.BoxStore; 20 | import io.objectbox.reactive.DataSubscription; 21 | import io.reactivex.Observable; 22 | 23 | /** 24 | * Static methods to Rx-ify ObjectBox queries. 25 | */ 26 | public abstract class RxBoxStore { 27 | /** 28 | * Using the returned Observable, you can be notified about data changes. 29 | * Once a transaction is committed, you will get info on classes with changed Objects. 30 | */ 31 | public static <T> Observable<Class> observable(final BoxStore boxStore) { 32 | return Observable.create(emitter -> { 33 | final DataSubscription dataSubscription = boxStore.subscribe().observer(data -> { 34 | if (!emitter.isDisposed()) { 35 | emitter.onNext(data); 36 | } 37 | }); 38 | emitter.setCancellable(dataSubscription::cancel); 39 | }); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /objectbox-rxjava/src/test/java/io/objectbox/query/MockQuery.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.query; 18 | 19 | import static org.mockito.Mockito.mock; 20 | import static org.mockito.Mockito.when; 21 | 22 | import io.objectbox.Box; 23 | import io.objectbox.BoxStore; 24 | import io.objectbox.reactive.SubscriptionBuilder; 25 | 26 | public class MockQuery<T> { 27 | private Box box; 28 | private BoxStore boxStore; 29 | private final Query query; 30 | private final FakeQueryPublisher fakeQueryPublisher; 31 | 32 | public MockQuery(boolean hasOrder) { 33 | // box = mock(Box.class); 34 | // boxStore = mock(BoxStore.class); 35 | // when(box.getStore()).thenReturn(boxStore); 36 | query = mock(Query.class); 37 | fakeQueryPublisher = new FakeQueryPublisher(); 38 | SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder(fakeQueryPublisher, null); 39 | when(query.subscribe()).thenReturn(subscriptionBuilder); 40 | } 41 | 42 | public Box getBox() { 43 | return box; 44 | } 45 | 46 | public BoxStore getBoxStore() { 47 | return boxStore; 48 | } 49 | 50 | public Query getQuery() { 51 | return query; 52 | } 53 | 54 | public FakeQueryPublisher getFakeQueryPublisher() { 55 | return fakeQueryPublisher; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /objectbox-rxjava3/README.md: -------------------------------------------------------------------------------- 1 | RxJava 3 APIs for ObjectBox 2 | =========================== 3 | While ObjectBox has [data observers and reactive extensions](https://docs.objectbox.io/data-observers-and-rx) built-in, 4 | this project adds RxJava 3 support. 5 | 6 | For general object changes, you can use `RxBoxStore` to create an `Observable`. 7 | 8 | `RxQuery` allows you to interact with ObjectBox `Query` objects using: 9 | * Flowable 10 | * Observable 11 | * Single 12 | 13 | For example to get query results and subscribe to future updates (Object changes will automatically emmit new data): 14 | 15 | ```java 16 | Query<User> query = box.query().build(); 17 | RxQuery.observable(query).subscribe(this); 18 | ``` 19 | 20 | Adding the library to your project 21 | ----------------- 22 | Grab via Gradle: 23 | ```gradle 24 | implementation "io.objectbox:objectbox-rxjava3:$objectboxVersion" 25 | ``` 26 | 27 | Migrating from RxJava 2 28 | ----------------------- 29 | 30 | If you have previously used the ObjectBox RxJava library note the following changes: 31 | 32 | - The location of the dependency has changed to `objectbox-rxjava3` (see above). 33 | - The package name has changed to `io.objectbox.rx3` (from `io.objectbox.rx`). 34 | 35 | This should allow using both versions side-by-side while you migrate your code to RxJava 3. 36 | 37 | Links 38 | ----- 39 | [Data Observers and Rx Documentation](https://docs.objectbox.io/data-observers-and-rx) 40 | -------------------------------------------------------------------------------- /objectbox-rxjava3/src/main/java/io/objectbox/rx3/Query.kt: -------------------------------------------------------------------------------- 1 | package io.objectbox.rx3 2 | 3 | import io.objectbox.query.Query 4 | import io.reactivex.rxjava3.core.BackpressureStrategy 5 | import io.reactivex.rxjava3.core.Flowable 6 | import io.reactivex.rxjava3.core.Observable 7 | import io.reactivex.rxjava3.core.Single 8 | 9 | /** 10 | * Shortcut for [`RxQuery.flowableOneByOne(query, strategy)`][RxQuery.flowableOneByOne]. 11 | */ 12 | fun <T : Any> Query<T>.flowableOneByOne(strategy: BackpressureStrategy = BackpressureStrategy.BUFFER): Flowable<T> { 13 | return RxQuery.flowableOneByOne(this, strategy) 14 | } 15 | 16 | /** 17 | * Shortcut for [`RxQuery.observable(query)`][RxQuery.observable]. 18 | */ 19 | fun <T> Query<T>.observable(): Observable<MutableList<T>> { 20 | return RxQuery.observable(this) 21 | } 22 | 23 | /** 24 | * Shortcut for [`RxQuery.single(query)`][RxQuery.single]. 25 | */ 26 | fun <T> Query<T>.single(): Single<MutableList<T>> { 27 | return RxQuery.single(this) 28 | } 29 | -------------------------------------------------------------------------------- /objectbox-rxjava3/src/main/java/io/objectbox/rx3/RxBoxStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.rx3; 18 | 19 | import io.objectbox.BoxStore; 20 | import io.objectbox.reactive.DataSubscription; 21 | import io.reactivex.rxjava3.core.Observable; 22 | 23 | /** 24 | * Static methods to Rx-ify ObjectBox queries. 25 | */ 26 | public abstract class RxBoxStore { 27 | /** 28 | * Using the returned Observable, you can be notified about data changes. 29 | * Once a transaction is committed, you will get info on classes with changed Objects. 30 | */ 31 | @SuppressWarnings("rawtypes") // BoxStore observer may return any (entity) type. 32 | public static Observable<Class> observable(BoxStore boxStore) { 33 | return Observable.create(emitter -> { 34 | final DataSubscription dataSubscription = boxStore.subscribe().observer(data -> { 35 | if (!emitter.isDisposed()) { 36 | emitter.onNext(data); 37 | } 38 | }); 39 | emitter.setCancellable(dataSubscription::cancel); 40 | }); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /objectbox-rxjava3/src/test/java/io/objectbox/rx3/QueryKtxTest.kt: -------------------------------------------------------------------------------- 1 | package io.objectbox.rx3 2 | 3 | import io.objectbox.query.Query 4 | import org.junit.Assert.assertNotNull 5 | import org.junit.Test 6 | import org.junit.runner.RunWith 7 | import org.mockito.Mockito 8 | import org.mockito.junit.MockitoJUnitRunner 9 | 10 | @RunWith(MockitoJUnitRunner::class) 11 | class QueryKtxTest { 12 | 13 | @Test 14 | fun flowableFromQuery() { 15 | val observable = Mockito.mock(Query::class.java).flowableOneByOne() 16 | assertNotNull(observable) 17 | } 18 | 19 | @Test 20 | fun observableFromQuery() { 21 | val observable = Mockito.mock(Query::class.java).observable() 22 | assertNotNull(observable) 23 | } 24 | 25 | @Test 26 | fun singleFromQuery() { 27 | val observable = Mockito.mock(Query::class.java).single() 28 | assertNotNull(observable) 29 | } 30 | } -------------------------------------------------------------------------------- /scripts/update-flatbuffers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # Expects FlatBuffers source files in the `../flatbuffers` directory, 5 | # the Java library in `objectbox-java`, e.g. run this from the root of this repo. 6 | 7 | script_dir=$(dirname "$(readlink -f "$0")") 8 | cd "${script_dir}/.." # move to project root dir or exit on failure 9 | echo "Running in directory: $(pwd)" 10 | 11 | src="../flatbuffers/java/src/main/java/com/google/flatbuffers" 12 | dest="objectbox-java/src/main/java/io/objectbox/flatbuffers" 13 | 14 | echo "Copying flatbuffers Java sources" 15 | rm -f ${dest}/*.java 16 | cp -v ${src}/*.java ${dest}/ 17 | 18 | echo "Updating import statements of Java sources" 19 | find "${dest}" -type f -name "*.java" \ 20 | -exec echo "Processing {}" \; \ 21 | -exec sed -i "s| com.google.flatbuffers| io.objectbox.flatbuffers|g" {} \; 22 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | // Supports resolving toolchains for JVM projects 3 | // https://docs.gradle.org/8.0/userguide/toolchains.html#sub:download_repositories 4 | id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0") 5 | } 6 | 7 | include(":objectbox-java-api") 8 | include(":objectbox-java") 9 | include(":objectbox-kotlin") 10 | include(":objectbox-rxjava") 11 | include(":objectbox-rxjava3") 12 | 13 | include(":tests:objectbox-java-test") 14 | include(":tests:test-proguard") 15 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Tests for `objectbox-java` 2 | 3 | ## Naming convention for tests 4 | 5 | All new tests which will be added to the `tests/objectbox-java-test` module must have the names of their methods in the 6 | following format: `{attribute}_{queryCondition}_{expectation}` 7 | 8 | For ex. `date_lessAndGreater_works` 9 | 10 | Note: due to historic reasons (JUnit 3) existing test methods may be named differently (with the `test` prefix). 11 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/main/java/io/objectbox/TestEntityMinimal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox; 18 | 19 | public class TestEntityMinimal { 20 | 21 | private long id; 22 | private String text; 23 | 24 | public TestEntityMinimal() { 25 | } 26 | 27 | public TestEntityMinimal(long id) { 28 | this.id = id; 29 | } 30 | 31 | public TestEntityMinimal(long id, String text) { 32 | this.id = id; 33 | this.text = text; 34 | } 35 | 36 | public long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getText() { 45 | return text; 46 | } 47 | 48 | public void setText(String text) { 49 | this.text = text; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTestK.kt: -------------------------------------------------------------------------------- 1 | package io.objectbox 2 | 3 | import io.objectbox.kotlin.awaitCallInTx 4 | import io.objectbox.kotlin.boxFor 5 | import kotlinx.coroutines.ExperimentalCoroutinesApi 6 | import kotlinx.coroutines.test.runTest 7 | import org.junit.Assert.assertEquals 8 | import org.junit.Test 9 | 10 | 11 | class BoxStoreTestK : AbstractObjectBoxTest() { 12 | 13 | /** 14 | * This is mostly to test the expected syntax works without errors or warnings. 15 | */ 16 | @Test 17 | fun boxFor() { 18 | val boxJavaApi = testEntityBox 19 | val box = store.boxFor<TestEntity>() 20 | assertEquals(boxJavaApi, box) 21 | 22 | // Note the difference to Java API: TestEntity::class.java 23 | val box2 = store.boxFor(TestEntity::class) 24 | assertEquals(boxJavaApi, box2) 25 | } 26 | 27 | @ExperimentalCoroutinesApi 28 | @Test 29 | fun awaitCallInTx() { 30 | val box = store.boxFor<TestEntity>() 31 | runTest { 32 | // put 33 | val id = store.awaitCallInTx { 34 | box.put(createTestEntity("Hello", 1)) 35 | } 36 | assertEquals(1, id!!) 37 | 38 | // get 39 | val note = store.awaitCallInTx { 40 | box.get(id) 41 | } 42 | assertEquals("Hello", note!!.simpleString) 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/FlowTest.kt: -------------------------------------------------------------------------------- 1 | package io.objectbox 2 | 3 | import app.cash.turbine.test 4 | import io.objectbox.kotlin.flow 5 | import io.objectbox.kotlin.query 6 | import kotlinx.coroutines.ExperimentalCoroutinesApi 7 | import kotlinx.coroutines.runBlocking 8 | import org.junit.Assert.assertEquals 9 | import org.junit.Test 10 | import kotlin.time.ExperimentalTime 11 | 12 | 13 | class FlowTest : AbstractObjectBoxTest() { 14 | 15 | @ExperimentalTime 16 | @ExperimentalCoroutinesApi 17 | @Test 18 | fun flow_box() { 19 | runBlocking { 20 | store.flow(TestEntity::class.java).test { 21 | assertEquals(TestEntity::class.java, expectItem()) 22 | putTestEntities(1) 23 | // Note: expectItem suspends until event, so no need to wait on OBX publisher thread. 24 | assertEquals(TestEntity::class.java, expectItem()) 25 | cancel() // expect no more events 26 | } 27 | } 28 | } 29 | 30 | @ExperimentalTime 31 | @ExperimentalCoroutinesApi 32 | @Test 33 | fun flow_query() { 34 | runBlocking { 35 | testEntityBox.query {}.flow().test { 36 | assertEquals(0, expectItem().size) 37 | putTestEntities(1) 38 | // Note: expectItem suspends until event, so no need to wait on OBX publisher thread. 39 | assertEquals(1, expectItem().size) 40 | cancel() // expect no more events 41 | } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/JniBasicsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox; 18 | 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import io.objectbox.internal.JniTest; 23 | 24 | 25 | import static org.junit.Assert.assertNotNull; 26 | import static org.junit.Assert.assertTrue; 27 | 28 | public class JniBasicsTest { 29 | @Before 30 | public void loadLib() { 31 | BoxStore.getVersionNative(); 32 | } 33 | 34 | @Test 35 | public void testReturnIntArray() { 36 | // Lower Android versions have a ReferenceTable with 1024 entries only 37 | for (int i = 0; i < 2000; i++) { 38 | int[] ints = JniTest.returnIntArray(); 39 | assertNotNull(ints); 40 | } 41 | } 42 | 43 | @Test 44 | public void testCreateAndDeleteIntArray() { 45 | // Lower Android versions have a ReferenceTable with 1024 entries only 46 | for (int i = 0; i < 2000; i++) { 47 | assertTrue("Failed at iteration " + i, JniTest.createAndDeleteIntArray()); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/Utf8HashIndexTest.java: -------------------------------------------------------------------------------- 1 | package io.objectbox; 2 | 3 | import io.objectbox.annotation.IndexType; 4 | 5 | /** 6 | * Same as {@link Utf8Test}, but with index on simpleString. 7 | */ 8 | public class Utf8HashIndexTest extends Utf8Test { 9 | 10 | @Override 11 | protected BoxStore createBoxStore() { 12 | return createBoxStore(IndexType.HASH); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/Utf8ValueIndexTest.java: -------------------------------------------------------------------------------- 1 | package io.objectbox; 2 | 3 | import io.objectbox.annotation.IndexType; 4 | 5 | /** 6 | * Same as {@link Utf8Test}, but with index on simpleString. 7 | */ 8 | public class Utf8ValueIndexTest extends Utf8Test { 9 | 10 | @Override 11 | protected BoxStore createBoxStore() { 12 | return createBoxStore(IndexType.VALUE); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/converter/StringMapConverterTest.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.converter; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import javax.annotation.Nullable; 9 | 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | public class StringMapConverterTest { 14 | 15 | @Test 16 | public void works() { 17 | convertAndBackThenAssert(null); 18 | 19 | convertAndBackThenAssert(new HashMap<>()); 20 | 21 | Map<String, String> mapWithValues = new HashMap<>(); 22 | mapWithValues.put("Hello", "Grüezi"); 23 | mapWithValues.put("💡", "Idea"); 24 | mapWithValues.put("", "Empty String Key"); 25 | convertAndBackThenAssert(mapWithValues); 26 | } 27 | 28 | private void convertAndBackThenAssert(@Nullable Map<String, String> expected) { 29 | StringMapConverter converter = new StringMapConverter(); 30 | byte[] converted = converter.convertToDatabaseValue(expected); 31 | 32 | Map<String, String> actual = converter.convertToEntityProperty(converted); 33 | assertEquals(expected, actual); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryRelationCountTest.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.query; 2 | 3 | import io.objectbox.relation.AbstractRelationTest; 4 | import io.objectbox.relation.Customer; 5 | import io.objectbox.relation.Customer_; 6 | import org.junit.Test; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class QueryRelationCountTest extends AbstractRelationTest { 13 | 14 | @Test 15 | public void queryRelationCount() { 16 | // Customer without orders. 17 | putCustomer(); 18 | // Customer with 2 orders. 19 | Customer customerWithOrders = putCustomer(); 20 | putOrder(customerWithOrders, "First order"); 21 | putOrder(customerWithOrders, "Second order"); 22 | 23 | // Find customer with no orders. 24 | try (Query<Customer> query = customerBox 25 | .query(Customer_.orders.relationCount(0)) 26 | .build()) { 27 | List<Customer> customer = query.find(); 28 | assertEquals(1, customer.size()); 29 | assertEquals(0, customer.get(0).getOrders().size()); 30 | } 31 | 32 | // Find customer with two orders. 33 | try (Query<Customer> query = customerBox 34 | .query(Customer_.orders.relationCount(2)) 35 | .build()) { 36 | List<Customer> customer = query.find(); 37 | assertEquals(1, customer.size()); 38 | assertEquals(2, customer.get(0).getOrders().size()); 39 | } 40 | 41 | // Find no customer with three orders. 42 | try (Query<Customer> query = customerBox 43 | .query(Customer_.orders.relationCount(3)) 44 | .build()) { 45 | List<Customer> customer = query.find(); 46 | assertEquals(0, customer.size()); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/relation/ExternalTypeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.relation; 18 | 19 | 20 | import org.junit.Test; 21 | 22 | 23 | import static org.junit.Assert.assertEquals; 24 | 25 | public class ExternalTypeTest extends AbstractRelationTest { 26 | 27 | /** 28 | * There is no way to test external type mapping works here. Instead, verify passing a model with 29 | * {@link io.objectbox.ModelBuilder.RelationBuilder#externalType(int)} works (see {@link MyObjectBox}) and that 30 | * there are no side effects for put and get. 31 | */ 32 | @Test 33 | public void standaloneToMany_externalType_putGetSmokeTest() { 34 | Customer putCustomer = new Customer(); 35 | putCustomer.setName("Joe"); 36 | Order order = new Order(); 37 | order.setText("Order from Joe"); 38 | putCustomer.getToManyExternalId().add(order); 39 | long customerId = customerBox.put(putCustomer); 40 | 41 | Customer readCustomer = customerBox.get(customerId); 42 | assertEquals(order.getText(), readCustomer.getToManyExternalId().get(0).getText()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/sync/PlatformTest.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.sync; 2 | 3 | import org.junit.Test; 4 | 5 | import io.objectbox.sync.internal.Platform; 6 | 7 | 8 | import static org.junit.Assert.assertNotNull; 9 | 10 | public class PlatformTest { 11 | 12 | @Test 13 | public void buildsAndNeverNull() { 14 | assertNotNull(Platform.findPlatform()); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/tree/DataBranch.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.tree; 2 | 3 | import io.objectbox.annotation.ConflictStrategy; 4 | import io.objectbox.annotation.Entity; 5 | import io.objectbox.annotation.Id; 6 | import io.objectbox.annotation.Unique; 7 | import io.objectbox.relation.ToOne; 8 | 9 | @Entity 10 | public final class DataBranch { 11 | @Id 12 | long id; 13 | 14 | @Unique(onConflict = ConflictStrategy.REPLACE) 15 | String uid; 16 | 17 | public ToOne<DataBranch> parent; 18 | public ToOne<MetaBranch> metaBranch; 19 | 20 | public String toString() { 21 | return "DataBranch(id=" + this.id + ", uid=" + this.uid + ')'; 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/java/io/objectbox/tree/MetaBranch.java: -------------------------------------------------------------------------------- 1 | package io.objectbox.tree; 2 | 3 | import io.objectbox.annotation.Entity; 4 | import io.objectbox.annotation.Id; 5 | import io.objectbox.relation.ToOne; 6 | 7 | @Entity 8 | public final class MetaBranch { 9 | @Id 10 | long id; 11 | 12 | String name; 13 | String description; 14 | 15 | public ToOne<MetaBranch> parent; 16 | 17 | public long getId() { 18 | return id; 19 | } 20 | 21 | public void setId(long id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getDescription() { 34 | return description; 35 | } 36 | 37 | public void setDescription(String description) { 38 | this.description = description; 39 | } 40 | 41 | public ToOne<MetaBranch> getParent() { 42 | return parent; 43 | } 44 | 45 | public void setParent(ToOne<MetaBranch> parent) { 46 | this.parent = parent; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/resources/io/objectbox/corrupt-keysize0-data.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-java/c84c0822c6d8e50ad9008794a3aa5e9913bc4a83/tests/objectbox-java-test/src/test/resources/io/objectbox/corrupt-keysize0-data.mdb -------------------------------------------------------------------------------- /tests/objectbox-java-test/src/test/resources/io/objectbox/corrupt-pageno-in-branch-data.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/objectbox/objectbox-java/c84c0822c6d8e50ad9008794a3aa5e9913bc4a83/tests/objectbox-java-test/src/test/resources/io/objectbox/corrupt-pageno-in-branch-data.mdb -------------------------------------------------------------------------------- /tests/test-proguard/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("java-library") 3 | } 4 | 5 | tasks.withType<JavaCompile> { 6 | // Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used. 7 | // https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation 8 | options.release.set(8) 9 | } 10 | 11 | repositories { 12 | // Native lib might be deployed only in internal repo 13 | if (project.hasProperty("gitlabUrl")) { 14 | val gitlabUrl = project.property("gitlabUrl") 15 | maven { 16 | url = uri("$gitlabUrl/api/v4/groups/objectbox/-/packages/maven") 17 | name = "GitLab" 18 | credentials(HttpHeaderCredentials::class) { 19 | name = project.findProperty("gitlabPrivateTokenName")?.toString() ?: "Private-Token" 20 | value = project.property("gitlabPrivateToken").toString() 21 | } 22 | authentication { 23 | create<HttpHeaderAuthentication>("header") 24 | } 25 | println("Dependencies: added GitLab repository $url") 26 | } 27 | } else { 28 | println("Dependencies: GitLab repository not added. To resolve dependencies from the GitLab Package Repository, set gitlabUrl and gitlabPrivateToken.") 29 | } 30 | } 31 | 32 | val obxJniLibVersion: String by rootProject.extra 33 | 34 | val junitVersion: String by rootProject.extra 35 | 36 | dependencies { 37 | implementation(project(":objectbox-java")) 38 | 39 | // Check flag to use locally compiled version to avoid dependency cycles 40 | if (!project.hasProperty("noObjectBoxTestDepencies") 41 | || project.property("noObjectBoxTestDepencies") == false) { 42 | println("Using $obxJniLibVersion") 43 | implementation(obxJniLibVersion) 44 | } else { 45 | println("Did NOT add native dependency") 46 | } 47 | 48 | testImplementation("junit:junit:$junitVersion") 49 | } 50 | -------------------------------------------------------------------------------- /tests/test-proguard/src/main/java/io/objectbox/test/proguard/ObfuscatedEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.objectbox.test.proguard; 18 | 19 | import io.objectbox.annotation.*; 20 | 21 | // THIS CODE IS GENERATED BY ObjectBox, DO NOT EDIT. Enable "keep" sections if you want to edit. 22 | 23 | /** 24 | * Entity "ObfuscatedEntity". 25 | */ 26 | @Entity 27 | public class ObfuscatedEntity { 28 | 29 | @Id 30 | private long id; 31 | private int myInt; 32 | private String myString; 33 | 34 | public ObfuscatedEntity() { 35 | } 36 | 37 | public ObfuscatedEntity(long id) { 38 | this.id = id; 39 | } 40 | 41 | public ObfuscatedEntity(long id, int myInt, String myString) { 42 | this.id = id; 43 | this.myInt = myInt; 44 | this.myString = myString; 45 | } 46 | 47 | public long getId() { 48 | return id; 49 | } 50 | 51 | public void setId(long id) { 52 | this.id = id; 53 | } 54 | 55 | public int getMyInt() { 56 | return myInt; 57 | } 58 | 59 | public void setMyInt(int myInt) { 60 | this.myInt = myInt; 61 | } 62 | 63 | public String getMyString() { 64 | return myString; 65 | } 66 | 67 | public void setMyString(String myString) { 68 | this.myString = myString; 69 | } 70 | 71 | } 72 | --------------------------------------------------------------------------------