Skip to content
Create a relational-database-like structure and JSONify it in Java.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
beautifier
data
datamanagement
README.md

README.md

DatabaseJSONifier

Create a relational-database-like structure and JSONify it in Java.

Example

I'm creating a database to store a person (name, surname, age).

A DataBase-Object needs a name and one or more tables.

A table is represented by the Table object.

The Table-Object needs a name and one or more rows.

The rows need some columns (a table is just a container of rows, while a row is a container of columns. They can be different)

A Column is a key-value object.

Let's create the data

Row row = new Row(
        new Column("name", "Andrea"),
        new Column("surname", "Riboni"),
        new Column("age", 18)
);
Row row2 = new Row(
        new Column("name", "John"),
        new Column("surname", "Smith"),
        new Column("age", 19)
);
Row row3 = new Row(
        new Column("name", "Matthew"),
        new Column("surname", "Blueberry"),
        new Column("age", 19)
);

Let's create the table to store them

Table table = new Table("Persons", row, row2, row3);

And let's retrieve the rows whose "name" column is equals to "Andrea"

Filter SimpleQuery = new Filter() {
        @Override
        public boolean filter(Row row) {
                //Is there a column with this name?
                Column col = row.getColumnByName("name");
                return col != null && (col.getValue().equals("Andrea"));
        }
};

Just print the result

System.out.println(table.query(SimpleQuery));

Output

{"Query":[{"row":[{"name": {"value": "Andrea", "type": "String"}},{"surname": {"value": "Riboni", "type": "String"}},{"age": {"value": "18", "type": "Integer"}}]}]}
You can’t perform that action at this time.