Instant Object 用户指南

文章编目 [隐藏]

TInstantConnector 派生。提供对数据库的访问。

In order for your application to use the database as object storage, you must use a connector component. The connector acts as a gateway between your application and the database, managing all the objects that are stored to and retrieved from the database. A connector component for each type of data access layer that is supported by 文章Instant Objects is available on the component palette. A connector is attached to a database by assigning a connection component to its Connection property. Each connector component supports its own connection type:

Access type Connector type Connection type
ADO TInstantADOConnector TADOConnection
BDE TInstantBDEConnector TDatabase
IBX TInstantIBXConnector TIBDatabase

Drop an appropriate connector component and a matching connection component on a form or a data module in your project. Configure the connection component to access the database and assign it to the Connection property of the connector component. The connector will use the connection to gain access to the database. By setting the IsDefault property to True, the connector will be used as the default connector in the application.

TInstantConnector components are used to gain access to databases. The connector uses components that are specific to the database engine to establish the actual connection. Multiple objects and components can share the connection provided by a single TInstantConnector component.

TInstantConnector introduces properties and methods that fall into the following categories:

  • Connecting and disconnecting to a database
  • Transaction control
  • Information about the database
  • Initialization of a database specific persistence broker

Instant Objects 中的数据表对应的对象类是 TInstantObject, 所有的数据表对象类都从该类派生。对于抽象文章Instant Objects 类,换句话说,就是不形成数据表的InstantObject,选择 Persistent Embedded.

TInstantObject.SaveState 的时候被加入到 Connector.AddTransactedObject(Self) 并且 FSaveStateLevel 应该是 2。没有参与事务的对象在SaveState 的时候仅仅只保存的是 State并且 FSaveStateLevel 应该是 1.

InstantObject的主键之一,这里InstantObject是定死了的——Guid字符串(长度为30)。用户可以重载 TInstantObject.GetID and SetID 使用自己的ID。

InstanObjects 2.0 可以改变OID(Object)的类型了, 并且可以将model保存在xml文件中。

GetCaption方法,Caption 将是 TInstantObject.ID.

 

Instant Objects 中被称为属性(Attribute),它的基类是 TInstantAttribute,

属性有如下的类型:

TInstantInteger, TInstantFloat, TInstantBoolean, TInstantString, TInstantDateTime, TInstantBlob, TInstantMemo, 它们都是从 TInstantAttribute 类直接派生。

TInstantComplex 派生. The ancestor of all the attribute classes that represent objects. TInstantComplex is the ancestor of all the attribute classes that represents objects. TInstantComplex introduces common properties and methods to:

  • Validate objects.
  • Specificy a connector for a database connection
  • TInstantComplex is abstract; so do not create instances of this class. Instead refer to the following concrete descendant classes:

TInstantParts represents a part relationship to multiple object. TInstantParts mainly implements functionality that has been introduced by its abstract ancestors. TInstantParts claims responsibility of an object that is added to its array of objects. This means that even though the reference to a particular object has been created independently of the parts attribute, it is taken over and eventually destroyed by the parts attribute if the object is added to the parts attributes array of objects.

If the parts attribute is owned, the owner of the parts attribute will become the owner of the part object. When a part object is changed it notifies its owner.

Part Objects are retrieved from the database when their owning object is retrieved.

Note: Objects that serve as parts should be considered as integrated, replaceable entities of their owner. An object can participate in only one part relationship at the time. If the owner object is stored, disposed or refreshed, it is supposed cascade the store, dispose or refresh operation to its part objects.

TInstantParts is derived from TInstantContainer.

TInstantPart represents a part relationship to a single object. TInstantPart mainly implements functionality that has been introduced by its abstract ancestors. TInstantPart claims responsibility of an object that is set as its Value. This means that even though the reference to a particular object has been created independently of the part attribute, it is taken over and eventually destroyed by the part attribute if the object is set as the Value of the part attribute.

When attempting to get an unassigned Value of a part attribute, an instance of the class type specified by the RequiredClass property is created and returned by the part attribute. This implies that the Value of a part attribute is always assigned.

If the part attribute is owned, the owner of the part attribute will become the owner of the part object. When a part object is changed it notifies its owner.

Part Objects are retrieved from the database when their owning object is retrieved.

Note: Objects that serve as parts should be considered as integrated, replaceable entities of their owner. An object can participate in only one part relationship at the time. If the owner object is stored, disposed or refreshed, it is supposed cascade the store, dispose or refresh operation to its part objects.

TInstantReferences 属性存放在数据库中的内容为: ObjectClassName, ObjectId 的列表。详见: TInstantObjectReference.WriteAsObject。换句话说,在 文章Instant Objects 中的引用表不是采用的ParentID指针的形式,而是直接在父亲上存放所有的儿子的信息指针。举例说明:

Parents table
  Class ID Name Childs
  The Childs attribute is a TInstantReferences.
Childs table
  Class ID Name Owner
  The Owner attribute is a TInstantReference point to a Parent.
注:
  1.在主表删除儿子的记录,只是删除在主表中的儿子指针,不会删除从表中的相关记录。
  2.当主表处于浏览状态时,修改从表数据,虽然从表的数据指针会添加到主表的对象上,但是却不会自动Post到数据库.
    这样做的结果有好有坏, 坏处是修改从表数据不能直接生效;好处是可以自己控制修改内容是否生效,如果决定让它生效
    可以使用 TInstantCustomExposer.PostChanges 一次性投递修改的内容。不过值得注意的是在默认参数的情况下,
    对于 References 的内容,从表数据一旦修改就会立即生效——在从表中会多出一些无主的数据(主表不Post的情况下)。
    你应该将从表参数 TInstantCustomExposer.Options 中的 eoAutoApply 设置为 False 就不会自动更新从表了。
  3.TInstantCustomExposer.PostChanges 只能post当前表的当前记录!不会更新关联子表的内容。
  4.TInstantCustomExposer.ApplyChanges 将post当前表的所有修改记录!但不会更新关联子表的内容。
以上[bug]我基本已经改正,只是对于删除操作如果从表不是eo AutoApply,那么从表中的数据不会被删除,所删除的仅仅是主表中的指针。

如果想在子表中,同时指明自己的父亲(在子表存在Parent字段),该如何?应当在主表添加儿子的时候,联系Parent字段. 可以重载 TInstantObject.BeforeContentChange 方法实现在添加删除儿子前事先通知,你可以在这里联系parent字段或当儿子在主表被删除的同时删除子表中的记录。

TInstantReferences represents a reference relationship to multiple objects. TInstantReference mainly implements functionality that has been introduced by its abstract ancestors.

TInstantReferences takes its own reference to an object that is added to its array of objects. This means that an object that has been created independently of the references attribute should also be destroyed independently of the references attribute even though it has been added to its array of objects.

Reference relationships may be heterogeneous. This means that an object may reference objects that are stored in another database. The Connector property of TInstantReferences is therefore writeable. To enable this distributed behavior the Connector property should simply be assigned to a Connector object that connects to the right database.

Referenced objects are retrieved on demand. This means that the references attribute will not retrieve the objects it references until they are required individually. If a references attribute references a non-existing object, the position the object occupies in the attributes array of objects will be nil.

Note: Referenced Objects should be considered as loosely coupled entities of other objects. No ownership is claimed by the object that defines the reference relationship. This implies that an object can participate in as many reference relationships, as it is required. Referenced objects are neither stored, disposed nor refreshed by the objects they are referenced by. If an object is owned, it cannot participate in a reference relationship.

TInstantReferences is derived from TInstantContainer.

InstantElement is the ancestor of attribute classes that represent a relationship with a single object.

TInstantElement = class(TInstantComplex)

InstantElement is the ancestor of attribute classes that represent a relationship with a single object. TInstantElement introduces common properties and methods to:

  • Load and Save the object it represents from and to a stream.

TInstantElement is abstract; so do not create instances of this class. Instead refer to the following concrete descendant classes:

Element attribute classes
TInstantPart
TInstantReference

FiledOptions 包含 foObjects, 否则 Reference属性不会包含在字段列表(只有它的下属字段).

    DataField = 'Category'
    DataSource = SubjectSource
    KeyField = 'Self'
    ListField = 'Name'
    ListSource = MainDataModule.CategorySource
TInstantReference represents a reference relationship to a single object. Although TInstantReference introduces properties and methods that can be used to reference objects, it mainly implements functionality that has been introduced by its abstract ancestors.

TInstantReference takes its own reference to an object that is set as its Value. This means that an object that has been created independently of the reference attribute should also be destroyed independently of the reference attribute even though it has been set as its Value.

The Value of a reference attribute may be unassigned.

Reference relationships may be heterogeneous. This means that an object may reference objects that are stored in another database. The Connector property of TInstantReference is therefore writeable. To enable this distributed behavior the Connector property should simply be assigned to a Connector object that connects to the right database.

Referenced objects are retrieved on demand. This means that the reference attribute will not retrieve the object it references until it is required. If a reference attribute references a non-existing object its Value property is nil.

Note: Referenced Objects should be considered as loosely coupled entities of other objects. No ownership is claimed by the object that defines the reference relationship. This implies that an object can participate in as many reference relationships, as it is required. Referenced objects are neither stored, disposed nor refreshed by the objects they are referenced by. If an object is owned, it cannot participate in a reference relationship.

TInstantExposer 一般不能单独在数据表中使用, 可以在编辑某记录项(Object)时或主从表中的从表中使用.

TInstantExposer is a dataset component that maps objects to the user interface of your application. Attributes defined in the business model are accessed through properties. Properties that are published can be accessed by data-aware controls via this component. In addition, the content of container attributes can be accessed too. The exposer component maps the published properties of objects to fields in a dataset. The objects being exposed are represented as rows in the dataset.

To expose an object, it must be assigned to the Subject property of a TInstantExposer. To expose multiple objects contained within another object, assign the main object to the Subject property and enter content mode by changing the Mode property from amObject to amContent. If the exposed class has no default container, specify the desired container in the property ContainerName. Specify the class of the exposed object(s) in the property ObjectClassName. By default, an exposer will make all simple properties of each exposed object as well as any related object available through fields in the dataset. Every field will have a fieldname matching the property it represents. For related objects, the fieldname will be the complete path to the property using regular dot notation. The property FieldOptions and the event OnIncludeField allow you to limit or extend the number fields to include.

Container attributes of exposed objects are automatically recognized by the exposer and represented as nested datasets within the exposer. Exposers can be linked together in master/detail relations. To link one exposer to another, assign the master exposer to the DataSet property of a TDataSource and assign the TDataSource to the MasterSource property of the detail exposer. The Subject of the detail exposer will be set to the current object of the master exposer, whenever this changes. If you want the detail exposer to expose an object that is related to the current object of the master exposer instead, simply specify the desired property path in MasterProperty.

TInstantExposer is not limited to exposing TInstantObject descendants. Any object with published propertied can be exposed. The content of standard VCL containers like TList, TObjectList and TCollection can be exposed in content mode.

Instant Objects 中的Query元件。一般我们使用它来联系数据控件和商务对象(BO)。

在 Where 子句中, 对Object的比较可以使用 Object.ID 来进行:

  SQL := 'Select * From TCompany Where Self <> "' + aCompany.Id + '"';
The TInstantSelector component allows you to select objects from the database and optionally expose them in the user interface. To select objects from the database, a command must be specified with the Command property. The syntax of this command is somewhat similar to an SQL SELECT-statement, but instead of tables and columns, you specify classes and attributes:
SELECT [DISTINCT] *|<Attribute>
FROM [ANY] <Class>
[WHERE <Expression>]
[ORDER BY <Attribute list>]

The simplest command that can be specified looks like this:

SELECT * FROM TContact

This command would select all concrete instances of the class TContact. To select instances of TContact and any descendant class, add the ANY keyword:

SELECT * FROM ANY Tcontact

If you want to select objects that are related to instances of a class, specify the relation attribute instead of the star, like this:

SELECT Address FROM ANY Tcontact

If the same object is related to from several objects via the specified attribute and you do not want it to appear more than once in the result, use the DISTINCT keyword with the attribute:

SELECT DISTINCT Address FROM ANY Tcontact

To select from objects that meet a certain criteria, you must add a WHERE clause to the command. This clause must contain an expression that evaluates to True or False. The expression can use attributes, constants and functions in combination with the most common operators. The following example will select all customers with a negative balance.

SELECT * FROM TCustomer WHERE Balance < 0

To order the selected objects by one or more attributes, specify the attributes with ORDER BY:

SELECT * FROM TCustomer ORDER BY Balance, Name

For an in-depth explanation of the Command property, please consult the 文章Instant Objects Reference Guide. When the selector is opened, it performs a query against the database. The resulting objects are available via the Objects property. The number of objects selected can be read via the property ObjectCount. If you want to expose the selected objects in the user interface, simply assign the selector to a TDataSource that is attached to data-aware controls.

TInstantSelector exposes a selection of objects. The objects are selected by the means of a Command statement. The selector is independent of the kind of database from which the selection is to be made. The syntax of the Command statement is therefore also database independent. When peforming the selection, the Command statement is parsed and translated to a statement that is understandable by the database to which the selector is connected through its Connector property.

The selection of objects may be modified by adding or removing objects to and from the selector components array of objects.

 

 

SQL 与 Selector

Selector 是 文章

 

InstantPresentation

 

DataSet 与 Exposer

 

TInstantReference
如果要 Lookup Reference 属性, 必须设置 Exposer.

 

TInstantElement

 

TInstantReferences

 

TInstantPart
将一个对象嵌入到字段中.

 

TInstantParts
将多个对象嵌入到字段中.

 

复杂类型
它们都是从

 

简单类型

 

字段和属性

数据表中的字段在 文章

 

Caption
是该对象的文本标题,如果用户没有重载

 

ID
ID 是

 

事务机制
参与事务的对象在

 

数据表 与 TInstantObject

文章

 

InstantPersistence

 

数据库 与 Connector

所有的 Connector 都是从
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值