diff --git a/.ci/release.sh b/.ci/release.sh index 08a54d75..b7ec9582 100644 --- a/.ci/release.sh +++ b/.ci/release.sh @@ -3,16 +3,18 @@ if [[ -z "${TRAVIS_TAG}" ]]; then echo "Not a tagged release" else - echo "Creating DataGate zip distribution" + echo "Copying artifacts" cp nitrite-datagate/build/libs/nitrite-datagate-$NITRITE_VERSION.jar nitrite-datagate/src/main/dist/lib/nitrite-datagate.jar cp nitrite-datagate/build/libs/nitrite-datagate-$NITRITE_VERSION.jar nitrite-datagate/src/main/docker/nitrite-datagate.jar rm nitrite-datagate/src/main/dist/lib/.gitkeep + echo "Creating DataGate zip distribution" cd nitrite-datagate/src/main/dist/ zip -r nitrite-datagate-$NITRITE_VERSION.zip bin conf lib cd - echo $(pwd) echo "Creating docker image" cd nitrite-datagate/src/main/docker + chmod +x datagate.sh docker build -t dizitart/nitrite-datagate:$NITRITE_VERSION . docker tag dizitart/nitrite-datagate:$NITRITE_VERSION dizitart/nitrite-datagate:latest docker login -u $DOCKER_USER -p $DOCKER_PASS diff --git a/.travis.yml b/.travis.yml index cdb11db8..df2d2d62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,5 +42,5 @@ deploy: env: global: - - NITRITE_VERSION=1.0 + - NITRITE_VERSION=1.0.1 - PGP_KEY_FILE=~/secring.gpg diff --git a/README.adoc b/README.adoc index 924eff28..dc3827da 100644 --- a/README.adoc +++ b/README.adoc @@ -5,6 +5,9 @@ image:https://codecov.io/gh/dizitart/nitrite-database/branch/master/graph/badge. image:https://javadoc.io/badge/org.dizitart/nitrite.svg["Javadocs", link=https://javadoc.io/doc/org.dizitart/nitrite] image:https://badges.gitter.im/dizitart/nitrite-database.svg["Gitter", link="https://gitter.im/dizitart/nitrite-database?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"] + +image:http://www.dizitart.org/nitrite-database/doc/1.0/images/nitrite-logo.svg[Logo 200, 200] + **NO**sql **O**bject (*NO~2~* a.k.a Nitrite) database is an open source nosql embedded document store written in Java. It has MongoDB like API. It supports both in-memory and single file based persistent store powered by @@ -71,6 +74,31 @@ ObjectRepository repository = db.getRepository(Employee.class); -- +*Annotations for POJO* +[source,java] +-- +// provides index information for ObjectRepository +@Indices({ + @Index(field = "joinDate", type = IndexType.NonUnique), + @Index(field = "name", type = IndexType.Unique) +}) +public class Employee implements Serializable { + // provides id field to uniquely identify an object inside an ObjectRepository + @Id + private long empId; + + private Date joinDate; + + private String name; + + private String address; + + // ... public getters and setters +} + +-- + + *CRUD Operations* [source,java] -- @@ -111,7 +139,7 @@ repository.insert(emp); collection.createIndex("firstName", indexOptions(IndexType.NonUnique)); collection.createIndex("note", indexOptions(IndexType.Fulltext)); -// create object index +// create object index. It can also be provided via annotation repository.createIndex("firstName", indexOptions(IndexType.NonUnique)); -- @@ -198,7 +226,7 @@ Release notes are available https://github.com/dizitart/nitrite-database/release |=== |Reference |API -|[Document] +|http://www.dizitart.org/nitrite-database[Document] |https://javadoc.io/doc/org.dizitart/nitrite[JavaDoc] |=== @@ -236,4 +264,4 @@ before you file an issue please check if it is already existing or not. == Maintainers -* Anindya Chatterjee \ No newline at end of file +* Anindya Chatterjee diff --git a/build.gradle b/build.gradle index 60575074..c72337b7 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ buildscript { classpath "io.franzbecker:gradle-lombok:$lombokPluginVersion" classpath "org.asciidoctor:asciidoctor-gradle-plugin:$asciidoctorPluginVersion" classpath "net.ltgt.gradle:gradle-errorprone-plugin:$errorPronePluginVersion" - classpath "com.github.jengelman.gradle.plugins:shadow:$shadowPluginVersion" + classpath "com.github.jengelman.gradle.plugins:shadow:$shadowPluginVersion" classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:$nexusStagingPlugin" } } diff --git a/gradle.properties b/gradle.properties index 728f9ca1..4dcad941 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,7 +22,7 @@ org.gradle.jvmargs=-Xmx1024m # artifact version -nitriteVersion=1.0 +nitriteVersion=1.0.1 # nitrite dependency asciidoctorVersion=1.5.4 @@ -44,6 +44,7 @@ log4j2Version=2.6.2 lombokVersion=1.16.10 lombokPluginVersion=1.7 luceneVersion=4.9.0 +meanbeanVersion=2.0.3 mongoDriverVersion=3.4.2 nexusStagingPlugin=0.8.0 objenesisVersion=2.4 diff --git a/nitrite-datagate/README.adoc b/nitrite-datagate/README.adoc new file mode 100644 index 00000000..9986dcec --- /dev/null +++ b/nitrite-datagate/README.adoc @@ -0,0 +1,74 @@ += Nitrite DataGate + +If you are using Nitrite Database in your applications and want to synchronize the data in +real-time across the devices, you need DataGate. + +Nitrite DataGate is the replication server for Nitrite database. It comes as a separate product. +It is available as a binary distribution or as a docker image. + +To get the latest binary distribution please visit the +https://github.com/dizitart/nitrite-database/releases[Release] page of Github. +The docker image is available at docker hub + +[source,bash] +-- +docker pull dizitart/nitrite-datagate +-- + +*Configuration* + +DataGate server needs a MongoDb instance to run. To configure Mongo details, edit the file +*datagate.properties* inside the *conf* directory of the binary distribution and set the below +properties + +[source,properties] +-- +# Mongo Config +datagate.mongo.host= +datagate.mongo.port= +datagate.mongo.user= +datagate.mongo.password= +datagate.mongo.database= +-- + +And run the server, execute the below command from bin folder + +[source,bash] +-- +./datagate.sh +-- + +To configure and run the docker image, some details like MongoDb connection +needs to be provided. Create some docker file like below and build it for +the desired result. + +[source,docker] +-- +FROM dizitart/nitrite-datagate + +COPY keystore.jks / + +## Connection details (Replace with your own values) +ENV DATAGATE_HOST "0.0.0.0" +ENV DATAGATE_HTTP_PORT "8080" +ENV DATAGATE_HTTPS_PORT "8443" +ENV DATAGATE_MONITOR_PORT "9090" +ENV DATAGATE_KEY_STORE "keystore.jks" +ENV DATAGATE_KEY_PASSWORD "s3cret" + +## Mongo connection details (Replace with your own values) +ENV DATAGATE_MONGO_HOST "192.168.0.100" +ENV DATAGATE_MONGO_PORT "2706" +ENV DATAGATE_MONGO_USER "demo" +ENV DATAGATE_MONGO_PASSWORD "demoPass" +ENV DATAGATE_MONGO_DATABASE "demo" + +## Starts the server +RUN ["chmod", "+x", "./datagate.sh"] +ENTRYPOINT [ "./datagate.sh" ] +-- + +Once the server is up and running, access the admin portal using the url +-- + http(s)://:/datagate +-- diff --git a/nitrite-datagate/src/main/docker/Dockerfile b/nitrite-datagate/src/main/docker/Dockerfile index 51b977c3..cef77b58 100644 --- a/nitrite-datagate/src/main/docker/Dockerfile +++ b/nitrite-datagate/src/main/docker/Dockerfile @@ -9,7 +9,8 @@ ENV JAVA_OPTS "$JAVA_OPTS -Drun.mode=docker -Djava.security.egd=file:/dev/./uran # log settings ENV DATAGATE_LOG_FILE "/logs/datagate.log" -ENV DATAGATE_SYNC_LOG_CLEANUP_DELAY "30" #days +# default 30 days cleanup policy +ENV DATAGATE_SYNC_LOG_CLEANUP_DELAY "30" ## Configure below environment variables #ENV DATAGATE_HOST "" @@ -26,4 +27,5 @@ ENV DATAGATE_SYNC_LOG_CLEANUP_DELAY "30" #days #ENV DATAGATE_MONGO_PASSWORD "" #ENV DATAGATE_MONGO_DATABASE "" +#RUN ["chmod", "+x", "./datagate.sh"] #ENTRYPOINT [ "./datagate.sh" ] \ No newline at end of file diff --git a/nitrite-datagate/src/main/java/org/dizitart/no2/datagate/NitriteDataGate.java b/nitrite-datagate/src/main/java/org/dizitart/no2/datagate/NitriteDataGate.java index cf67030c..b00663bd 100644 --- a/nitrite-datagate/src/main/java/org/dizitart/no2/datagate/NitriteDataGate.java +++ b/nitrite-datagate/src/main/java/org/dizitart/no2/datagate/NitriteDataGate.java @@ -27,6 +27,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -56,7 +58,7 @@ @EnableSwagger2 @EnableScheduling @SpringBootApplication -@EnableAutoConfiguration +@EnableAutoConfiguration(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class }) public class NitriteDataGate extends WebMvcConfigurerAdapter { @Value("${datagate.mongo.host}") diff --git a/nitrite/build.gradle b/nitrite/build.gradle index d784f834..f2bf5cb8 100644 --- a/nitrite/build.gradle +++ b/nitrite/build.gradle @@ -48,6 +48,7 @@ dependencies { testCompile "org.awaitility:awaitility:$awaitilityVersion" testCompile "joda-time:joda-time:$jodaTimeVersion" testCompile "com.squareup.okhttp3:mockwebserver:$okhttpVersion" + testCompile "org.meanbean:meanbean:$meanbeanVersion" } gradle.buildFinished { BuildResult result -> diff --git a/nitrite/src/docs/asciidoc/collections/annotations.adoc b/nitrite/src/docs/asciidoc/collections/annotations.adoc new file mode 100644 index 00000000..9504310d --- /dev/null +++ b/nitrite/src/docs/asciidoc/collections/annotations.adoc @@ -0,0 +1,30 @@ +Nitrite provides a set of annotations for entity objects while using it in ObjectRepository. The +annotations are to let Nitrite knows about various information about the ObjectRepository while +constructing it. It also helps to reduce some boilerplate code. + +.Example +[source,java] +-- +// Employee class +@Indices({ + @Index(field = "joinDate", type = IndexType.NonUnique), + @Index(field = "name", type = IndexType.Unique) +}) +public class Employee implements Serializable { + @Id + private long empId; + + private Date joinDate; + + private String name; + + private String address; + + // ... public getters and setters +} + +-- + +`Index` annotation is to let Nitrite knows about the field which will be indexed. `Id` annotation +is to mark a field as id field. This id field is used to uniquely identify an object inside an +ObjectRepository. More on these annotations will be discussed later. \ No newline at end of file diff --git a/nitrite/src/docs/asciidoc/index.adoc b/nitrite/src/docs/asciidoc/index.adoc index 896746f9..3f6dca14 100644 --- a/nitrite/src/docs/asciidoc/index.adoc +++ b/nitrite/src/docs/asciidoc/index.adoc @@ -100,6 +100,10 @@ include::nitrite-collection.adoc[] include::object-repository.adoc[] +==== Annotations + +include::collections/annotations.adoc[] + ==== NitriteMapper include::collections/nitrite-mapper.adoc[] diff --git a/nitrite/src/docs/asciidoc/tools/datagate.adoc b/nitrite/src/docs/asciidoc/tools/datagate.adoc index 2d67758c..df20741a 100644 --- a/nitrite/src/docs/asciidoc/tools/datagate.adoc +++ b/nitrite/src/docs/asciidoc/tools/datagate.adoc @@ -1,12 +1,13 @@ Nitrite DataGate is the replication server for Nitrite database. It comes as a separate product. It is available as a binary distribution or as a docker image. -To get the latest binary distribution please visit the Release page of Github. The docker image +To get the latest binary distribution please visit the +https://github.com/dizitart/nitrite-database/releases[Release] page of Github. The docker image is available at docker hub [source,bash] -- -docker pull dizitart/nitrite-datagate:1.0 +docker pull dizitart/nitrite-datagate -- *Configuration* @@ -38,7 +39,7 @@ the desired result. [source,docker] -- -FROM dizitart/nitrite-datagate:1.0 +FROM dizitart/nitrite-datagate COPY keystore.jks / @@ -58,5 +59,11 @@ ENV DATAGATE_MONGO_PASSWORD "demoPass" ENV DATAGATE_MONGO_DATABASE "demo" ## Starts the server +RUN ["chmod", "+x", "./datagate.sh"] ENTRYPOINT [ "./datagate.sh" ] --- \ No newline at end of file +-- + +Once the server is up and running, access the admin portal using the url +-- + http(s)://:/datagate +-- diff --git a/nitrite/src/main/java/org/dizitart/no2/Cursor.java b/nitrite/src/main/java/org/dizitart/no2/Cursor.java index e559ffa6..1ed76316 100644 --- a/nitrite/src/main/java/org/dizitart/no2/Cursor.java +++ b/nitrite/src/main/java/org/dizitart/no2/Cursor.java @@ -25,11 +25,11 @@ * [source,java] * . Example of {@link Cursor} * -- - * // createId/open a database + * // create/open a database * Nitrite db = Nitrite.builder() * .openOrCreate("user", "password"); * - * // createId a collection named - test + * // create a collection named - test * NitriteCollection collection = db.getCollection("test"); * * // returns all ids un-filtered @@ -43,7 +43,7 @@ * -- * * [icon="{@docRoot}/note.png"] - * NOTE: To createId an iterator over the documents instead of the ids, + * NOTE: To create an iterator over the documents instead of the ids, * call on the {@link Cursor}. * * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/IndexOptions.java b/nitrite/src/main/java/org/dizitart/no2/IndexOptions.java index 9b227ba2..1d88eee1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/IndexOptions.java +++ b/nitrite/src/main/java/org/dizitart/no2/IndexOptions.java @@ -29,10 +29,10 @@ public class IndexOptions { /** - * Specifies the type of an index to createId. + * Specifies the type of an index to create. * * @param indexType type of an index. - * @returns type of an index to createId. + * @returns type of an index to create. * */ @Getter @Setter private IndexType indexType; @@ -42,7 +42,7 @@ public class IndexOptions { * way. * * @param async if set to `true` then the index will be created asynchronously; - * otherwise createId index operation will wait until all existing + * otherwise create index operation will wait until all existing * documents are indexed. * @returns `true` if index is to be created asynchronously; otherwise `false`. * @see NitriteCollection#createIndex(String, IndexOptions) diff --git a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java index 65fae4a6..04094e30 100644 --- a/nitrite/src/main/java/org/dizitart/no2/Nitrite.java +++ b/nitrite/src/main/java/org/dizitart/no2/Nitrite.java @@ -55,7 +55,7 @@ * [NOTE] * ==== * - It does not support ACID transactions. - * - Use {@link NitriteBuilder} to createId a db instance. + * - Use {@link NitriteBuilder} to create a db instance. * ==== * * @author Anindya Chatterjee @@ -78,7 +78,7 @@ public class Nitrite implements Closeable { } /** - * Provides a builder utility to createId a {@link Nitrite} database + * Provides a builder utility to create a {@link Nitrite} database * instance. * * @return a {@link NitriteBuilder} instance. diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java b/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java index 9af6a52d..33e6e928 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteBuilder.java @@ -41,7 +41,7 @@ import static org.dizitart.no2.util.StringUtils.isNullOrEmpty; /** - * A builder utility to createId a {@link Nitrite} database instance. + * A builder utility to create a {@link Nitrite} database instance. * * === Example: * @@ -106,7 +106,7 @@ public class NitriteBuilder { /** * Sets file name for the file based store. If `file` is `null` - * the builder will createId an in-memory database. + * the builder will create an in-memory database. * * @param path the name of the file store. * @return the {@link NitriteBuilder} instance. @@ -116,6 +116,22 @@ public NitriteBuilder filePath(String path) { return this; } + /** + * Sets file name for the file based store. If `file` is `null` + * the builder will create an in-memory database. + * + * @param file the name of the file store. + * @return the {@link NitriteBuilder} instance. + */ + public NitriteBuilder filePath(File file) { + if (file == null) { + this.filePath = null; + } else { + this.filePath = file.getPath(); + } + return this; + } + /** * Sets the size of the write buffer, in KB disk space (for file-based * stores). Unless auto-commit is disabled, changes are automatically @@ -269,8 +285,8 @@ public NitriteBuilder nitriteMapper(NitriteMapper nitriteMapper) { /** * Opens or creates a new database. If it is an in-memory store, then it - * will createId a new one. If it is a file based store, and if the file does not - * exists, then it will createId a new file store and open; otherwise it will + * will create a new one. If it is a file based store, and if the file does not + * exists, then it will create a new file store and open; otherwise it will * open the existing file store. * * [icon="{@docRoot}/note.png"] @@ -288,7 +304,7 @@ public NitriteBuilder nitriteMapper(NitriteMapper nitriteMapper) { * -- * * @return the nitrite database instance. - * @throws NitriteIOException if unable to createId a new in-memory database. + * @throws NitriteIOException if unable to create a new in-memory database. * @throws NitriteIOException if the database is corrupt and recovery fails. * @throws IllegalArgumentException if the directory does not exist. */ @@ -298,8 +314,8 @@ public Nitrite openOrCreate() { /** * Opens or creates a new database. If it is an in-memory store, then it - * will createId a new one. If it is a file based store, and if the file does not - * exists, then it will createId a new file store and open; otherwise it will + * will create a new one. If it is a file based store, and if the file does not + * exists, then it will create a new file store and open; otherwise it will * open the existing file store. * * While creating a new database, it will use the specified user credentials. @@ -324,7 +340,7 @@ public Nitrite openOrCreate() { * @param password the password * @return the nitrite database instance. * @throws SecurityException if the user credentials are wrong or one of them is empty string. - * @throws NitriteIOException if unable to createId a new in-memory database. + * @throws NitriteIOException if unable to create a new in-memory database. * @throws NitriteIOException if the database is corrupt and recovery fails. * @throws NitriteIOException if the directory does not exist. */ diff --git a/nitrite/src/main/java/org/dizitart/no2/NitriteId.java b/nitrite/src/main/java/org/dizitart/no2/NitriteId.java index 74608c62..1b3d9a6d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/NitriteId.java +++ b/nitrite/src/main/java/org/dizitart/no2/NitriteId.java @@ -32,7 +32,7 @@ * * During insertion if an unique object is supplied in the '_id' field * of the document, then the value of the '_id' field will be used to - * createId a new {@link NitriteId}. If that is not supplied, then nitrite + * create a new {@link NitriteId}. If that is not supplied, then nitrite * will auto generate one and supply it in the '_id' field of the document. * * diff --git a/nitrite/src/main/java/org/dizitart/no2/ObjectId.java b/nitrite/src/main/java/org/dizitart/no2/ObjectId.java index cbacd25c..bb8026c1 100644 --- a/nitrite/src/main/java/org/dizitart/no2/ObjectId.java +++ b/nitrite/src/main/java/org/dizitart/no2/ObjectId.java @@ -165,7 +165,7 @@ private static int createMachineIdentifier() { } catch (Throwable t) { // exception sometimes happens with IBM JVM, use random machinePiece = (new SecureRandom().nextInt()); - log.warn("Failed to createId machine identifier from network interface, using random number instead", t); + log.warn("Failed to create machine identifier from network interface, using random number instead", t); } machinePiece = machinePiece & LOW_ORDER_THREE_BYTES; return machinePiece; @@ -185,7 +185,7 @@ private static short createProcessIdentifier() { } catch (Throwable t) { processId = (short) new SecureRandom().nextInt(); - log.warn("Failed to createId process identifier from JMX, using random number instead", t); + log.warn("Failed to create process identifier from JMX, using random number instead", t); } return processId; diff --git a/nitrite/src/main/java/org/dizitart/no2/filters/Filters.java b/nitrite/src/main/java/org/dizitart/no2/filters/Filters.java index c0fc9c6a..d6ad259e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/filters/Filters.java +++ b/nitrite/src/main/java/org/dizitart/no2/filters/Filters.java @@ -20,7 +20,7 @@ import org.dizitart.no2.Filter; /** - * A helper class to createId all type of {@link Filter}s. + * A helper class to create all type of {@link Filter}s. * * @since 1.0 * @author Anindya Chatterjee diff --git a/nitrite/src/main/java/org/dizitart/no2/internals/IndexingService.java b/nitrite/src/main/java/org/dizitart/no2/internals/IndexingService.java index 3cd9ec8c..070dbc98 100644 --- a/nitrite/src/main/java/org/dizitart/no2/internals/IndexingService.java +++ b/nitrite/src/main/java/org/dizitart/no2/internals/IndexingService.java @@ -65,7 +65,7 @@ void createIndex(String field, IndexType indexType, boolean isAsync) { Object fieldLock = indexMetaService.getFieldLock(field); synchronized (fieldLock) { if (!indexMetaService.hasIndex(field)) { - // if no index createId index + // if no index create index index = indexMetaService.createIndexMetadata(field, indexType); } else { // if index already there throw @@ -110,7 +110,7 @@ void updateIndexEntry(Document document, NitriteId nitriteId) { NitriteMap> indexMap = indexMetaService.getIndexMap(field); - // createId the nitriteId list associated with the value + // create the nitriteId list associated with the value ConcurrentSkipListSet nitriteIdList = indexMap.get((Comparable) fieldValue); @@ -159,7 +159,7 @@ void removeIndexEntry(Document document, NitriteId nitriteId) { NitriteMap> indexMap = indexMetaService.getIndexMap(field); - // createId the nitriteId list associated with the value + // create the nitrite list associated with the value if (fieldValue instanceof Comparable) { ConcurrentSkipListSet nitriteIdList = indexMap.get((Comparable) fieldValue); if (nitriteIdList != null) { @@ -243,7 +243,7 @@ private void buildIndexInternal(final String field, final Index index) { indexMetaService.markDirty(field); if (index.getIndexType() != IndexType.Fulltext) { - // createId index map + // create index map NitriteMap> indexMap = indexMetaService.getIndexMap(field); @@ -251,7 +251,7 @@ private void buildIndexInternal(final String field, final Index index) { indexMap.clear(); for (Map.Entry entry : underlyingMap.entrySet()) { - // createId the document + // create the document Document object = entry.getValue(); // retrieved the value from document @@ -260,7 +260,7 @@ private void buildIndexInternal(final String field, final Index index) { if (fieldValue == null) continue; validateDocumentIndexField(fieldValue, field); - // createId the id list associated with the value + // create the id list associated with the value ConcurrentSkipListSet nitriteIdList = indexMap.get((Comparable) fieldValue); if (nitriteIdList == null) { nitriteIdList = new ConcurrentSkipListSet<>(); @@ -281,7 +281,7 @@ private void buildIndexInternal(final String field, final Index index) { } else { // for update-rebuild or remove-rebuild this block will never come for (Map.Entry entry : underlyingMap.entrySet()) { - // createId the document + // create the document Document object = entry.getValue(); // retrieve the value from document diff --git a/nitrite/src/main/java/org/dizitart/no2/internals/NitriteTextIndexingService.java b/nitrite/src/main/java/org/dizitart/no2/internals/NitriteTextIndexingService.java index e9469bdf..30ccf700 100644 --- a/nitrite/src/main/java/org/dizitart/no2/internals/NitriteTextIndexingService.java +++ b/nitrite/src/main/java/org/dizitart/no2/internals/NitriteTextIndexingService.java @@ -159,7 +159,7 @@ private Set searchByTrailingWildCard(String field, String searchStrin Set idSet = new LinkedHashSet<>(); String term = searchString.substring(0, searchString.length() - 1); - for (val entry : indexMap.entrySet()) { + for (Map.Entry> entry : indexMap.entrySet()) { String key = (String) entry.getKey(); if (key.startsWith(term.toUpperCase())) { idSet.addAll(entry.getValue()); @@ -173,7 +173,7 @@ private Set searchContains(String field, String term) { = indexMetaService.getIndexMap(field); Set idSet = new LinkedHashSet<>(); - for (val entry : indexMap.entrySet()) { + for (Map.Entry> entry : indexMap.entrySet()) { String key = (String) entry.getKey(); if (key.contains(term.toUpperCase())) { idSet.addAll(entry.getValue()); @@ -192,7 +192,7 @@ private Set searchByLeadingWildCard(String field, String searchString Set idSet = new LinkedHashSet<>(); String term = searchString.substring(1, searchString.length()); - for (val entry : indexMap.entrySet()) { + for (Map.Entry> entry : indexMap.entrySet()) { String key = (String) entry.getKey(); if (key.endsWith(term.toUpperCase())) { idSet.addAll(entry.getValue()); diff --git a/nitrite/src/main/java/org/dizitart/no2/objects/DefaultObjectRepository.java b/nitrite/src/main/java/org/dizitart/no2/objects/DefaultObjectRepository.java index 174b011f..26e0be6e 100644 --- a/nitrite/src/main/java/org/dizitart/no2/objects/DefaultObjectRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/objects/DefaultObjectRepository.java @@ -16,7 +16,6 @@ package org.dizitart.no2.objects; -import lombok.val; import org.dizitart.no2.*; import org.dizitart.no2.Index; import org.dizitart.no2.event.ChangeListener; @@ -28,15 +27,14 @@ import java.lang.reflect.Field; import java.util.Collection; +import java.util.Set; import static org.dizitart.no2.Constants.DOC_ID; import static org.dizitart.no2.IndexOptions.indexOptions; import static org.dizitart.no2.UpdateOptions.updateOptions; import static org.dizitart.no2.exceptions.ErrorCodes.*; import static org.dizitart.no2.exceptions.ErrorMessage.*; -import static org.dizitart.no2.util.ObjectUtils.createUniqueFilter; -import static org.dizitart.no2.util.ObjectUtils.extractIndices; -import static org.dizitart.no2.util.ObjectUtils.getIdField; +import static org.dizitart.no2.util.ObjectUtils.*; import static org.dizitart.no2.util.StringUtils.isNullOrEmpty; import static org.dizitart.no2.util.ValidationUtils.notNull; @@ -316,8 +314,8 @@ private void initRepository(NitriteContext nitriteContext) { private void createIndexes() { validateCollection(); - val indexes = extractIndices(nitriteMapper, type); - for (val idx : indexes) { + Set indexes = extractIndices(nitriteMapper, type); + for (org.dizitart.no2.objects.Index idx : indexes) { if (!collection.hasIndex(idx.value())) { collection.createIndex(idx.value(), indexOptions(idx.type(), false)); } diff --git a/nitrite/src/main/java/org/dizitart/no2/sync/SyncService.java b/nitrite/src/main/java/org/dizitart/no2/sync/SyncService.java index dd07e54b..ee64182d 100644 --- a/nitrite/src/main/java/org/dizitart/no2/sync/SyncService.java +++ b/nitrite/src/main/java/org/dizitart/no2/sync/SyncService.java @@ -55,7 +55,7 @@ void pullChanges() { if (syncTemplate.isOnline()) { // pull all changes from remote to local, but local changes are // not pushed to remote. - // createId the last sync time of local, pull everything from remote + // create the last sync time of local, pull everything from remote // from that time and update local. try { if (syncTemplate.trySyncLock(syncConfig.getSyncDelay(), originator)) { diff --git a/nitrite/src/main/java/org/dizitart/no2/sync/data/UserAgent.java b/nitrite/src/main/java/org/dizitart/no2/sync/data/UserAgent.java index 7a16286b..f1391a45 100644 --- a/nitrite/src/main/java/org/dizitart/no2/sync/data/UserAgent.java +++ b/nitrite/src/main/java/org/dizitart/no2/sync/data/UserAgent.java @@ -90,6 +90,7 @@ public static UserAgent parse(String userAgentString) { break; case 3: userAgent.setClientId(split[3].trim()); + //fall through default: break; } diff --git a/nitrite/src/main/java/org/dizitart/no2/util/DocumentUtils.java b/nitrite/src/main/java/org/dizitart/no2/util/DocumentUtils.java index 47ddefea..943f6ef8 100644 --- a/nitrite/src/main/java/org/dizitart/no2/util/DocumentUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/util/DocumentUtils.java @@ -82,7 +82,7 @@ public static Object getFieldValue(Document document, String field) { * are initialized to `null`. Such empty document is used for projection purpose. * * @param the type parameter - * @param nitriteMapper the {@link NitriteMapper} to createId the document. + * @param nitriteMapper the {@link NitriteMapper} to create the document. * @param type the class definition. * @return the empty document */ diff --git a/nitrite/src/main/java/org/dizitart/no2/util/ObjectUtils.java b/nitrite/src/main/java/org/dizitart/no2/util/ObjectUtils.java index 60f95e53..a65d48ea 100644 --- a/nitrite/src/main/java/org/dizitart/no2/util/ObjectUtils.java +++ b/nitrite/src/main/java/org/dizitart/no2/util/ObjectUtils.java @@ -18,7 +18,6 @@ import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.dizitart.no2.exceptions.IndexingException; import org.dizitart.no2.exceptions.InvalidIdException; import org.dizitart.no2.exceptions.NotIdentifiableException; @@ -86,7 +85,7 @@ public static String findObjectStoreName(Class type) { */ public static Set extractIndices(NitriteMapper nitriteMapper, Class type) { notNull(type, errorMessage("type can not be null", VE_INDEX_ANNOTATION_NULL_TYPE)); - val indexes = type.getAnnotation(Indices.class); + Indices indexes = type.getAnnotation(Indices.class); Set indexSet = new LinkedHashSet<>(); if (indexes != null) { Index[] indexList = indexes.value(); @@ -104,7 +103,7 @@ public static Set extractIndices(NitriteMapper nitriteMapper, Class { + @Override + public String[] create() { + return new String[] {"user", "admin", "client"}; + } + } +} + diff --git a/nitrite/src/test/java/org/dizitart/no2/sync/SimpleSyncTest.java b/nitrite/src/test/java/org/dizitart/no2/sync/SimpleSyncTest.java index 4000b8e7..deb2eb10 100644 --- a/nitrite/src/test/java/org/dizitart/no2/sync/SimpleSyncTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/sync/SimpleSyncTest.java @@ -39,7 +39,7 @@ public class SimpleSyncTest extends BaseSyncTest { @Test public void testSimpleSync() { - // createId primary sync handle + // create primary sync handle syncHandlePrimary = Replicator.of(primaryDb) .forLocal(primary) .withSyncTemplate(syncTemplate) @@ -48,7 +48,7 @@ public void testSimpleSync() { .withListener(new SyncTestEventListener()) .configure(); - // createId secondary sync handle + // create secondary sync handle syncHandleSecondary = Replicator.of(secondaryDb) .forLocal(secondary) .withSyncTemplate(syncTemplate)