Skip to content

douglasdotv/json-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Database

en pt-br

Description

This is a Java-based client–server application for storing, retrieving and modifying JSON data. It supports various JSON types (including objects, arrays, numbers and strings) and allows nested key access using keys provided as JSON arrays.

Features

  • File-Based Persistence: A file-based database is used to store the JSON data, ensuring data preservation across server restarts.
  • Concurrent Request Handling: ExecutorService is used to process multiple client requests concurrently.
  • Thread-Safe File Access: The ReentrantReadWriteLock implementation of ReadWriteLock is used to manage controlled read/write access to the database file.
  • Dynamic JSON Storage: Various JSON types are supported, allowing storage and modification of complex nested data.
  • Nested Key Access: Keys specified as JSON arrays are used to perform operations on nested JSON values.
  • Selective Deletion: Specific nested keys can be removed without affecting parent objects.

Examples

  • Set a Simple Key-Value Pair:

    java Main -t set -k message -v "Hello World!"

    Sent: {"type":"set","key":"message","value":"Hello World!"}
    Received: {"response":"OK"}

  • Set a Nested JSON Object:

    java Main -in setFile.json

    Sent:

    {
      "type": "set",
      "key": "user",
      "value": {
        "name": "Jane Doe",
        "contact": {
          "email": "jane.doe@example.com",
          "phone": "555-1234"
        },
        "preferences": {
          "language": "Java",
          "editor": "IntelliJ IDEA"
        }
      }
    }

    Received: {"response":"OK"}

  • Retrieve a Nested Value:

    java Main -in getFile.json

    Sent: {"type":"get","key":["user","name"]}
    Received: {"response":"OK","value":"Jane Doe"}

  • Update a Nested Value:

    java Main -in updateFile.json

    Sent: {"type":"set","key":["user","contact","phone"],"value":"555-4321"}
    Received: {"response":"OK"}

  • Delete a Nested Value:

    java Main -in deleteFile.json

    Sent: {"type":"delete","key":["user","preferences","editor"]}
    Received: {"response":"OK"}

  • Exit the Application:

    java Main -t exit

    Sent: {"type":"exit"}
    Received: {"response":"OK"}

About

A JSON database that utilizes the ExecutorService API for concurrency management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages