simerplaha / SwayDB

Persistent and in-memory key-value storage engine for JVM that scales on a single machine.
https://swaydb.simer.au
Apache License 2.0
293 stars 16 forks source link

Improve Java Slice API's usability #326

Open simerplaha opened 2 years ago

simerplaha commented 2 years ago

Accessing Slice from Java requires input ByteOps for each API call which is repetitive and no fun.

Slice
  .ofBytesJava(50) 
  .addInt(data.getInteger(), ByteOps.Java())
  .addLong(data.getLongVal(), ByteOps.Java())
  .addStringUTF8(data.getString(), ByteOps.Java())
  .close(); 

See example.

Solution

Maybe implement a Java singleton instance in Slice which makes the above simpler. For example:

Slice.Java // .java or SliceJava or SliceJ ?
  .ofBytes(50)
  .addInt(data.getInteger())
  .addLong(data.getLongVal())
  .addStringUTF8(data.getString())
  .close();

With a dedicated Java implementation we could possibly remove ByteOps all together as long as there are no boxing issues.

Reference code

See SliceTest.java. The end goal is to improve this API.

hemantgs commented 2 years ago

Hi , can I have a go

simerplaha commented 2 years ago

Sure! Go for it!

simerplaha commented 2 years ago

I've moved all Slice related to code into a single project called slice and all Java related code into single project swaydb-java.

This should make things easier.

simerplaha commented 2 years ago

Related task #319 requires @specialized(Byte) applied to Slice which in my IntelliJ setup does not register breakpoints.

To make debugging/breakpoints work remove @specialized(Byte) from Slice.scala.

simerplaha commented 2 years ago

@hemantgs sorry I've had to attempt at this task because I'm running some benchmarks and ByteOps needs to be removed. This commit is preview only.

Progress

All Java APIs in Slice will be prefixed j. So in our IDE we can just hit j to filter out java relevant functions.

image

If prefix java_ or j_ feel better. We can change this based on whatever is preferred but this naming convention should be consistent for all APIs.

simerplaha commented 2 years ago

The prefixes for Java APIs is inconvenient. There is a better way of doing this so Java APIs are seamless.

I'm going to remove "good first issue" label and work on core tasks. Will visit Java APIs before the release.

ghost commented 1 year ago

Hello sir , I am new to open source contribution. I already know java , my tech stacks & tools includes C, C++ , Python , Java, JavaScript , HTML , CSS , SQL , Bootstrap, ReactJS, ExpressJS, NodeJS & Git . I need a little help from your side to contribute to these amazing projects.

simerplaha commented 1 year ago

Hey! Welcome to the project :)

That's a wealth of knowledge you have there. That's awesome!

A great Java API is very important. Other than the issues labelled java I'd suggest just browsing through the Java code and see where you'd want to improve things.

SwayDB.java.examples is another project that is entirely Java which gets cloned a bit.

If there is anything specific you'd like to work on please go ahead and let me know how I can help.

But make sure to read the project status. As you can tell by the commit frequency SwayDB is not under active development right now. I hope to resume someday.

ghost commented 1 year ago

@simerplaha Need a little help , There are lots of functions i saw was new to me . in this product . what are the prerequired know we require about the project . Am i missing something about this project

simerplaha commented 1 year ago

Other than Scala there is no other prerequisite. SwayDB has no external core dependency so you'd just need to know Scala.

The Java API is written in Scala with the goal to have a nicer Java & Scala interop and minimum or no extra memory allocation. So it does not use anything from Scala's type-system that does not interop easily with Java.