Code Monkey home page Code Monkey logo

jsondb-core's Introduction

Circle CI Travis branch Coveralls branch

JsonDB is a pure java database that stores its data as Json Files.

A very small memory footprint, runs embedded within your java program.

Provides APIs that are very similar and inspired by MongoDB.

Provides a Apache JxPath based query system.

Visit http://jsondb.io for detailed information about Jsondb, Why Jsondb and Using Jsondb

Stargazers over time

Stargazers over time

jsondb-core's People

Contributors

alexstaeding avatar farooqkhan avatar jansoren avatar rzwitserloot avatar snwiem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsondb-core's Issues

Is is possible to have different json-files using the same document?

Hi 🙂

I have multiple collections that are using the same document. Is there any posibility to persist the different collections in different json-files?

The reason why I want to use multiple json files is that the data in them is large and has nothing to do with each other.

Nullpoint Exception for ID

I had in my project import javax.persistence.Id; as annotation for the models, usually every database share the same annotation, so I got a nullpoint exception for this.

So there 2 ways to solve this problem:

1- Handle this exception to show to the user a better information about the error.
2- Implement javax.persistence annotation as it is used by the most java db.

ClassCastException

Hello again,

I am having a different issue now.

Same bean

@Data
@Document(collection = "beans", schemaVersion = "1.0")
public class Bean {
  @Id
  private String id;
  
  private List<String> stuff;

  public Bean() {
    this.id = UUID.randomUUID().toString();
  }
}

and database class

public class Database {
 private final JsonDBTemplate jsonDBTemplate = new JsonDBTemplate...

  public void a() {
   List<Bean> all = jsonBDTemplate.findAll(Bean.class);
   for (Bean bean : all) {
     System.out.println(bean);
   }
 }
}

I also have a Spring Controller

@RestController
@RequestMapping("/test")
public class TestController {
  @Autowired
  private Database database;

  @RequestMapping("/a")
  public void invokeA() {
    database.a();
  }
}

So when I call http://localhost/test/a I get

java.lang.ClassCastException: Bean cannot be cast to Bean
  at Database.a() ~[]
  at TestController.invokeA() ~[]
  at sun.reflect .....

where the at Database.a() points to the line for (Bean bean : all) .

I was looking online and people suggest that somehow I may have several class loaders and somehow I may be casting classes from different class loaders. Have you ever had this, and how do I obtain more information for debug?

Spring boot starter parent: 1.5.8.RELEASE
Version: 1.0.64

File Writes Are Not Thread Safe

Using this in a simple Servlet container application and ran into concurrency issues where multiple threads are trying to write to the file at the same time. Looked at the code the only write protection is a FileLock, and the java documentation states that

File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine. (reference)

It should be as simple as marking the io methods synchronized.

I'm happy to do a RP if its welcomed.

Recursive data structures. Cycles not supported

I noticed the library does not support cycling relations. Also this is not documented within the readme or the documentation page so i just want to write this done for anyone else is interesting in it.
This is a common to not be handled with json so i will close this issue.

It will throw an StackOverflowError excpetion:

java.lang.RuntimeException: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: de.hartz.software.parannoying.model.DeviceData1["deviceData1"]-
	at io.jsondb.Util.deepCopy(Util.java:187)
	at io.jsondb.JsonDBTemplate.insert(JsonDBTemplate.java:840)
	at io.jsondb.JsonDBTemplate.insert(JsonDBTemplate.java:827)
```

Disable Package Scan?

How hard would it be to disable the package scan feature?

I would like to use the library in an OSGi environment where at best the scan finds nothing due to the way OSGi classloading works, and at worst, well does something worse. What I would like to do is manually hand the database the classes i would like it to use

How to get sort and Limit data?

Hello,
How can we get limit data like sql such as say within range from 1 - 10, then from 10-20 etc.

Also is there any way to get sorted data from the collection (as in order by etc)?

Thanks

Android does not find any classes

TL;DR;
It seems this project is not able to run on android.

At first thanks for this library. But i m struggeling a lot at getting it working with android.

currently my problem is that the lib is initalized properly but as soon as i want to call
jsonDBTemplate.createCollection(DeviceData1::class.java)
it throws

io.jsondb.InvalidJsonDbApiUsageException: No class found with @document Annotation ` 2020-08-31 21:26:20.854 15038-15038/de.hartz.software.parannoying E/AndroidRuntime: FATAL EXCEPTION: main Process: de.hartz.software.parannoying, PID: 15038 java.lang.RuntimeException: Unable to instantiate application de.hartz.software.parannoying.App: io.jsondb.InvalidJsonDbApiUsageException: No class found with @document Annotation and attribute collectionName as: root at android.app.LoadedApk.makeApplication(LoadedApk.java:989) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5733) at android.app.ActivityThread.-wrap1(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1660) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6521) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: io.jsondb.InvalidJsonDbApiUsageException: No class found with @document Annotation and attribute collectionName as: root at io.jsondb.JsonDBTemplate.createCollection(JsonDBTemplate.java:285) at io.jsondb.JsonDBTemplate.createCollection(JsonDBTemplate.java:275) at de.hartz.software.parannoying.model.Storage.init(Storage.kt:94) at de.hartz.software.parannoying.App.initStorage(App.kt:58) at de.hartz.software.parannoying.App.initApp(App.kt:26) at de.hartz.software.parannoying.App.initApp$default(App.kt:21) at de.hartz.software.parannoying.App.attachBaseContext(App.kt:50) at android.app.Application.attach(Application.java:189) at android.app.Instrumentation.newApplication(Instrumentation.java:1104) at android.app.Instrumentation.newApplication(Instrumentation.java:1088) at android.app.LoadedApk.makeApplication(LoadedApk.java:983) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5733)  at android.app.ActivityThread.-wrap1(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1660)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6521)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)  `

So it is not finding the entityclasses also the base package is properly set and the anntitation is set like mentioned in the usage section. On the other hand determineCollectionName is working without any problems..

when calling reflections.getAllTypes() in CollectionMetaData.builder(JsonDBConfig dbConfig) from the debugger it throws:
Couldn't find subtypes of Object. Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)

I disabled obfusication via gradle.build file:
...
minifyEnabled false
useProguard false
...
I m using Java 8 and also the Java 8 Lib ('io.jsondb:jsondb-core:1.0.115-j8'). In special i use Kotlin in the whole application, but also when i m creating java files for the Entities these are not found.


I dont have any further ideas on how to debugg this problem. Is this problem maybe already known or are there any work arounds?

db.delete can't delete objects in array based on index if the array name contains dashes

For example:

db.delete("/arraytest/my-array[0]"); // Wont work
db.delete("/arraytest/myarray[0]"); // Will work

I am storing an SSID as the array name and it would greatly simplify the code if i could keep it that way. Otherwise i will have to loop the array, match the SSID value, check the index of that value and delete the subdata based on the index where it matched the SSID value.

I have tried to encase the array name in brackets, to no avail.

Interestingly

db.delete("/arraytest/my-array"); // Will work just fine.

Anyone know a way to fix this?
Thanks for a great plugin.

JsonParseException deletes db file

When there is a problem in JSON file, it gets JsonParseException and it deletes this entry. But it should leave the file untouched, it is much better, otherwise we lost all the data because of a simple problem in JSON file.

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('6' (code 54)): was expecting a colon to separate field name and value
at [Source: ...; line: 1, column: 150]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipColon2(ReaderBasedJsonParser.java:2212) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipColon(ReaderBasedJsonParser.java:2191) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextFieldName(ReaderBasedJsonParser.java:924) ~[jackson-core-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:283) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789) ~[jackson-databind-2.8.3.jar:2.8.3]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2833) ~[jackson-databind-2.8.3.jar:2.8.3]
at io.jsondb.JsonDBTemplate.loadCollection(JsonDBTemplate.java:204) [jsondb-core-1.0.64.jar:?]
at io.jsondb.JsonDBTemplate.reloadCollection(JsonDBTemplate.java:170) [jsondb-core-1.0.64.jar:?]
at io.jsondb.JsonDBTemplate.loadDB(JsonDBTemplate.java:140) [jsondb-core-1.0.64.jar:?]
at io.jsondb.JsonDBTemplate.initialize(JsonDBTemplate.java:117) [jsondb-core-1.0.64.jar:?]
at io.jsondb.JsonDBTemplate.(JsonDBTemplate.java:95) [jsondb-core-1.0.64.jar:?]
at io.jsondb.JsonDBTemplate.(JsonDBTemplate.java:81) [jsondb-core-1.0.64.jar:?]

One file for each item in a collection

Is it possible to create one file for each item in a collection?
I have a large document with alot of items that ends up beeing a realy large collection.

Would be nice with something like

@Document("MyDocument"+id)

cannot access JsonDBTemplate

Every time I try to connect my application it generates the same error.

C:\Users\Thomaz\Desktop\Bot\src\main\java\bot\finn\discord\Main.java:15: error: cannot access JsonDBTemplate
import io.jsondb.JsonDBTemplate;
^
bad class file: C:\Users\Thomaz.gradle\caches\modules-2\files-2.1\io.jsondb\jsondb-core\1.0.115-j11\28dd0e74b2dfc45748de1a683b025a71913cc6fd\jsondb-core-1.0.115-j11.jar(io/jsondb/JsonDBTemplate.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

No class found with @Document Annotation and attribute collectionName as: User, Android

Hello there,
when I try to create collection this exception is thrown " No class found with @document Annotation and attribute collection Name as: User ", I am sure 100% my code and implementation are correct. If I use it in java code test it work 100%. The problem in reflection does not find the classes at runtime (samsung device). check the code below please:

this is my db init code:

String baseScanPackage = "com.myapp.chat.model";
  String base64EncodedKey = CryptoUtil.generate128BitKey(SomeSecretPassword, SomeUniqueSecreteSalt);
  ICipher cipher = new Default1Cipher(base64EncodedKey);
        jsonDBTemplate = new JsonDBTemplate(dbFilesLocation, baseScanPackage, cipher);

 if (!jsonDBTemplate.collectionExists(User.class))
            jsonDBTemplate.createCollection(User.class);

this is my User class code:

@Document(collection = "User", schemaVersion= "1.0")
public class User implements Serializable {

    @Id
    public String id;
   

    public User() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
   }

the problem is in reflection does not find classes at runtime.

Runtime error on Java(TM) SE Embedded Runtime Environment

Hi,

I wrote a simple test applicaiton with your jsondb. The application was running fine on windows/ubuntu and raspberry pi. But when i tried running it on a different embedded system (Arnv5tejl) I got an java.lang.NoClassDefFoundError: java/beans/PropertyDescriptor exception.

Before the exception I got a warning: "Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added". Any idea of what is going on here ?

java -version:
Java(TM) SE Embedded Runtime Environment (build 1.8.0_65-b17, profile compact2, headless)
Java HotSpot(TM) Embedded Minimal VM (build 25.65-b01, mixed mode)

uname -a:
Linux gw-446D 4.4.24 #1 Thu Jan 26 09:10:47 CET 2017 armv5tejl GNU/Linux

Output:
# java -jar simplejsondb.jar
Hello World!
[main] INFO io.jsondb.JsonDBConfig - Encryption is not enabled for JSON DB
Jan 30, 2017 6:00:17 AM com.fasterxml.jackson.databind.ext.Java7Support
WARNING: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 s upport added
[main] INFO org.reflections.Reflections - Reflections took 6262 ms to scan 1 url s, producing 1 keys and 2 values
Added a new jsonDBTemplate
Exception in thread "main" java.lang.NoClassDefFoundError: java/beans/PropertyDe scriptor
at org.apache.commons.jxpath.ri.model.beans.CollectionPointerFactory.cre ateNodePointer(CollectionPointerFactory.java:42)
at org.apache.commons.jxpath.ri.model.NodePointer.newNodePointer(NodePoi nter.java:81)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.(JXPath ContextReferenceImpl.java:193)
at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.(JXPath ContextReferenceImpl.java:167)
at org.apache.commons.jxpath.ri.JXPathContextFactoryReferenceImpl.newCon text(JXPathContextFactoryReferenceImpl.java:39)
at org.apache.commons.jxpath.JXPathContext.newContext(JXPathContext.java :416)
at io.jsondb.JsonDBTemplate.createCollection(JsonDBTemplate.java:309)
at io.jsondb.JsonDBTemplate.createCollection(JsonDBTemplate.java:270)
at martinharbo.kyrkjeveien.App.main(App.java:33)
Caused by: java.lang.ClassNotFoundException: java.beans.PropertyDescriptor
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more

Superflous dependencies declared

The following libraries are defined as compile dependencies:

          "org.slf4j:jcl-over-slf4j:1.7.21",
          "org.apache.logging.log4j:log4j-core:2.6.2",
          "org.apache.logging.log4j:log4j-api:2.6.2",
          "org.apache.logging.log4j:log4j-slf4j-impl:2.6.2",

However, as far as I can see this project uses the slf4j api, so it should be up to the application that uses jsondb to decide and package the desired logging implementation. I therefore suggest to drop them from here - or maybe add them as testCompile dependency if really needed for running the tests.

JDK Version of Binary Release at Maven Central

Currently, I'm trying to use JsonDB in a project of mine that is targeting JDK 8. Unfortunately, the binary release at Maven Central is built with JDK 11. If I use it in a JRE 8 environment I end up with the following exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: io/jsondb/JsonDBTemplate has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at TestMain.main(TestMain.java:7)

As far as I see, JsonDB is built using JDK 8 according to .travis.yml. I would be glad, if you can use JDK 8 for feature releases, as well. It would help me with using your project without having to build it on my own with an older JDK.

Simple collections as part of Documents

Hello,

I have a simple bean:

@Data
@Document(collection = "beans", schemaVersion = "1.0")
public class Bean {
  @Id
  private String id;
  
  private List<String> stuff;

  public Bean() {
    this.id = UUID.randomUUID().toString();
  }
}

and some database class

public class Database {
  private final JsonDBTemplate jsonDBTemplate = new JsonDBTemplate...

  public Database() {
    if (!jsonDBTemplate.collectionExists(Bean.class) {
      jsonDBTemplate.createCollection(Bean.class);
      Bean bean = new Bean();
      bean.setStuff(Arrays.asList("A", "B"));

      jsonDbTemplate.upsert(bean);
    }    
  }
}

So in json, bean comes as:

{"id":"8b38034d-77d6-443f-8f00-4d757f26658f","stuff":null}

Is the saving of basic collections inside of documents not supported? Is there a workaround for that?

Using version: 1.0.36

Thank you,
oiale

LocalDateTime cannot be persisted

Hi,

Is there any way to persist java.time.LocalDateTime?
I understand that the problem lays in the lack of a default constructor during the deepCopy phase.

java.lang.InstantiationException: java.time.LocalDateTime
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.new();

Thanks

getCollection always return the last item

@Data class BaseEntity { private String a; private String b; } @Data class AClass extends BaseEntity { @Id private Integer id; private String d; }
cause the property id is not in the BaseEntity,the source code only handle the most super clazz

invalid json format

A json file I generated with jsondb has multiple top-level values and thus (afaik) is not a valid json document.
Is there a way to configure jsondb to create entries under a single top-level value?

Example:

{"schemaVersion":"1.0"}
{"id":"foo","nickname":"a","onlineTimeSeconds":0,"lastSeenMillis":0,"ignoreAfk":false,"movedToAfk":0}
{"id":"bar","nickname":"b","onlineTimeSeconds":0,"lastSeenMillis":0,"ignoreAfk":false,"movedToAfk":0}
{"id":"baz","nickname":"c","onlineTimeSeconds":0,"lastSeenMillis":0,"ignoreAfk":false,"movedToAfk":0}

Insecure default cipher

The default cipher implementation at https://github.com/Jsondb/jsondb-core/blob/c49654d1eee2ace4d5ca5be19730652a966ce7f4/src/main/java/io/jsondb/crypto/DefaultAESCBCCipher.java is vulnerable to various attacks.

The cipher construction used is AES-128/192/256 in CBC mode with PKCS5 padding with the key as the IV and no authentication.

  • Lack of authentication leads to various interactive attacks. PKCS5+CBC makes these attacks fairly simple.
  • Using the key as the IV can be used to reveal the key, as CBC does not protect the confidentiality of the IV. For example, given a limited decryption oracle, an attacker could decrypt two identical blocks A||A. The decryption oracle in this mode will yield (Dec_K(A)^K) || (Dec_K(A)^A), which can be used to extract K.
  • Using the same IV repeatedly leads to distinguisher attacks.

All in all, this set of algorithms provides IND-EAV security at most. While the documentation does state that "CBC may not be the most secure mode", this is a severe understatement. Offering this set of algorithms as the only default, and even offering it at all, will lead to insecure storage of secrets.

Jsondb ignore formatting characters upon loading

First - off thanks for the great work! I have a feature suggestion: It would be nice, if jsondb can deal with whitespace resp. formatting characters upon loading.

Szeanario: To change data in the json files of jsondb i usually format the file in a Json Editor, which helps for editing the files. It seems that jsondb cannot deal with certain formatting. When i format a file for example with the JSON Editor Plugin in Eclipse on Windows i get upon loading the exception as seen in the attachted file exception.txt
with the file patch.txt ( I changed the suffix from json to txt because it's seem Github does'nt know json files)

Json db actually then deletes all data in file and starts with a fresh file.

I think the future to able to edit "live" and then reload the file is very good.

Bug: Multiple SchemaUpdates (Rename) not possible

In JsonDBTemplate.updateCollectionSchema the JasonWrite function renameKeyInJsonFile is called:
https://github.com/Jsondb/jsondb-core/blob/master/src/main/java/io/jsondb/JsonDBTemplate.java#L402

At this call the collection.values() are passed but not updated.

So if you have multiple renameOperations only the last one takes effect.

The renameKeyInJsonFile-Method should take the PathToCollectionFile instead of the collection.values() and only operate on the JsonFile

Symlinks broken

Seems like the database gets rewritten every time there's a modification to the data. This makes it impossible to use symlinks

jsonDBTemplate.getCollection() not able to identify already existing collection

We are trying to use jsonDBTemplate.getCollection() to check the Json files are already created and during next run even though the collection exists in the directory it is not able to fetch it and when it tries to createCollection, we get the following error: collection already exists.

Meaning during creation time, JsonDB is able to identify that collection exists and but jsonDBTemplate.getCollection() is not able to fetch the collection.

We implemented Serialisation and ensured that serialVersionUID is unique, but still facing the issue,. Can you please help

Why the weird format?

I am looking at this thing closely and i found one critical thing that i really dislike and i wanted to know why you did it. this line right here

T row = dbConfig.getObjectMapper().readValue(line, entity);

That line pretty much locks you into the idea that each collection is a non-standard json and you can never pretty print that json file. I want to use this as a way to inject test data into a gradle build, and the ability to pretty print the collection files is a big deal for me.

Why did you do it this way rather than a collection being an array of objects? If it was an array of objects you could simply use jackson or gson to slurp up the entire file and all is well

Method for fast retrieval of collection size

Such feature would be great instead of requiring a call to findAll and create a new collection. Or maybe I am missing some other way to do so on an more efficient way with the current API?

Failed to move temporary collection file instances

package io.swagger.jsondata;

import io.jsondb.annotation.Document;
import io.jsondb.annotation.Id;

@Document(collection = "instances", schemaVersion= "1.0")
public class Instance {
    @Id
    private String name;
    private String value;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
package io.swagger.utils;
import io.jsondb.JsonDBTemplate;
import io.jsondb.query.Update;
import java.io.File;
import io.swagger.jsondata.Instance;


public class GuidUtils {

    private static final Object lock = new Object();
    private static volatile JsonDBTemplate instance;
    private static String initValue="100000000";

    public static synchronized  JsonDBTemplate getJsonDBTemplate(){
        JsonDBTemplate r = instance;
        if (r == null) {
            synchronized (lock) {    // While we were waiting for the lock, another
                r = instance;        // thread may have instantiated the object.
                if (r == null) {
                    String dbFilesLocation = System.getProperty("user.home")+ File.separator+"jsondb";
                    String baseScanPackage = "io.swagger.jsondata";
                    r= new JsonDBTemplate(dbFilesLocation, baseScanPackage);
                    instance = r;
                }
            }
        }
        return r;
    }


    //C:\Users\EDZ\jsondb\instance.json
    public static String getUniqueId(){
        JsonDBTemplate jsonDBTemplate=GuidUtils.getJsonDBTemplate();
        if(!jsonDBTemplate.collectionExists(Instance.class)){
            jsonDBTemplate.createCollection(Instance.class);
            Instance instance = new Instance();
            instance.setName("guid");
            instance.setValue(initValue);
            jsonDBTemplate.insert(instance);
        }
        Instance instanceOld = jsonDBTemplate.findById("guid", Instance.class);
        Update update = Update.update("value", Long.parseLong(instanceOld.getValue())+1);
        String jxQuery = String.format("/.[name='%s']", "guid");
        Instance instanceNew = jsonDBTemplate.findAndModify(jxQuery, update, "instances");
        return instanceNew.getValue();
    }

    public static void main(String[] args) {
        for(int i=0;i<1000;i++){
            System.out.println(GuidUtils.getUniqueId());
        }
    }
    
}
19-01-17 09:56:43.260 ERROR [main] io.jsondb.io.JsonWriter                  updateInJsonFile 575 : Failed to move temporary collection file instances4765154015649112693.tmp to collection file instances.json
java.nio.file.AccessDeniedException: C:\Users\EDZ\jsondb\instances4765154015649112693.tmp -> C:\Users\EDZ\jsondb\instances.json
	at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
	at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
	at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:301)
	at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
	at java.nio.file.Files.move(Files.java:1395)
	at io.jsondb.io.JsonWriter.updateInJsonFile(JsonWriter.java:573)
	at io.jsondb.JsonDBTemplate.findAndModify(JsonDBTemplate.java:1333)
	at io.swagger.utils.GuidUtils.getUniqueId(GuidUtils.java:47)
	at io.swagger.utils.GuidUtils.main(GuidUtils.java:53)

TURN OFF ERROR HANDLING IN MAVEN RELEASES, PLEASE

can you please either remove logging output from stable releases, or remove logging altogether. while on this topic, the logging library this code uses is extremely vulnerable, and it's been this way for over year at least. the warning and info messages are meaningless, and hampers development, when trying to see my own debug messages. thanks in advance.

get rid of this, please! we don't need it.

97 [main] INFO io.jsondb.JsonDBTemplate - Encryption is not enabled for JSON DB 109 [main] WARN org.reflections.Reflections - given scan urls are empty. set urls in the configuration

Util.deepCopy() question

Hi Farooq,
I really love jsondb.io !!!

I did some experimentation: I commented out the deep copying code in the Util.java class:

protected static Object deepCopy(Object fromBean) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// XMLEncoder out = new XMLEncoder(bos);
// out.writeObject(fromBean);
// out.close();
//
// ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
// XMLDecoder in = new XMLDecoder(bis, null, null, JsonDBTemplate.class.getClassLoader());
// Object toBean = in.readObject();
// in.close();
// return toBean;
return fromBean;
}

Then I ran my application and it seems that there was no negative impact and after calling the JsonDBTemplate constructor for the first time, all other db calls where extremely fast!

My questions are:

  1. What is the benefit (or considerations) for doing the deep copying?
  2. NOT doing the deep copying - what problems may it cause, if any?
  3. I would like to gain more insight into when the json data files are loaded into memory: when calling the JsonDBTemplate constructor for the first time, does it load ALL the json data files into memory to cache the collections up-front?

Again, I love your DB and I look forward to hear your answers!

Support for excluding fields

In my needs, the POJO has some property which link directly to another POJO. From .net background, I believe it's called lazy-loading prop. My workaround is available so you can consider this as suggestion.

class Person {
...
}

class Teacher {
@Id
private int personId
...
// this prop is null in json file, I would love to have it deleted
public Person person;
}

Table Generation Strategy

Feature Request:

Create a setting for Table Generation Strategy.
Usually databases have 3 options:

  1. Create
  2. Drop and Create
  3. Update

JDK 15 compliance

I was just curious if this library would work with JDK 15. Using some features from it for a recent project and I've used this library in the past but for java 8 project.

Thanks in advance!

Modified json file make collectionExist return false

Hi!
I have 2 json db file. One for user (users.json) and one for transactions (transactions.json)
Everytime i run the java application. The transactions.json file is rewritten and i loose every data in it.
When i add some data in the file, the jsonDBTemplate.collectionExists(Transaction.class) return false so a new transactions.json is written.

ph

CollectionExists always return false

The following object always return false for the method collectionExists:

{"schemaVersion":"1.0"}
{"id":"66159eb1-ccde-4e23-8870-d313cea4df62","username":"Phoeniiiix","token":"eyJraWQiOiJuek9QejMycnBGYUdrVDlBQ3VzTmc0cXNlYmhBN1NBSzNISmtYZzFNSzBjPSIsImFsZyI6IlJTMjU2In0.eyJjdXN0b206bmF0aW9uYWxpdHlJc28iOiJCUiIsInN1YiI6IjY2MTU5ZWIxLWNjZGUtNGUyMy04ODcwLWQzMTNjZWE0ZGY2MiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0yLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMl83UU9ZOExMVVIiLCJjdXN0b206YXZhdGFyIjoiXC9pbWdcL2F2YXRhclwvYXZhdGFyMTMucG5nIiwiY29nbml0bzp1c2VybmFtZSI6IlBob2VuaWlpaXgiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJwaG9lbml4IiwiYXVkIjoiNmVrc3Fnb2RycWgyYWc4MWVjb3E0dTZ1aHAiLCJ1cGRhdGVkX2F0IjoxNTUzMzYxODE0LCJ0b2tlbl91c2UiOiJpZCIsImN1c3RvbTpuYXRpb25hbGl0eU5hbWUiOiJCcmFzaWwiLCJhdXRoX3RpbWUiOjE1NjkyNDU4MTcsImN1c3RvbTpkaXNwbGF5TmFtZSI6IlBob2VuaXgiLCJleHAiOjE1NjkyNDk0MTcsImlhdCI6MTU2OTI0NTgxNywiZW1haWwiOiJndWluaDk3QGdtYWlsLmNvbSJ9.OKs2-8LwtV_wDRQXqFEtFj-Uluh4GwRAoH5EjWtv-NxZA8HFKdUiOxxAynJLHztTFSI4JwhcUSUEiIWA4fLQcQ0yBPKuK2wIN6bYuKd3uPwAn29MSSiddnQatf76iaaYMhuy3BDnUax915_XdiQTVCL_1HP-jGIsVkt0mTknAvXdHIC7RgF2LVRsRNN5zUF37q-wqYGZQ4fo6IF-0vZ7gaBp3uDOp54XHnZ5KDzJi1aszb10xY7F_qPqBc58u8gBAy_xrbQMn_VzQ7n4eV91WJUWcNSaHSh2HZWqvcFbczMkdOWYngpZhc94jlfccP5reZO2JdngeoiUYYUBoEOZRg","email":"[email protected]","birthdate":null,"hmac":null,"displayName":"Phoenix","playerId":null,"avatar":"/img/avatar/avatar13.png","tokenExpiration":1569249417000,"nationalityIsoCode":"BR","nationalityIsoName":"Brasil","emailLogin":true,"tokenRefresh":"eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.NHyj1jh-lufEofDkQhNNKS-C3dRH457MPUiis8u9KwHjcM43txTeVR5gUzccFGAE9pbtObc30Y0DugIaGb-tvGwmtPPk5-cYZaVXAncFRmPtNxtxzg6vTkkaVUDpvlxIeRcxtIM336Ke77F5Dut4-yP_bQipXj22JCZmKtBSOt6Uame23LYvrptsqfr7pnNJbmyaAHeLUQBiIQR-WvjYjE2Z8PwYvDwwSjyjg74R6-XXrzNgFwFhzt-Y0q4_QMSXo5kzIoooMrOLRNLjyoFZCfGTJlXoXVx5QsIofTvtFp0S5BbrKowAgk2n2dqNlPtywYEg4GlJFmvOLLqY9vFz3w.yxqodh37n2Yyhalx.c-i--AE7LSyAjiCUHoxOVSwt6HJYrilLYIoSSslJAtgXbTTysIF2nx2xjgA5ZwHHJRQxXn9oH4hX0ph-XN7hdAU-pMFzEggQR-MIoODGzOqFnkISuzDfoEIMbIfeazLHERuUUHpHO8YF4heApHc_QmeozsIuxxyia-ycJ7nZymcAjwiEouT7Al3DF-3bwoZJIOJvECQ5nwx1XoWZbJdTtwh1JXf2o0_c_8tVpFduzK6oKvSuZ5FtlLFJmtW3ttiTNeVrgl_sKjGlUgywCj9lrw__2cFFHcwwYElzx4mbIG56aq0VUOlwKwuLDk56fhaU1-sVrIuPGPJbEuNJEZBdQCxq5SU-HnSpPernvnITp7b8IXxmlNgULwgPfNlDY_C_FnXZNr8FImcTSULW5N_x4RGHp9DmJyXUDUS-gOwo7PjRjLSJs5Z9_3fmuUkFxz8kDSfr01CLBPnXasr-BAo06d2Bj_awgjAktdtAx99FOQ9UjrjFRINsEaON1IcHJ2Y_jlxAvSi8JgBV08c6y6EDB-5znErnjtC74MdKqQg59FJ1egwtPZ6eBAxZeNmR17uSvVelh4H3gVf-WWqPBe_nLN7IGvaJuX1Ink_ZlLAe5s8vW9wN44-8d7uu8JrZZv02092I1YQZHUzt6n5n_hYKlNrHgGtHq2APO_GSaavO-AnL2pe1PgEEJdpNwwy1Sq3bgizQnsSNGXrZlo1w857FXA69FWfA9LADddA6jORvkmuYP9LLA1dixQ57Ae4h3UOBh0One2DxEJxhh3Q73oOaAaJ4uteOi-HuqnPBm5UCrNb6jA_OiGlP9NwVKTc3UD-EF4TMwcoQZN9EgFeBtoAAvBzK_tO8UH6KZH3rBnorZ4uF9IpLavJR2OmxqmXSQ3GJsADn0zqPRchAaGSCjp6D9QRnEB9pjbPPpubEMEeFKRb8rgtqOLGDRLfHb6IYJUMpyOGR7Ihv39U5YtX_8Qn6Vr9sK7B_IQdOshQyrlaAwEJQoFuBpCniIlCDdhAUXVq6-2Mrhqhq67ujIsAXhxnk0pVaCYNXfMZoP57r7_NEWAkpOuvSI6nWhyJcDqg_0OX4QVuoibFp4Ajm8J-cpXCoEfz2AVydKec5voM_82398bpSSmu_VYykBnjnIkB_TPr4RTeO2k-qNRcceNntbkYRpBGOjwdr1MT-dBnoWb9OBZv73H1GPE9M4FfSkeGzxFBiqrR-yqUAW6fbcWD8eA_qxN0Je55dAEKXS8YbMTE41c85O_tPHaFfS_a-2I-jWZFbzwvb39wWGHKWpN4RP5DPtDmy7D-cDnYaP7Y._GzD-eeiYayIem2CXTXGHQ","cashier":{"id":"2a58e8c6-5e47-4875-a1df-1c6940ce95fe","realMoney":0.0,"bonusMoney":3000.0,"playMoney":0.0,"rakeBack":693,"vipStatus":0,"vipProgress":0.0,"inPlayMoney":1000.0,"inRealMoney":0.0,"userId":"66159eb1-ccde-4e23-8870-d313cea4df62"},"game":{"id":"9ce97aff-16d4-4c05-8e27-10c2efc06ea5","userId":"66159eb1-ccde-4e23-8870-d313cea4df62","lol":null,"dota2":null,"r6s":{"id":"49d2e47d-8b01-4c19-b313-d00aff92fb3c","region":"sbr","isVerified":true,"name":"eMastersR6bot44","iconUrl":"https://ubisoft-avatars.akamaized.net/49d2e47d-8b01-4c19-b313-d00aff92fb3c/default_146_146.png","rank":"unranked","tier":null,"profileId":"49d2e47d-8b01-4c19-b313-d00aff92fb3c","userId":"66159eb1-ccde-4e23-8870-d313cea4df62","winRate":0.0,"url":"https://game-rainbow6.ubi.com/en-us/uplay/player-statistics/49d2e47d-8b01-4c19-b313-d00aff92fb3c/multiplayer","lastTimeChecked":null,"messages":{"free_to_use":true}},"fifa":null,"tft":null,"underlords":null,"valid":true},"avatars":null}

Addition of toString() method to document class results in it not being located

I have a document class that was not being picked up during the JsonDBTemplate initialize phase. After stripping it down to determine what might be causing it, I found that just the inclusion of the public String toString()... method in the class was causing it to not be recognized as a valid collection. I have not looked into why that is.

Clarify that a default constructor is needed

If no default constructor is given, calls to jsondb will fail with an ArrayOutOfBoundsException or an InstantiationException somewhere in a java.* package (during the XML serialization and deserialization step).

It would be nice to point out, that those POJOs have to be JavaBeans (and may be to clarify what a JavaBean is). It would be even better to check for a default constructor via reflection and throw a meaningful Exception.

ndjson parse example

hello.

i need develop server for parse ndjson format to java object .

can you show me an examples ?

thank you very much.

Provide security contact info

I'd like to privately discuss a security topic with the maintainers, but there is no way to privately contact them.

Ideally an e-mail address and PGP key should be provided.

xpath lower-case() find.

Does the xpath functionality support setting attributes to lowercase or the ability to translate() them.

Essentially I'm trying to run a find search for a parameter that is stored as case sensitive but can be found by a case insensitive value.

If i have an attribute in the db as such
name = John

and attempt to find values == to "john" would return that document.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.