Datarabbit lightweight data access framework (09) -- idataschemaaccesser

Source: Internet
Author: User
(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.