-
Notifications
You must be signed in to change notification settings - Fork 0
Get started
olestxcode edited this page Nov 6, 2020
·
1 revision
Welcome to the litebase wiki!
A litebase project has some basic interfaces and classes:
-
Column- this interface is a Java presentation of relational table's column. -
ColumnBuilder- a builder class forColumncreating. -
DataContainer<T, ID>- this interface is a Java presentation of relational tables. -
DataContainerBuilder<T, ID>- a builder class forDataContainer<T, ID>creating. -
Data- this interface provides an access to a query result. -
HashMapData- a simple implementation ofDataclass based on HashMap.
Let's create a Person class:
import lombok.Data;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor
@AllArgsConstructor
public class Person {
private final long id;
private String name, surname;
}
Let's create a DataContainer for Person class:
DataContainer persons = new MySqlDataContainerBuilder()
.withName("person_data")
.withDataSource(myDataSource)
.withColumn(new ColumnBuilder(Long.class)
.setName("id")
.setPrimary(true)
.build())
.withColumn(new ColumnBuilder(String.class)
.setName("name")
.build())
.withColumn(new ColumnBuilder(String.class)
.setName("surname")
.build())
.withDataMapper(object -> {
Data data = new HashMapData();
data.writeLongValue("id", object.getId());
data.writeStringValue("name", object.getName());
data.writeStringValue("surname", object.getSurname());
return data;
})
.withObjectMapper(data -> {
return new Person(data.getLongValue("id"), data.getStringValue("name"), data.getStringValue("surname"));
})
.build();
We can:
-
create();- create a table -
delete()- delete a table -
delete(Person)- delete a specified person from table -
findById(Long)- find Person by id - and some other methods you can use.