Getting started

Setting things up

This tutorial only works with ABEL shipped with EiffelStudio 14.05. You can find the code in the unstable directory.

It is also possible to get the latest code from the SVN directory .

Getting started

We will be using PERSON objects to show the usage of the API. In the source code below you will see that ABEL handles objects "as they are", meaning that to make them persistent you don't need to add any dependencies to their class source code.

class PERSON create make feature {NONE} -- Initialization make (first, last: STRING) -- Create a newborn person. require first_exists: not first.is_empty last_exists: not last.is_empty do first_name := first last_name := last age:= 0 ensure first_name_set: first_name = first last_name_set: last_name = last default_age: age = 0 end feature -- Basic operations celebrate_birthday -- Increase age by 1. do age:= age + 1 ensure age_incremented_by_one: age = old age + 1 end feature -- Access first_name: STRING -- The person's first name. last_name: STRING -- The person's last name. age: INTEGER -- The person's age. invariant age_non_negative: age >= 0 first_name_exists: not first_name.is_empty last_name_exists: not last_name.is_empty end

There are three very important classes in ABEL:

  • The deferred class PS_REPOSITORY provides an abstraction to the actual storage mechanism. It can only be used for read operations.
  • The PS_TRANSACTION class represents a transaction and can be used to execute read, insert and update operations. Any PS_TRANSACTION object is bound to a PS_REPOSITORY.
  • The PS_QUERY [G] class is used to describe a read operation for objects of type G.

To start using the library, we first need to create a PS_REPOSITORY.For this tutorial we are going to use an in-memory repository to avoid setting up any external database.Each ABEL backend will ship a repository factory class to make initialization easier.The factory for the in-memory repository is called PS_IN_MEMORY_REPOSITORY_FACTORY.

class START create make feature {NONE} -- Initialization make -- Initialization for `Current'. local factory: PS_IN_MEMORY_REPOSITORY_FACTORY do create factory.make repository := factory.new_repository create criterion_factory explore end repository: PS_REPOSITORY -- The main repository. end endWe will use criterion_factory later in this tutorial.The feature explore will guide us through the rest of this API tutorial and show the possibilities in ABEL.

cached: 04/23/2024 12:57:11.000 PM