Skip to content
G-Art edited this page Dec 30, 2020 · 10 revisions

ORM

CoreTex core based on ORM developed especially for the platform and named ActiveORM. AcriveORM based on modified active record design pattern. The main difference is each record object (Item) can't perform CRUD operation for themself and used for this porpuses service layer and acts as a container for data with lazy load abilities.

ActiveOrm based on several components:

  1. MetaContext, ItemContext
  2. Cache
  3. CRUD opperation services
  4. Query transformator

ActiveORM load persistence metadata from dedicated tables in DB to memory in the system initialization stage. Metadata used for query transformation, field restriction validation, building an automatic query for explicit CRUD actions, extracting and mapping result set data.

Storing metadata to DB allowed to avoid using reflection for query transformation and result set data extraction it allowed reach good performance for CRUD operation.

Short CRUD operations example:

public class ExampleClass{

@Resource
private ItemService itemService;

@Resource
private SearchService searchService;

public void createExample() {
    ExampleItem exampleItem = itemService.create(ExampleItem.class, UUID.fromString("00000000-0000-0000-0000-000000000000"));
    exampleItem.setExampleFiels("Example data");
    itemService.save(exampleItem);
}

public void searchExample() {
    ExampleItem exampleItem = searchService.search("SELECT * FROM Example as e WHERE e.uuid = :uuid", Map.of("uuid", UUID.fromString("00000000-0000-0000-0000-000000000000")))
}

public void updateExample() {
    ExampleItem exampleItem = searchService.search("SELECT * FROM Example as e WHERE e.uuid = :uuid", Map.of("uuid", UUID.fromString("00000000-0000-0000-0000-000000000000")))
    exampleItem.setExampleFiels("Example data new");
    itemService.save(exampleItem);
}

public void deleteExample() {
    ExampleItem exampleItem = searchService.search("SELECT * FROM Example as e WHERE e.uuid = :uuid", Map.of("uuid", "00000000-0000-0000-0000-000000000000"))
    itemService.delete(exampleItem);
}

}

Query

To retrieve some data from DB you may use a regular SQL syntax query. The query will be parsed and transformed if you use item name instead of table name. example:

"SELECT * FROM " + ExampleItem.ITEM_TYPE + " as e"

If you use item type instead of table name this query will be automatically transformed and table name will be adjusted additionally will be added or adjusted "WHERE" where will be added "metaType" field to separate required type and solve inheritance collision for one table storing types.

For queries where used inherited types that have dedicated tables will be added union blocks automatically.