First, 3 packages are built under the project, namely: Core,utils,bean
Core
Query interface
PackageCom.yf.sorm.core;Importjava.util.List;/*** Responsible for enquiry (core category of external service) *@authorYANGF **/ Public InterfaceQuery {/*** Execute a DML statement directly *@paramSQL SQL statements *@paramparams parameter *@returnnumber of rows affecting the record after executing the SQL statement*/ Public intexecutedml (String sql, object[] params); /*** Store An object in the database *@paramobj objects to store*/ Public voidInsert (Object obj); /*** * Delete Clazz represents the record in the table corresponding to the class (specifies the record of the primary key value ID) *@paramClazz class object with table corresponding to *@paramthe value of the ID primary key*/ Public voidDelete (class<?> clazz,intID); /*** The corresponding record of the output object in the database (the class table in which the object resides, the corresponding record of the object's primary key value) *@paramobj Object*/ Public voidDelete (Object obj); /*** Update the record for the object, and update only the value of the specified field *@paramobject to be updated by obj *@paramField Updated Property list *@returnnumber of rows affecting the record after executing the SQL statement*/ Public intUpdate (Object obj, string[] field); /*** The query returns multiple rows of records and encapsulates each row of records into an object of the class specified by Clazz *@paramSQL query statement *@paramClazz Class object for JavaBean classes that encapsulate data *@paramParams SQL parameters *@returnthe results of the query*/ Public<T> list<t> queryrows (String sql, class<?>Clazz, object[] params); /*** The query returns a row of records and encapsulates the record into an object of the class specified by Clazz *@paramSQL query statement *@paramClazz Class object for JavaBean classes that encapsulate data *@paramParams SQL parameters *@returnthe results of the query*/ Public<T> T Queryuniquerow (String sql, class<?>Clazz, object[] params); /*** The query returns a value (one column in a row) and returns the value *@paramSQL query statement *@paramparams SQL parameter *@returnthe results of the query*/ Public<T>T queryvalue (String sql, object[] params); /*** The query returns a number (one column in a row) and returns the value *@paramSQL query statement *@paramParams SQL parameters *@returnnumber of queries to*/ PublicNumber querynumber (String sql, object[] params);}
Typeconvertor interface
PackageCom.yf.sorm.core;/*** Responsible for converting between Java data types and database data types *@authorYANGF **/ Public InterfaceTypeconvertor {/*** Convert Database data type to Java data type *@paramcolumntype Data type of database field *@returndata types for Java*/ Publicstring Databasetypetojavatype (string columntype); /*** Convert Java data type to database data type *@paramjavadatatype Java Data type *@returnDatabase Data Type*/ Publicstring Javatypetodatabasetype (string javadatatype);}
Bean:
Columninfo class
PackageCom.yf.sorm.bean;/*** Encapsulate information for a field in the table *@authorYANGF **/ Public classColumninfo {/*** Field name*/ PrivateString name; /*** Data type of the field*/ PrivateString DataType; /*** Field Key type (0: Normal key, 1: Primary key, 2: foreign key)*/ Private intKeyType; /*** Empty Constructor*/ PublicColumninfo () {}/*** constructor *@paramName field names *@paramdataType data type of field *@paramthe key type of the KeyType field*/ PublicColumninfo (string name, String DataType,intKeyType) { Super(); This. Name =name; This. DataType =DataType; This. KeyType =KeyType; } /*** Return field name *@returnField name*/ PublicString GetName () {returnname; } /*** SET field name *@paramName field names*/ Public voidsetName (String name) { This. Name =name; } /*** Returns the data type of the field *@returnthe data type of the field*/ PublicString Getdatatype () {returnDataType; } /*** Set the data type of the field *@paramdataType The data type of the field*/ Public voidSetdatatype (String dataType) { This. DataType =DataType; } /*** Returns the key type of the field *@returnthe key type of the field*/ Public intGetkeytype () {returnKeyType; } /*** Set the key type of the field *@paramthe key type of the KeyType field*/ Public voidSetkeytype (intKeyType) { This. KeyType =KeyType; }}
Tableinfo:
PackageCom.yf.sorm.bean;ImportJava.util.Map;/*** Information on storage table structure *@authorYANGF **/ Public classTableinfo {/*** Table name*/ PrivateString Tname; /*** Information for all fields key: Field name*/ PrivateMap<string, columninfo>colums; /*** Unique PRIMARY key, this framework only supports cases where there is only one primary key in the table*/ PrivateColumninfo Onlyprikey; /*** Empty Constructor*/ PublicTableinfo () {}/*** constructor *@paramtname Table name *@paramcolums information for all fields *@paramonlyprikey Unique PRIMARY key*/ PublicTableinfo (String tname, map<string, columninfo>colums, Columninfo Onlyprikey) { Super(); Tname=Tname; This. colums =colums; This. Onlyprikey =Onlyprikey; } /*** Return table name *@returnTable name*/ PublicString Gettname () {returnTname; } /*** Set Table name *@paramtname Table name*/ Public voidsettname (String tname) {tname=Tname; } /*** Return information for all fields *@returninformation for all fields*/ PublicMap<string, columninfo>getcolums () {returncolums; } /*** Set information for all fields *@paramcolums information for all fields*/ Public voidSetcolums (map<string, columninfo>colums) { This. colums =colums; } /*** Return unique PRIMARY key *@returnUnique PRIMARY Key*/ Publiccolumninfo Getonlyprikey () {returnOnlyprikey; } /*** Set Unique PRIMARY key *@paramonlyprikey Unique PRIMARY key*/ Public voidSetonlyprikey (Columninfo onlyprikey) { This. Onlyprikey =Onlyprikey; }}
Design of Sorm (Simple object relation mapping) frame interface