Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 24 20:09
    anidotnet commented #216
  • Jun 24 20:03
    frett27 added as member
  • Jun 24 14:35
    anidotnet commented #228
  • Jun 24 09:09
    sheinbergon commented #228
  • Jun 23 18:04
    aleksandar-stefanovic commented #218
  • Jun 23 17:45
    aleksandar-stefanovic commented #218
  • Jun 23 09:56
    anidotnet commented #228
  • Jun 23 09:55
    anidotnet commented #228
  • Jun 23 09:21
    sheinbergon commented #228
  • Jun 23 09:19
    sheinbergon opened #228
  • Jun 22 15:44
    anidotnet commented #216
  • Jun 22 11:12
    frett27 commented #216
  • Jun 21 19:03
    anidotnet commented #216
  • Jun 21 18:31
    frett27 commented #216
  • Jun 19 10:22
    anidotnet commented #216
  • Jun 19 08:56
    frett27 commented #216
  • Jun 16 12:14
    anidotnet closed #227
  • Jun 16 12:14
    anidotnet commented #227
  • Jun 16 12:06
    aukhatov opened #227
  • Jun 10 12:07
    aukhatov commented #226
Nalaxon
@Nalaxon

@anidotnet Sry, for my late answer.
I would like to do the following:
1.) export ObjectStore into json file
2.) update some Objects
I can do both, but not in the same program, because as soon as I import Objects I need for the second step, I get an ClassNotFoundExceptionin the first step.

Why do we want to do the first step:

  • We simply want to be able to export the DB
  • We would like to use the zipped json files to do backups, because it seems that they are smaller in size than zippped db files

I hope this clarified a bit what I try to achieve.

Anindya Chatterjee
@anidotnet
Create a common library where you would put your entity files (e.g. Company class). Use the common library in program 1 where you will export the object and in the program 2 also where you wan to update the object. In this way Company class will always be there in your programs(both 1 and 2) as a library. I hope I have answered your question. If not, please create a small demo project explaining what you want to do and which also reproduce the error you are facing. That will really help to debug your issue.
Angelos Veglektsis
@angelix
FYI We have some exception reports when creating an index.
org.dizitart.no2.exceptions.IndexingException: 
  at org.dizitart.no2.internals.IndexingService.createIndex (IndexingService.java:74)
  at org.dizitart.no2.internals.NitriteService.createIndex (NitriteService.java:225)
  at org.dizitart.no2.internals.DefaultNitriteCollection.createIndex (DefaultNitriteCollection.java:74)

if (!mNitriteProperties.hasIndex(KEY_DB_KEY) && !mNitriteProperties.isIndexing(KEY_DB_KEY)) {
      mNitriteProperties.createIndex(KEY_DB_KEY, IndexOptions.indexOptions(IndexType.Unique, true));
}
Anindya Chatterjee
@anidotnet
@angelix which version of nitrite are you using and what error code it is throwing?
Angelos Veglektsis
@angelix

@anidotnet Nitrite v3.3.0

Caused by org.dizitart.no2.exceptions.IndexingException
NO2.5005: index already exists on key

Anindya Chatterjee
@anidotnet
@angelix it might be a synchronization issue. Try to move createIndex call out of your app's multithreading logic. Meantime, please share me some reproducible code.
Anindya Chatterjee
@anidotnet
@angelix is it possible for you to test your code against 3.4.0-SNAPSHOT?
Melvin Snijders
@TheMelvinNL
Is it possible to do a case insensitive search?
Anindya Chatterjee
@anidotnet
@TheMelvinNL you can use regex filter and use case-insensitive pattern. This SO question might help you - https://stackoverflow.com/questions/3436118/is-java-regex-case-insensitive
Dinesh
@dinbtechit
Hi @anidotnet , do you have any examples for exposing nitrite collections as a reactive streams Restful API?
Anindya Chatterjee
@anidotnet
@dinbtechit nope I don't have any ready made example.
Dinesh
@dinbtechit

@anidotnet - ok no worries Anindya I'll try to create something. But have a rookie question. The in-memory instance doesn't seem to store anything in the heap. I'm always getting null or actually nothing is returned. what am I doing wrong here?

// In Memory instance
Nitrite db = Nitrite.builder()
        .openOrCreate();

// Creating repository
 ObjectRepository<Employee> repository = db.getRepository(Employee.class);

// Inserting Employee
Employee emp = new Employee();
emp.setEmpId(12564);
emp.setAddress("12 Some Street");
repository.insert(employees);

// Listing all the employees
List<Employee> employees =  repository.find().toList();
for (Employee employee: employees) {
   System.out.println(employee);
}

Output - No records are being returned.

Any clue what am I doing wrong here?

Anindya Chatterjee
@anidotnet
@dinbtechit if you change repository.insert(employees); to repository.insert(emp); it works.
Dinesh
@dinbtechit
@anidotnet - Oops there was a typo in my question. I meant to type repository.insert(emp); 😀. It doesn't seem to store anything in the memory.
Anindya Chatterjee
@anidotnet
That is very strange. It seems to be working fine for me. Are you getting any error message?
Dinesh
@dinbtechit
There is no errors at all. I'm really baffled too.
It works fine if I store them in a file. Its just the in-memory. Doesn't want to store anything.
I'm running it on Jetty as a web application. Not sure if that makes any difference though.
Anindya Chatterjee
@anidotnet
OK just do one thing. Create a maven project, reproduce your issue and send me the project. I'll see what's going on
send me at anindya @ dizitart.com
Dinesh
@dinbtechit
sure.. on it.
Anindya Chatterjee
@anidotnet
I saw your code. There are 2 things.
a. If you want to maintain 2 types of db, you must create 2 separate Nitrite variables.
b. In your closeConnection method, you are closing the db. In-memory db is not persistent. As soon as you close the db, it looses data unlike file store db.
Dinesh
@dinbtechit
Thanks Anindya. Appreciate your response. Actually I just want to maintain the in-memory version of the db. The github code that I provided was more of an example to demonstrate 2 different behaviors. Unfortunately, I see the same behavior even if I don't close the connection and/or use a different variables.
Anindya Chatterjee
@anidotnet
@dinbtechit here is the final version of DatabaseConnection file which works

public final class DatabaseConnection {
    private static final DatabaseConnection DB_CONN = new DatabaseConnection();

    private Nitrite db;
    private ObjectRepository<Employee> repository;

    private DatabaseConnection(){
        db = Nitrite.builder().openOrCreate();
        repository = db.getRepository(Employee.class);
    }

    public static DatabaseConnection getInstance() {
        return DB_CONN;
    }

    /**
     * Inserting into inmemory
     * @param employee
     * @return
     */
    public List<Employee> insertIntoMemory(Employee employee) {
        return insert(employee);
    }

    /**
     * Find from memory
     * @param offset
     * @param size
     * @return
     */
    public List<Employee> findFromMemory(int offset, int size){
        return find(offset, size);
    }

    private List<Employee> insert(Employee employee){
        List<Employee> employees = new ArrayList<>();
        WriteResult wr = null;
        try {
            wr = repository.insert(employee);
            System.out.println("\n Affected Rows : " + wr.getAffectedCount());
            return repository.find().toList();

        } catch (Exception e) {
            System.out.println("Unable to insert transaction. ");
            e.printStackTrace();

        }
        return employees;
    }


    private List<Employee> find(int offset, int size) {
        List<Employee> employees = new ArrayList<>();
        try {
            employees = repository.find(limit(offset, size)).toList();
        } catch (Exception e) {
            System.out.println("Unable to find transactions. ");
            e.printStackTrace();
        }
        return employees;
    }

}
And here is the result
HTTP/1.1 200 OK
Date: Thu, 05 Dec 2019 18:30:39 GMT
Content-Type: application/json
Content-Length: 365
Server: Jetty(9.4.22.v20191022)

[
  {
    "empId": "f843e184-46f0-4967-b3e1-fecbb4dfcf23",
    "address": "From Memory. 123, North Pole."
  },
  {
    "empId": "6a75a311-5cb7-44fd-9ca8-1b7a86ea3b22",
    "address": "From Memory. 123, North Pole."
  },
  {
    "empId": "c2e3c339-26b3-4bb9-8823-41bc94e90065",
    "address": "From Memory. 123, North Pole."
  },
  {
    "empId": "1d40b65a-4ef7-4acf-973e-2b327f591629",
    "address": "From Memory. 123, North Pole."
  }
]

Response code: 200 (OK); Time: 35ms; Content length: 365 bytes
Not only closing the store after every call, you are also calling Nitrite.builder().openOrCreate()before every insert call, which is actually resetting the memory store before every insert.
Dinesh
@dinbtechit
Ahh! that totally makes sense. Massively appreciate that.
Jon Buck
@jonbuck16

Hi, I am not sure I understand the find API for a specific use case.. say I have some JSON as follows...

"tags": [
            {
                "type": "example"
            }
        ],

How do I write a find query that returns documents that have a tag where the key is type or documents that have a type field with the value example?

Anindya Chatterjee
@anidotnet
You have to use elemMatch filter here.
public void testCollectionField() {
        Document document = createDocument("name", "John")
            .put("tags", new Document[] {
                createDocument("type", "example").put("other", "value"),
                createDocument("type", "another-example").put("other", "some-other-value")
            });

        NitriteCollection example = db.getCollection("example");
        example.insert(document);

        document = createDocument("name", "Jane")
            .put("tags", new Document[] {
                createDocument("type", "example2").put("other", "value2"),
                createDocument("type", "another-example2").put("other", "some-other-value2")
            });
        example.insert(document);

        DocumentCursor cursor = example.find(elemMatch("tags", eq("type", "example")));
        for (Document doc : cursor) {
            System.out.println(doc);
        }
    }
nitrite currently does not support indexing on collection field, so for now you have to search un-indexed.
Jon Buck
@jonbuck16
@anidotnet Thanks for the help, will give this a try
Tareq Kirresh
@TareqK
@anidotnet Ive got a crazy idea
About the datagate
Interested ?
The idea is to re-write it as a separate project (as a library), and offer a standalone version as well
This way, we can allow people who want to build apps with the datagate to integrated it better instead of integrating via the database
Especially when it comest to stuff like access rights and access control and sync policies
I'm also thinking we should look at the sync client and use something more real time like a websocket or SSE instead of polling
Making things a bit faster and have higher data consistency
What do you think ?
Anindya Chatterjee
@anidotnet
Your point about refactoring the sync client, I definitely have it in my mind for the next major release 4.x. But I did not understand your proposal about datagate server. What use case do you have in mind? Care to elaborate? As for me, I was planning to rewrite it using golang as a separate application to squeeze maximum throughput during sync. Implementing it as a library I did not have it in my mind unless there is a valid use case.
Tareq Kirresh
@TareqK
The use case is simple : I, as someone who wants to build a mobile application that uses datagate, need integrated authentication and access rights (Ie, I can only see and edit my authorized data), need multiple login tokens (from my different clients), may need to modify data from web/desktop clients directly to the database, etc. In most applications, I'll also need a higher level of consistency for some entities, like invoice serials and stock numbers , etc. So a lot of the time, I'll be running the datagate alongside my application server, and getting data from both. Right now, this means that I'll be integrating via the database and running 2 servers. If the datagate were a library with its own endpoints integrated into my application, this wouldn't be the case, and I have more levels of consistency possible.
Anindya Chatterjee
@anidotnet
@TareqK in its current form you can do the same with datagate application. It's a spring boot application, so you should be good to integrate datagate into your application, provided your application is also a spring boot application. You just have to delete the application file NitriteDataGate.java from datagate.
Tareq Kirresh
@TareqK
I use JavaEE, since I need some of the features. Which is why I want it to be a library, so it's framework agnostic .
Anindya Chatterjee
@anidotnet
How are you planning to build a server component which is framework agnostic? You have to use some kind of framework to expose the endpoints. Moreover, what you are proposing is directly against microservice architecture. You can modify datagate source to fit your access control, but I'll suggest separate your application logic from datagate.
Tareq Kirresh
@TareqK
It can be kept agnostic by writing it as a plain servlet or websocket and using it in any servlet compatible environment. I mean we are going to rewrite it using websockets anyway, which means everything we use will be in the javax.ws package which is compatible with a lot of frameworks of varying complexity (spring , jersey, rest easy, spark, etc).
And as for the Microservices paradigm, it shouldn't be forced on users, they should be able to choose anyway.