Entity
Object Hierarchy:
Description:
public class Entity :
Object
An Entity represents a record in a table, or the table itself when defining it to Almanna.
Example:
using Almanna;
public class Account : Entity {
public override string entity_name { owned get { return "account"; } }
public int account_id { get; set; }
public int account_status_id { get; set; }
public string username { get; set; }
public string password_hash { get; set; }
public DateTime date_created { get; set; }
public DateTime date_modified { get; set; }
public override void register_entity() {
add_column( new Column<int>.with_name_type( "account_id", "integer" ) );
columns["account_id"].size = 4;
add_column( new Column<int>.with_name_type( "account_status_id", "integer" ) );
columns["account_status_id"].size = 4;
columns["account_status_id"].is_nullable = true;
add_column( new Column<string>.with_name_type( "username", "character varying" ) );
columns["username"].size = 40;
add_column( new Column<string>.with_name_type( "password_hash", "character" ) );
columns["password_hash"].size = 40;
add_column( new Column<DateTime>.with_name_type( "date_created", "timestamp without time zone" ) );
columns["date_created"].size = 8;
columns["date_created"].is_nullable = true;
add_column( new Column<DateTime>.with_name_type( "date_modified", "timestamp without time zone" ) );
columns["date_modified"].size = 8;
columns["date_modified"].is_nullable = true;
try {
set_primary_key("account_id");
} catch (EntityError e) {
stderr.printf( "Error adding primary key to entity: %s\n", e.message );
}
}
}
Content:
Properties:
Creation methods:
Methods:
- public void seal ()
Function called after an entity has been filled by the datastore.
- public void unseal ()
Function called before an entity has been filled by the datastore.
- public void reload () throws SearchError
Reload the data in this entity from the data store.
- public void bind_data_from (Object o, bool? ignore_nulls = false)
Bind properties to this entity from properties in the given entity.
- public void bind_data_to (Object o, bool? ignore_nulls = false)
Bind properties from this entity to properties in the given entity.
- public Search<Entity> search () throws SearchError
- public virtual void register_entity ()
The register_entity() method is provided by your entity, and adds the
columns and relationships associated with the entity. This is automatically called by the entity loader.
- public virtual void save () throws EntityError, ExecuteError, SearchError
Save the current object to the data store
- public virtual void @delete () throws EntityError, ExecuteError
Delete the current object from the data store
- public ArrayList<Entity>? get_related (string related)
Get a list of items from a related entity, as defined with a
might_have relationship.
- public Search<Entity>? get_related_search (string related)
Get a Search object for related items, as defined with a might_have
relationship.
- protected void add_column (Column column)
Add a column. Must have a corresponding property in the entity.
- protected void add_columns (ArrayList<Column?> columns)
Add multiple columns. Must have corresponding properties in the
entity.
- protected void set_primary_key (string column) throws EntityError
Set one primary key for this entity. Will throw an error if the given
column has not been added via add_column.
- protected void set_primary_keys (string[] columns) throws EntityError
Set multiple primary keys for this entity. Will throw an error if any
of the given columns have not been added via add_column.
- protected void add_unique_constraint (string name, string[] columns) throws EntityError
Create a unique constraint corresponding to a database-provided unique
constraint.
- protected void add_has_one (string property_name, string this_column, string? foreign_column = null) throws EntityError
Add a has_one relationship. A has_one relationship implies that this
entity will have a corresponding record in the joined entity. Most SQL implementations would make this an INNER JOIN.
- protected void add_might_have (string property_name, string this_column, string? foreign_column = null) throws EntityError
Add a might_have relationship. A might_have relationship implies that
this entity may or may not have a corresponding record in the joined entity. Most SQL implementations would make this a LEFT JOIN.
- protected void add_has_many (string property_name, Type many_of, string? this_column, string? foreign_column)
Add a has_many relationship. A has_many relationship has zero or more
related records in another table. Most implementations would do a separate select.
- protected void add_many_to_many (string name, Entity join_entity, Entity foreign_entity, string? this_column, string? foreign_column)
- public string? _normalize_property (string property)
- public ParamSpec? _get_property (string property)
- public string? _type_of (string property)
- public Type? _gtype_of (string property)
- public void _set_in_storage ()
Fields:
Inherited Members:
All known members inherited from class GLib.Object