Git Product home page Git Product logo

datastore's Introduction

DataStore

This is a file based key-vaue dataStore created in java, for storing data in a file. It supports basic CRD(create,read,delete) operations

Steps of installation

  • Create a folder named "DataStore" in C:\ drive of your windows system and clone this repository in that folder.(All the files and folders must be under DataStore folder).
  • Now to establish automatic deletetion of records which are expired or their time-to-live peroid is over. place DataStoreRun.bat file in startup programs of windows.
  • To find that startup folder press windows+R key and then in text box type shell:startup then click OK. The required folder will get open, in that folder put DataStoreRun.bat file.
  • Now the installation setup is done.

How to use this library

To instantiate the library

DataStoreInterface dataStore=DataStore.getInstance();

or

DataStoreInterface dataStore=DataStore.getInstance("C:\\path to desired file\\file.abc"); 
  • If path is not provided then it will get instantiated in the default location C:\dataStoreData\store.data otherwise in the file name provided.
  • Client can instantiate in multiple files but for any file only it's one instnace will be returned.

To store data in the file

public void create(String key,String jasonString,long time-to-live);
ex: dataStore.create("ABC","{\"abc\":\"pqr\"}",67577);
  • Third parameter time-to-live(in seconds) is optional, if provided then the key will be valid for only upto that durtion of time.
  • If key already exists or json is invalid then it will throw DatStoreException.
  • If fle size exceeds 1GB then it will throw DatStoreException.
  • If key passed is more than 32 characters then it will throw DatStoreException.
  • If the JSON passed is more than 16 KB then it will throw DataStoreException

To get json data

public String get(String key);
ex: dataStore.get("ABC");
  • To get data, pass the key for that data. If key is found then it will return JSON string for that, otherwise it will return null. this method throws DataStoreException.

To delete data

public boolean delete(String key);
ex: dataStore.delete("ABC");
  • This method will delete the key and data against that key if key is found. If found deleted then it will return true otherwise false. this method throws DataStoreException.

To compile and run the program

To compile: Add jar files in dist folder to your classpath

javac -classpath c:\DataStore\dist\*;. yourFileName.java

To run: Add jar files in dist folder to your classpath

java -classpath c:\DataStore\dist\*;. classFileName

Description

  • The code written in library is thread safe.
  • Not more than one process can access the same file at any instant of time.
  • This library is tested on windows-10 operating system.
  • JDK must be installed in your system to use this library.

A full code snipet for understanding

import com.freshworks.dataStore.DataStore;
import com.freshworks.dataStore.exceptions.*;
import com.freshworks.dataStore.interfaces.DataStoreInterface;
public class test1 {
   public static void main(String arg[])
   {
      try{
         DataStoreInterface dsi,dsi2,dsi3;
      //get instanece of store at default location - C:\dataStoreData\store.data
      dsi=DataStore.getInstance();
      
      //create and key and strore key value pair to store
      dsi.create("ABC","{\"name\":\"abc\"}" );
      dsi.create("XYZ","{\"name\":\"xyz\"}" );
      //get method to get  json against key ABC
      String abc=dsi.get("ABC");
      System.out.println(abc);

      String xyz=dsi.get("XYZ");
      System.out.println(xyz);
      
      //delete key and value against key ABC, it will return true if deleted successfully elese return false if key not found
      boolean isDel=dsi.delete("ABC");
      System.out.println(isDel);
      isDel=dsi.delete("XYZ");
      System.out.println(isDel);

      dsi2=DataStore.getInstance();
      System.out.println(dsi2.get("ABC"));

      dsi3=DataStore.getInstance("C:\\ddStore\\pqr.aa");
      dsi3.create("PQR", "{\"name\":\"pqr\"}");
         

      }catch(Exception e)
      {
         e.printStackTrace();
         System.out.println(e.getMessage());
      }
   }
   
}

Thanking you

datastore's People

Contributors

ambarish99 avatar

Watchers

 avatar

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.