(Fully qualified class name: Datarabbit. schema. idataschemaaccesser )
In the implementation of many accessors described earlier, users do not need to provide any information about the database table structure (such as primary keys and primary-foreign key relationships ), this is because they all use idataschemaaccesser to obtain the outline information of the target data table. This article describes how to use idataschemaaccesser in the datarabbit framework to access and operate the outline of the data table.
We can obtain idataschemaaccesser reference from idataaccesser, the entry point of datarabbit:
IdataschemaaccesserDataschemaaccesser = Dataaccesser. getdataschemaaccesser (null) ;
Note that idataschemaaccesser is also obtained using a get method, just like obtaining various accessors described earlier.
Idataschemaaccesser provides two functions: Obtain the outline information of a specified table, and create a new data table based on the outline information. The complete definition of idataschemaaccesser is as follows: Public Interface Idataschemaaccesser: itransactionaccesser
{
/// <Summary>
/// Revoke ache clears the cache Schema
/// </Summary>
Void Revoke AchE ();
/// <Summary>
///Getdataschema: Get the data outline of the target table
/// </Summary>
DataschemaGetdataschema (StringTable );
/// <Summary>
/// Createtable creates a table with the same outline and schema in the database.
/// </Summary>
Void Createtable ( String Table,DataschemaSchema, Bool Createfkeys );
}
Through interface definition, we can see that it also inherits the itransactionaccesser interface, which indicates that idataschemaaccesser can work in a non-transaction or transaction environment.
Use datarabbitDataschemaTo encapsulate the outline information of a data table.ColumnschemaAnd nForeignkeyIs as follows:
ColumnschemaIt encapsulates the outline information of a data column, including the column name, column type, whether it is a primary key, whether it is an auto-incrementing column, whether it is allowed to be blank, remarks, and the maximum length.
ForeignkeyIt encapsulates a foreign key information of the current data table, including the foreign key column name, the name of the primary table, and the corresponding primary key name of the primary table.
In addition,DataschemaA property named primarykey is also provided to mark the primary key of the current table. It can represent a single primary key or a joint primary key.
Finally, we provide an example to demonstrate how to create a student table in Oracle. The structure of this table is the same as that of the student table in sqlserver.
IdataaccesserDataaccessertosqlserver = ... ; // Create idataaccesser through dataaccesserfactory
IdataaccesserDataaccessertooracle = ... ; // Create idataaccesser through dataaccesserfactory
DataschemaStudentschema = Dataaccessertosqlserver. getdataschemaaccesser (null ).
Getdataschema( " Student " );
Dataaccessertooracle. getdataschemaaccesser (null ).
Createtable( " Student " , Studentschema, False );
Go to: datarabbit lightweight data access framework-Sequence