Skip to content

cindia3704/WatchIt-DB-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

23 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–ฅWatchIt-DB-Project๐Ÿ–ฅ

This is a project to deal with big data by using appropriate indexes in the database & dynamic queries.
It is a console project implementing functions in OTT(over-the-top) services.
It uses large amount of dummy data created instead of real data used in current OTT services.

๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ DB ๋ฐ Transaction์„ ์„ค๊ณ„ ๋ฐ ๊ตฌํ˜„ํ•œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค.
์ฝ˜์†” ํ”„๋กœ๊ทธ๋žจ์ด๋ฉฐ, ๊ธฐ๋ณธ์ ์ธ OTT ์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ ๊ธฐ๋Šฅ๋“ค์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์„œ๋น„์Šค ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ์œ„ํ•ด ๋Œ€์šฉ๋Ÿ‰ ๋”๋ฏธ ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๐ŸŒฑProject Introduction๐ŸŒฑ

Goal

  • To deal with big data (ex. over 1000000 data) we need to think of a way to effectively process them in the database
  • This could be done by using appropriate indexs in relational databases

Service

  • Login/ Register (๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž…)
  • Buy tickets (์ด์šฉ๊ถŒ ๊ฒฐ์ œ)
  • Multiple profiles per user (ํ•œ ์‚ฌ์šฉ์ž์—๊ฒŒ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ”„๋กœํ•„ ํ• ๋‹น)
  • Show all contents to user (๋ชจ๋“  ์ปจํ…์ธ  ๋ณด์—ฌ์ฃผ๊ธฐ)
  • Show contents by genre (์žฅ๋ฅด๋ณ„ ์ปจํ…์ธ  ๋ณด์—ฌ์ฃผ๊ธฐ)
  • Search contents / See user search history (์ปจํƒ ์ธ  ๊ฒ€์ƒ‰ ๋ฐ ์‚ฌ์šฉ์ž ๊ฒ€์ƒ‰๊ธฐ๋ก ๋ณด๊ธฐ)
  • View content specific information (์ปจํ…์ธ  ์ƒ์„ธ ์ •๋ณด ๋ณด๊ธฐ)
  • Rate content (์ปจํ…์ธ  ๋ณ„์  ์ฃผ๊ธฐ)
  • Add content to my favorites (๋‚ด ์ฐœ ๋ชฉ๋ก์— ์ปจํ…์ธ  ์ถ”๊ฐ€)

๐Ÿ’ปInstallation and Setup๐Ÿ’ป

To begin using this template, choose one of the following options to get started:

To set up the database with pre-defined SQL statements, please refer to the file below:

๐Ÿ“Requirements๐Ÿ“

  • Java Version 11
  • MySQL Version 8.0.23
  • MySQLWorkBench Version 8.0.20

๐Ÿ—‚Project Directories ๐Ÿ—‚

โ”œโ”€โ”€ dao
โ”‚   โ”œโ”€โ”€ ContentCommentDao.java
โ”‚   โ”œโ”€โ”€ ContentDao.java
โ”‚   โ”œโ”€โ”€ MyContentDao.java
โ”‚   โ”œโ”€โ”€ OrdersDao.java
โ”‚   โ”œโ”€โ”€ RatingDao.java
โ”‚   โ”œโ”€โ”€ SearchHistoryDao.java
โ”‚   โ”œโ”€โ”€ TicketDao.java
โ”‚   โ”œโ”€โ”€ UserDao.java
โ”‚   โ””โ”€โ”€ UserProfileDao.java
โ”œโ”€โ”€ entity
โ”‚   โ”œโ”€โ”€ ContentComment.java
โ”‚   โ”œโ”€โ”€ Content.java
โ”‚   โ”œโ”€โ”€ LoggedInUser.java
โ”‚   โ”œโ”€โ”€ MyContent.java
โ”‚   โ”œโ”€โ”€ Orders.java
โ”‚   โ”œโ”€โ”€ Rating.java
โ”‚   โ”œโ”€โ”€ SearchHistory.java
โ”‚   โ”œโ”€โ”€ Ticket.java
โ”‚   โ”œโ”€โ”€ User.java
โ”‚   โ””โ”€โ”€ UserProfile.java
โ”œโ”€โ”€ enums
โ”‚   โ”œโ”€โ”€ ContentGenre.java
โ”‚   โ”œโ”€โ”€ ContentType.java
โ”‚   โ”œโ”€โ”€ RateStatus.java
โ”‚   โ”œโ”€โ”€ TicketType.java
โ”‚   โ””โ”€โ”€ UserStatus.java
โ””โ”€โ”€ Main.java

๐Ÿ“™Project Functions๐Ÿ“™

Image Description
image Welcome page
image Register
image Login
image Choose User Profile
image Buy Ticket
image Main Page
image See Content by Type
Choose content type
image See Content by Type
List of all contents
image See Content by Genre
Choose content genre
image See Content by Genre
List of all contents
image See My Content List
image See Content Detail
image See Search History
image See My Comment List
& Change My Comment

๐Ÿ“ŒERD๐Ÿ“Œ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-08-22 แ„‹แ…ฉแ„’แ…ฎ 4 39 25

โœจConnecting to Databaseโœจ

  • Database is connected by using jdbc
  • To use this code and connect to your local database, change the "USERNAME" & "PASSWORD"
  • You may need to change the URL if your schema name is not "WatchIt"
        Connection conn = null;

        final String USERNAME = "ENTER_YOUR_MYSQL_USERNAME";
        final String PASSWORD = "ENTER_YOUR_MYSQL_PASSWORD";
        final String URL = "jdbc:mysql://localhost:3306/WatchIt?characterEncoding=latin1&useConfigs=maxPerformance";
        try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
        }catch (ClassNotFoundException e){
            e.printStackTrace();
            System.out.println("Class not found!!");
        }catch (SQLException e){
            e.printStackTrace();
            System.out.println("Connection failed!!");
        }

๐Ÿ“ŠCreating Big Data Example๐Ÿ“Š

1. Create a method making dynamic SQL statements
โžก๏ธ Use PreparedStatement to create dynamic queries & use set methods to insert data for each property

  public static void insertComments(ContentComment contentComment, Connection conn) throws SQLException {
        String sqlStmt = "insert into content_comment values(?,?,?,?);";
        PreparedStatement pStmt = null;
        try{
            pStmt = conn.prepareStatement(sqlStmt);
            pStmt.setInt(1,contentComment.getId());
            pStmt.setString(2,contentComment.getComment());
            pStmt.setInt(3,contentComment.getUserProfileId());
            pStmt.setInt(4,contentComment.getContentId());
            pStmt.executeUpdate();
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            pStmt.close();
        }
    }

2. Create method for making Entities
3. Call the method made in (1) and provide entity made in (2) & connection instance parameters

  private static void makeRandomContents() throws SQLException {
        for(int i =1;i<=5;i++){
            ContentDao contentDao = new ContentDao();
            Content content = new Content();
            content.setId(i);
            content.setContentType(getContentType(getRandomIndex(0,4)));
            content.setContentGenre(getContentGenre(getRandomIndex(0,12)));
            content.setTitle(getRandomString(5,10));
            content.setYear(getRandomIndex(1980,2022));
            content.setDescription(getRandomString(30,300));
            content.setPoster("https://watchIt.com/"+getRandomString(5,20)+".jpg");
            content.setVideo("https://watchIt.com/"+getRandomString(5,20)+".mp4");
            content.setTotalRateScore(getRandomDouble(0.0,5.0));
            content.setAgeLimit(getRandomIndex(0,20));
            contentDao.insertContent(content);
        }
    }

Result
โžก๏ธ 100000 data created in database image

Creating Indexs

  • Function: Showing all contents by type
    • Index needed in Content table
    • SQL statement for creating index:
      CREATE INDEX idx_type_content ON WatchIt.content(type);

image

  • Function: Showing contents in user's my content list that the user didn't rate
    • Index needed in MyContent table
    • SQL statement for creating index:
      CREATE INDEX idx_profile_id_rating_status ON WatchIt.my_content(user_profile_id,rating_status);
  • Function: Change rate status of a certain content in my content list
    • Index needed in MyContent table
    • SQL statement for creating index:
      CREATE INDEX dx_profile_content ON WatchIt.my_content(user_profile_id,content_id);

image

Transaction Example

  • Function:
    • Update user ticket payment & status when "INACTIVE" user logged in
    • ์‚ฌ์šฉ์ž ๋กœ๊ทธ์ธ ์‹œ ์‚ฌ์šฉ์ž๊ฐ€ ๋น„ํ™œ์„ฑํ™” ๋œ ์‚ฌ์šฉ์ž์˜ ์ด์šฉ๊ถŒ ๊ตฌ๋งค ๋ฐ status ์—…๋ฐ์ดํŠธ
  • SQL statements in transaction:
    • S1-1 :

            SELECT * FROM user WHERE username = ? and password = ? ;
    • S1-1 Explanation:

      • Check if user with username & password exists
      • ํšŒ์›๊ฐ€์ž… ๋œ ์‚ฌ์šฉ์ž ์ค‘, ์‚ฌ์šฉ์ž ์ž…๋ ฅ์œผ๋กœ ๋“ค์–ด์˜จ username & password๋ฅผ ๊ฐ–๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ ํ›„ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ์‚ฌ์šฉ์ž ์กฐํšŒ
    • S1-2:

        SELECT * FROM ticket;  ( ์ •์  SQL ) 
    • S1-2 Explanation:

      • If user status is INACTIVE, redirect to payment page & show all ticket types
      • ์‚ฌ์šฉ์ž๊ฐ€ ๋น„ํ™œ์„ฑํ™” ๋œ ์‚ฌ์šฉ์ž์ธ ๊ฒฝ์šฐ ์ด์šฉ์› ๊ตฌ๋งค ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜์—ฌ ์ด์šฉ๊ถŒ์„ ๋ชจ๋‘ ๋ณด์—ฌ์คŒ
    • S1-3:

        SELECT MAX( id ) as total FROM orders;
    • S1-3 Explanation:

      • If user bought a new ticket, get max id from order table
      • ์‚ฌ์šฉ์ž๊ฐ€ ์ด์šฉ๊ถŒ์„ ๊ตฌ๋งคํ•˜๋ฉด orders ํ…Œ์ด๋ธ”์— ๋ ˆ์ฝ”๋“œ๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด์•ผ ํ•˜๋Š”๋ฐ ์ด๋•Œ id๊ฐ’ ์„ค์ •์„ ์œ„ํ•ด ํ˜„์žฌ orders ํ…Œ์ด๋ธ”์— ๋ ˆ์ฝ”๋“œ ์ค‘ id ์นผ๋Ÿผ์˜ ์ตœ๋Œ€๊ฐ’์„ ์กฐํšŒํ•˜์—ฌ ์ด๋ณด๋‹ค 1๋งŒํผ ํฐ ์ˆ˜๋ฅผ ์ƒˆ ๋ ˆ์ฝ”๋“œ์˜ id ๊ฐ’์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
    • S1-4:

        INSERT INTO orders values(?,?,?,?,?);
    • S1-4 Explanation:

      • If user bought a new ticket, add a record in order table
      • ์‚ฌ์šฉ์ž๊ฐ€ ์ƒˆ ์ด์šฉ๊ถŒ์„ ๊ตฌ๋งคํ–ˆ๋‹ค๋ฉด order ํ…Œ์ด๋ธ”์— ๋ ˆ์ฝ”๋“œ ํ•˜๋‚˜ ์ƒ์„ฑ
    • S1-5:

        UPDATE user SET status = ? WHERE id = ?;
    • S1-5 Explanation:

      • Update user status to ACTIVE
      • ์‚ฌ์šฉ์ž๊ฐ€์˜ ์ƒˆ ์ด์šฉ์› ๊ตฌ๋งค๊ฐ€ ์„ฑ๊ณต์ ์ด๋ฉฐ ์‚ฌ์šฉ์ž์˜ ์ƒํƒœ๋ฅผ ๋น„ํ™œ์„ฑํ™”์—์„œ ํ™œ์„ฑํ™”๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค. ์ด๋•Œ ๋™์  ๋งค๊ฐœ๋ณ€์ˆ˜ id์˜ ๊ฐ’์€ S1-1์—์„œ ๋ฐ˜์€ ๊ฒฐ๊ณผ ์…‹์˜ ๋ฐ์ดํ„ฐ ๊ฐ’์˜ ์ผ๋ถ€์ด๋‹ค.

Releases

No releases published

Packages

No packages published

Languages