SmartPersistencelayer design function articles
The lasting layer SmartPersistencelayer is simply referred to as SPL, and the current version is 2.0.
Persistent layer concept
Data layer transparent
At present, everyone can find several kinds of persistence layers. In fact, the ideas of each lasting layer are the same, but in the implementation method, there are also some details of the details, and each lasting layer has a uniqueness or It is inadequate, this is a development process, SPL is no exception, I also hope that there is a friend to ask questions, which can make the lasting layer more perfect.
The persistence layer (below I instead of the persistence layer) is a low-level platform for system development, all related database operations are implemented by PL, using the O / R mapping to separate the business objects with the database, because of ideology From the perspective, business logic itself should not have too many constraints, and business logic is ever-changing, then business logic should not be treated by the database, so what kind of database (SQL Server, Oracle, etc.) is used. Looking at the business logic level, it is a database, as long as the functionality of the relational database can be implemented.
Therefore, the most fundamental feature of PL is to use business logic to separate the data layer, so that the system is transparent to the database.
SPL currently supports SQL Server, Access, Oracle, SPL automatically generates SQLConnection, and other databases are connected to OLEDBCONNECTION. This is also a way of MS recommended.
Entity mapping
In the ORM principle, we can understand that in order to make business logic development and database can have this corresponding relationship, use Object Relational mapping, that is, "Entity Entity" is defined in the business system, then implements Entity through an XML file. Maps with Table, then the operation of Entity in the business system, through the PL and XML mapping to complete real database access.
Entity in the SPL is different from other PLs. SPL uses inheritance Objectentity to implement the Entity itself to add deletion modification, this implementation is more objective, and it is more important to the system development station on the OO level, current SPL is available in SPL Entity's Retrieve, Save, delete (delete) function. In these operations, the developer really senses object-oriented development, transparent to the data layer, does not require any SQL statement to implement multi-database operations.
This will solve the slow development speed of SQL writing, complex statement debugging, easy error, and poor expansion.
Relational mapping
From ORM, in addition to the entity, there is a relational feature, which is the relationship between the Database and Entity to implement a table relationship in the database. This kindal has a considerable complexity, and some PLs on the network also realize the relational, which should be a better start, and the specific function and effect I have not paid.
Due to this complexity, the SPL currently removes the RELATIONAL function, I need more time to consider how to develop system development to relativeal more convenient.
It may also be in this regard, so that SPL is easy to get started by other PLs, it is easy to understand.
SPL feature
Based on the completion of the above entity, SPL adds some features, I briefly introduce first, which will be released in subsequent documents.
Standard criteria
Criteria refers to the standard. The current SPL is divided into RetrieVecriteria (Get Standard), Updatecriteria (Update), Deletecriteria (deleted), which is also operated for an entity. RetrieveCrietria (Get Standard)
Advanced queries can be performed by RetrieveCriteria, such as defining query conditions, defining sorting methods, etc., give a simple example:
There is currently a studententity entity, to implement "Query all the students who surname Liu, sort with a student number:"
Retrievecriteria Rc = New RetrieVecriteria (TypeEnTentity); // Installation
Condition c = rc.getnewcondition (); // Create a condition
C.addMatchPerfix (studententity.name, 'Liu'); // This will generate Name Like 'Liu%' inquiry
Rc.Orderby (studEntentity.no); // This generates Order by no
DataTable DT = rc.ASDataTable (); // This is returned in a DATATABLE
About the Condition class will be explained later, RetrieveCriteria provides a variety of return modes, which makes it easy to operate the return result. If it is data binding, it returns directly; if it is to operate, use the ASENTITYCONTAINER mode to return Entity Collection.
Updatecriteria (Update) and Deletecriteria (Delete Standard)
Updatecriteria is a statement that generates Update Table Set Name = 'XX' Where ....
Deletecriteria is a statement that produces delete from table where ...
Using the way is similar to RetrieveCriteria, will be explained in detail in later documents.
Transaction processing
Transaction processing may be the most frequently used in system development, and transaction processing in the SPL is quite simple, and those operations described earlier can be processed by transaction:
NEW TRANSACTION ();
T. AddsaveObject (Objectentity)
Add Entity Save to Transactions, Automatically judge Insert and Update according to Entity's ISPERSISTENCE
T.adddeleteObject (Objectentity)
Add Entity Delete to the transaction
T.adDDeletecriteria (Deletecriteria)
Add Delete Standard to Transaction
T.addupdatecriteria (Updatecriteria)
Add update standards to transactions
T.Addsqlstring (Sqlstring, DB)
Add SQL execution statements to transactions
T.Process ()
Perform a transaction, if you encounter an error, the transaction all rollback.
Query Advanced Query
Query is a powerful query class that can be combined between Entity, or some static database operations in Query.
Query's joint query function currently supports the inner connection, no left join, because the query itself is a most complicated thing, so in my design, I usually use a view to make a joint query.
Query. ProcessSQL (Sqlstring, "DB")
Static execution SQL statement, can be processed using this SQL statement for some features that SPL unable
Query also supports simple summary queries, and the specific functions are explained in future documents to support automatic growth fields.
Automatically grow field, do not need to indicate in the SPL, automatically perform value, and return to the system entity to make subsequent processing, for example, after adding the order master, return the ID to Entity To be used when ordering is preserved for orders.
Dynamic data source configuration
By default, the data source will be read from the XML configuration file, and the system also provides a data source connection using code direct ADD.
Multi-book support
A multi-replete set in a large system is also some exactly the same table entity, but the data source is different. This kind of mesh is called a multi-book, and the SPL supports multiple accounts, which is all the operations. Manually set DatabaseName in the system, which will be updated to different databases.
Memory storage
This feature should be the only one in the domestic market.
For some maintenance-type data, due to small data volume, less field, low maintenance frequency, high usage, in order to improve the overall performance of the system, these data can be saved in memory, reducing the database access, SPL to use this The function is very simple, as long as you want to declare entity, specify "issavetomeMory = true", so that SPL will be saved to memory after the first acquisition, and later reads will automatically get from memory, this Entity update For example, Insert, Update, delete, etc., will automatically update to memory according to IssaveTomemory, that is, for the developer, this feature is completely transparent. Second: The memory storage is also supported by multi-books, that is, the same entity, if it is obtained from different databases, generate two memory recovery, and later read and modifications are also with their own accounts. Quasi.
I briefly introduced a SPL design start point and function point. Detailed introduction I will post a document later.
I hope that friends who are interested can make comments on SPL so that SPL can be more perfect.
Listen to
November 2004
MSN: TINTOWN_LIU@hotmail.com