Some Aucfan use ArangoDB. ArangoDB is a hybrid NoSQL database that takes advantage of DocumentDB and GraphDB.
** I'll leave DocumentDB and GraphDB aside. *
At Aucfan, we create services that utilize data such as product information and sales information.
In the team I belong to, I think that a database like ArangoDB is suitable when you want to handle information (specs etc.) with different properties for each product and data considering the relationship of data such as manufacturer and category. ,I'm using.
On the other hand, Java or Kotlin is used to create software that refers to and aggregates such data. Therefore, when accessing ArangoDB programmatically, use the Java API provided by ArangoDB.
ArangoDB is not Java. The data to be handled is basically in JSON format. Of course, the definition of the data type will be different from the program.
When the data type that is naturally used in Java is put in ArangoDB, it changes to the type that ArangoDB can handle (JSON format), and I tested it so that I would not be bothered by unintended type conversion when using data. ..
The various versions are as follows.
Java → ArangoDB
To store in ArangoDB, use the BaseDocument
class and set the data with the ʻaddAttribute ()` method.
Check the stored data with the ArangoDB Web UI and check the stored status.
Java type | → Arango DB type | Remarks |
---|---|---|
int | Numerical value(integer) | |
Integer | Numerical value(integer) | |
long | Numerical value(integer) | |
Long | Numerical value(integer) | |
float | Numerical value(Decimal) | * Data is corrupted |
Float | Numerical value(Decimal) | * Data is corrupted |
double | Numerical value(Decimal) | |
Double | Numerical value(Decimal) | |
BigDecimal | String | |
boolean | Boolean value(true/false) | |
Boolean | Boolean value(true/false) | |
LocalDate | String | ISO 8601 format |
LocalDateTime | String | ISO 8601 format |
OffsetDateTime | String | ISO 8601 format |
ZonedDateTime | String | ISO8601(Expansion)format |
List | Array | |
Map | object | The type in the object is the same as the above mapping |
ArangoDB → Java The data type when data is stored in ArangoDB from WebUI and acquired by Java is as follows.
ArangoDB type | → Java type | Remarks |
---|---|---|
String | String | |
Numerical value(integer) | Long | |
Numerical value(Decimal) | Double | |
Boolean value(true/false) | Boolean | |
Array | ArrayList | The inside type is the same as the others |
object | HashMap | The inside type is the same as the others |
Java → ArangoDB → Java The flow of data type change when the data stored in ArangoDB in Java is acquired in Java is as follows.
Java type | → Arango DB type | → Java type | Remarks |
---|---|---|---|
int | Numerical value(integer) | Long | |
Integer | Numerical value(integer) | Long | |
long | Numerical value(integer) | Long | |
Long | Numerical value(integer) | Long | |
float | Numerical value(Decimal) | Double | * Data is corrupted |
Float | Numerical value(Decimal) | Double | * Data is corrupted |
double | Numerical value(Decimal) | Double | |
Double | Numerical value(Decimal) | Double | |
BigDecimal | String | String | |
boolean | Boolean value(true/false) | Boolean | |
Boolean | Boolean value(true/false) | Boolean | |
LocalDate | String | String | ISO 8601 format |
LocalDateTime | String | String | ISO 8601 format |
OffsetDateTime | String | String | ISO 8601 format |
ZonedDateTime | String | String | ISO8601(Expansion)format |
List | Array | ArrayList | The inside type is the same as the others |
Map | object | HashMap | The type in the object is the same as the above mapping |
I found that I need to be a little careful when using ArangoDB with Java API.
You can use it without worrying about it
--Integer is a Long type --Double type decimal --The boolean value is Boolean type --List and Map collection classes
I want to expand a little
--If you want to handle with Big Decimal --If you put it in ArangoDB, it will be serialized to a string. --When fetching from ArangoDB, it is fetched as a character string, so deserialize the character string. --When using DateTime API of Java 8 or later --When you put it in ArangoDB, it is serialized to a string --When fetching from ArangoDB, it is fetched as a character string, so deserialize the character string.
In fact, the calculation of decimal numbers is more complicated. .. .. If you are interested ( ̄ ー  ̄)
Recommended Posts