-
Notifications
You must be signed in to change notification settings - Fork 0
Setup Database, Dao's and Entities.
Darius Wattimena edited this page Jun 24, 2017
·
4 revisions
Database:
- Can create the database table for the given entity.
Dao:
- Execute query's
- Find
- Save
- Delete
First add the needed annotations to the entity and extend the BaseEntity. A simple entity should look like this:
@Entity(tableName = "test_entity")
public class TestEntity extends BaseEntity<TestEntity> {
@Field(fieldName = "id", fieldType = FieldType.Integer, primary = true)
private Integer id;
@Field(fieldName = "name", fieldType = FieldType.Varchar)
private String name;
@Override
public Integer getId() {
return id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public List<TestEntity> buildResultSet(ResultSet resultSet) {
return null;
}
}
Once you're done with all the entities create the database and dao's. A basic Database should look like this:
public class TestDatabase {
public TestDatabase() throws Exception {
Resource resource = new Resource();
resource.setDatabase("DatabaseName");
resource.setHostname("localhost");
resource.setUser("admin");
resource.setPassword("password");
resource.setPort("80");
Database database = new Database(new MysqlDatabaseType(), resource);
database.createTable(TestEntity.class);
Dao<TestEntity> testEntityDao = new Dao<>(database, TestEntity.class);
}
}