Database operation (1.0.0.1) (continued)

zhaozj2021-02-16  62

Profile Datamodel.xml

Select * from bank_library where bank_id = @BankID

Select * from bank_library where bank_id = 1

SELECT * ACCOUNT

Description:

1. DataModel: Root point.

2. Command: Command contact, represents a SQL command statement; ID command number, used to numbered the command, the program will not be used in the program; the name of the name command is called by this name; Type command type, there are two Values ​​(Command, Produce), representing a SQL statement or a stored procedure.

3. CommandString: The name of the SQL statement or stored procedure of the command can be filled in the SQL statement that can be run in the query analyzer.

4. Param: Parameter node, each node represents a parameter, ID parameter number; Name parameter name, the consistency must be referenced in the above node; the default value of the default parameter; the data type of the TYPE parameter; Data length; these attributes should be consistent with fields in the database.

Profile TableDefine.xml

< / Column>

Description:

1. TableDefine: root node.

2. Table: Description point represents a database table. Alias ​​table alias, references in the program; the real name of the Name table, and the table names in the database.

3. Column: The column points represent the definition of a column. Alias ​​column alias, reference; Name column's real name, match the column name in the database; DataType column defined by the data type; length column defined by the length; NULLFLAG column is allowed to be empty flag; ForeignKey Foreign key logo; default default; autoAdd self-increment mark.

4. The definition of the table in the database will be imported directly into this configuration file, as for the relationship between the table and the table, I will add it later.

IDBase interface

This interface class defines the interface common to the database operation. All database operation classes implemented for different databases should follow this interface, and the factory (FACTORY) mode is applied, so that the upper layer is called, it is not necessary to consider the following Specific database engine. Current: SQL query statement is the order in which the parameters in the parameter array in the parameter array is consistent in the order of the parameters in the configuration file DATAMODEL.XML.

I will further modify and automatically generate simple query statements without writing XML files in advance.

String getsingle (String Sqlstr, String [] VALS);

Hashtable getsinglerow (String Sqlstr, String [] VALS);

ArrayList getMultirow (String Sqlstr, String [] VALS);

Void CreateItem (String ItemName, String [] ColsValueArray;

Void Modify (String ItemId, String "COLSNAMEARRY, STRING [] ColSValueArray;

Void deleteItem (String ItemName);

* GetSingle (): According to the name of the transferred database (defined in the configuration file), the parameter array, retrieves a single value of a string type, such as: Depending on the user name to take the user's address.

* GetSinglerow (): According to the name of the recorded database (defined in the configuration file), the parameter array, retrieves multiple columns in the database table, the result is stored in the HashTable according to the corresponding relationship of the field name, value, convenient Use. For example, according to the user's name, the user's information is removed. When there are multiple rows return, take the first line of the data set.

* GetMultirow (): Based on the name of the recorded database (defined in the configuration file), the parameter array, retrieves multiple rows in the database table, and retrieves an array, each element in the array is A HashTable, each HashTable stores a multi-column in the database table. For example, take out all the list of users who were born in 1979, each user exists in a HashTable, and the array contains all user lists of all eligibles.

* CREATETEM (): According to the passing table name, to insert the value of the table, generate an Insert statement, execute the database insertion operation. Note: Indicates an alias, defined in the configuration file, is not a real database table name, there is a hidden relationship in the middle, which ensures that the program is required without changing the program without changing the database table name. The column name is also the same; in addition, the value to be inserted must be consistent with the sequence defined in the configuration file TableDefine.xml, otherwise the generated statement will be wrong. For example: insert a new user into the user table.

* ModifyItem (): According to the passive table name, the value of the primary key, to modify the field array, the value group, where the field array and value array must correspond one, and then automatically generate the UPDATE statement. For example: according to user name, modify the user's address, phone.

* DeleteItem (): Automatically generates the DELETE statement based on the values ​​of the passing table name, the value of the primary key. For example: delete user information according to username. SQLDBase class

The IDBASE interface, the implementation of the public method is consistent with the interface class described above, which is worth explanating that this class provides two constructors.

Public SqldBase (String Conname)

Public SqldBase ()

Using the default database, you can use the second constructor. If other database connections are used, the name of the database connection in the first constructor, the parameter, and the configuration file systemconfig.xml should be used to refer to different connections.

DBASEFActory class

This is a factory class that realizes the factory model. It is designed to operate the database operation class that does not need to be used for the above-level call, depending on the settings in the configuration file.

Public static idbase getDBaseUtility ()

Public Static IDBase GetDBaseUtility (String Conname)

{

Idbase mydbaseutil = null;

IF (constant.data_base.equals ("SQLServer2000"))

{

mydbaseutil = new sqldbase (conname);

}

Return mydbaseutil;

}

The two methods are basically consistent, and the parameters are just to indicate which database connection to use.

Factory Factory mode

Returns the corresponding operation class based on the database indicated in the configuration file, here if the database specified in the configuration is "SQLServer2000", returns the SQLDBase class.

Conclude

The introduction of the class associated with the database is here. During writing, I feel that many places have not written clearly. Interested friends should be fully understood, but the source code is not completely completed, etc. I will give it to you later, I hope everyone can see it for the younger brother, thank you.

转载请注明原文地址:https://www.9cbs.com/read-23793.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.056, SQL: 9