Please refer to -- data access layer (1)

Source: Internet
Author: User

Before posting this essay, I hesitated for a long time. Do you want to put this essay on the home page? As a rookie essay, it is not suitable for the home page, this article may soon sink, so I have the courage to put it on the homepage...

This essay was written mainly because I encountered a problem when I was working on the data access layer. I consulted others in the blog community and got enthusiastic help from everyone, however, the messages on QQ are much faster than those on blogs, so I want to put them on the blog garden ..... don't talk about it. Let's get into the question.

Now we want to create a simple video website where Administrators, Users, video categories, videos, administrators, and users can upload videos and comment on videos.

My intentions: In this essay, let alone the business logic layer and performance layer to view the website'sData access layerI want to enable this Dal layer to achieve database independence and better meet the object-oriented design philosophy. I am doing more to learn, so I don't want to use some ready-made things, I hope I can improve it slowly and exercise myself in the improvement process.

Below is my Dal class diagram:

Description: Idatabase is an interface that defines some methods for executing SQL statements or stored procedures. Only three methods are marked. sqlserver and Oracle are two specific databases to implement the idatabase interface, idal is an interface for managing video, user, admin, and comment. The createdb () method reads the database type from the configuration file, then, the reflection is used to create and return the specific database (sqlserver class or Oracle class). Other methods use the database class returned by createdb () to execute the corresponding SQL statements or stored procedures, getcount () is the total number of returned objects (such as the total number of videos and the total number of users). getitem (int id) uses the ID of the object (which is the primary key in the database) the returned object (for example, getitem (int id) in videodal returns the video object through the video ID in the database). getlist is the list of returned objects (such as videolist, user List), getpagedlistorderbypk (INT startrow, int maxrows, sorttype) also returns a list, but it is the list of objects that should be displayed on the current page during pagination, startrow and maxrows are the starting line number of the page and the maximum number of records retrieved (which can be considered as page size). The method body interacts with the database and extracts data. sorttype is an enumeration, there are two values, ASC and DESC, which represent the sorting rules. The results are sorted by the primary key.

The following are the Business Objects (I don't know if there is a problem, because they only map the corresponding table fields of the database, but only have two or three more attributes)

In the user class, video class, etc., all fields of the corresponding table in the database (the database contains admin, user, video, videosort, and comment tables, the user class has the videos and comments attributes, indicating the list of videos uploaded by a user and the list of all posted comments. Other classes also have similar attributes.

all I can think of now is this, but I know that there are many problems, but I am comparing dishes horizontally and do not know how to improve them, so I am so bold to put it on the homepage, hoping to get your advice. You can rest assured that you don't have to worry about hurting your self-esteem. OK, come on ..

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.