Core Types¶
Type Aliases¶
| Type | Definition | Unit | Description |
|---|---|---|---|
TTPrimaryKey |
Int32 |
Trysil.Types |
Primary key type (single integer) |
TTVersion |
Int32 |
Trysil.Types |
Version column for optimistic locking |
TTPrimaryKeyHelper¶
Class helper for TTPrimaryKey:
Converts a primary key value to its SQL string representation.
TTNullable<T>¶
Generic nullable wrapper for entity fields. See Nullable Types for full documentation.
// Declaration
[TColumn('MiddleName')]
FMiddleName: TTNullable<String>;
// Create with value
LValue := TTNullable<String>.Create('John');
// Check and read
if not LValue.IsNull then
ShowMessage(LValue.Value);
// Default values
LName := LValue.GetValueOrDefault; // type default
LName := LValue.GetValueOrDefault('N/A'); // custom default
// Equality
if LValue1.Equals(LValue2) then ...
// Set to null
LValue := nil;
Key points:
- No default constructor — uninitialized state is null
- Supports implicit conversion from
T - Operators:
=,<> - Supported types:
String,Integer,Int64,Double,Currency,Boolean,TDateTime,TGUID
TTValue¶
Alias for TValue from System.Rtti. Used throughout the framework for filter parameters and column values.
TTEventMethodType¶
Enum defining lifecycle event types:
| Value | Description |
|---|---|
BeforeInsert |
Before inserting a new record |
AfterInsert |
After inserting a new record |
BeforeUpdate |
Before updating an existing record |
AfterUpdate |
After updating an existing record |
BeforeDelete |
Before deleting a record |
AfterDelete |
After deleting a record |
TTUpdateMode¶
Controls the WHERE clause strategy on UPDATE and DELETE commands:
| Value | Description |
|---|---|
KeyAndVersionColumn |
Default. Includes version column for optimistic locking |
KeyOnly |
Uses only the primary key (for tables without [TVersionColumn]) |
Set on the connection:
Collections¶
TTList<T>¶
Generic list with LINQ-style filtering. Unit: Trysil.Generics.Collections.
var LPersons := LContext.CreateEntityList<TPerson>();
try
LContext.SelectAll<TPerson>(LPersons);
// Filter with predicate
var LPredicate: TTPredicate<TPerson> :=
function(const AItem: TPerson): Boolean
begin
Result := AItem.Firstname = 'David';
end;
for var LPerson in LPersons.Where(LPredicate) do
WriteLn(LPerson.Lastname);
finally
LPersons.Free;
end;
Supports ITEnumerable<T> / ITEnumerator<T> for for..in loops.
TTObjectList<T>¶
Owned list (OwnsObjects = True). Used internally by the framework for managing object lifetimes. For a list of entities use TTContext.CreateEntityList<T> instead, which owns what the identity map does not and tells the context about every entity it frees; an owning TTObjectList<T> of your own is right for the result of a RawSelect<T> into a plain DTO and for objects that are not entities. See who frees what.
// Default: OwnsObjects = True
var LList := TTObjectList<TPerson>.Create;
// Explicit OwnsObjects
var LList := TTObjectList<TPerson>.Create(False);
TTHashList<T>¶
Hash-based set for fast lookups:
var LSet := TTHashList<String>.Create;
try
LSet.Add('value');
if LSet.Contains('value') then ...
LSet.Remove('value');
finally
LSet.Free;
end;
TTCache<K, V>¶
Generic key-value cache. Unit: Trysil.Cache.
Used internally by TTMapper and other components for caching computed results.
TTRoundRobin<T>¶
Generic round-robin load balancer. Unit: Trysil.LoadBalancing.
TTRoundRobin<T> is abstract: declare a descendant for the type you are
balancing.
type
TConnectionPool = class(TTRoundRobin<TTConnection>)
end;
var
LBalancer: TConnectionPool;
LConnection: TTConnection;
begin
LBalancer := TConnectionPool.Create;
try
LBalancer.CreateItems(
function: TTConnection
begin
result := TTSqlServerConnection.Create('Main');
end,
4);
LConnection := LBalancer.Next;
finally
LBalancer.Free;
end;
end;
Next returns nil when nothing has been created, and cycles from the first
item afterwards. CreateItems adds to the pool rather than replacing it, so
calling it twice doubles the pool; a size below one is clamped to one. The
balancer owns what the factory returns and frees it with itself, so the
connections above must not be freed by the caller.
Trysil uses it to spread log items across the logger threads, in the core logger (TTLoggerThreads) and in the HTTP log (TTHttpLogThreads).