├── 01 ├── 01-todolist-doc.md └── Projects.md ├── 02 └── java-basics │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ └── main │ └── java │ ├── com │ └── scaler │ │ ├── inheritence │ │ ├── Apple.java │ │ ├── Fruit.java │ │ ├── Main.java │ │ ├── Mango.java │ │ └── TypeErasure.java │ │ └── threads │ │ └── ThreadUsage.java │ └── org │ └── example │ ├── Fruit.java │ ├── Main.java │ └── Sample.java ├── 03 └── spring │ ├── basicapp │ ├── .gitignore │ ├── README.md │ ├── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── scaler │ │ │ │ └── basicapp │ │ │ │ ├── BasicappApplication.java │ │ │ │ ├── HelloController.java │ │ │ │ ├── UserController.java │ │ │ │ └── pojos │ │ │ │ └── User.java │ │ └── resources │ │ │ └── application.yaml │ │ └── test │ │ └── java │ │ └── com │ │ └── scaler │ │ └── basicapp │ │ └── BasicappApplicationTests.java │ └── todoapp │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── scaler │ │ │ └── todoapp │ │ │ ├── TodoappApplication.java │ │ │ ├── notes │ │ │ ├── NoteEntity.java │ │ │ ├── NotesController.java │ │ │ └── NotesService.java │ │ │ └── tasks │ │ │ ├── CreateTaskRequest.java │ │ │ ├── TaskEntity.java │ │ │ ├── TasksController.java │ │ │ └── TasksService.java │ └── resources │ │ └── application.yaml │ └── test │ └── java │ └── com │ └── scaler │ └── todoapp │ ├── TodoappApplicationTests.java │ └── tasks │ └── TasksServiceTests.java ├── 04 └── spring │ └── todo_withdb │ ├── .gitignore │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── scaler │ │ │ │ └── todo_withdb │ │ │ │ ├── TodoWithdbApplication.java │ │ │ │ ├── common │ │ │ │ ├── BaseEntity.java │ │ │ │ └── ErrorResponseDto.java │ │ │ │ ├── notes │ │ │ │ ├── NoteEntity.java │ │ │ │ ├── NotesController.java │ │ │ │ └── NotesRepository.java │ │ │ │ └── tasks │ │ │ │ ├── TaskDto.java │ │ │ │ ├── TaskEntity.java │ │ │ │ ├── TasksController.java │ │ │ │ ├── TasksRepository.java │ │ │ │ └── TasksService.java │ │ └── resources │ │ │ └── application.yaml │ └── test │ │ └── java │ │ └── com │ │ └── scaler │ │ └── todo_withdb │ │ ├── TodoWithdbApplicationTests.java │ │ └── tasks │ │ └── TasksRepositoryTests.java │ ├── todos.mv.db │ └── todos.trace.db ├── 05 └── spring │ └── blog_app │ ├── .gitignore │ ├── README.md │ ├── blog.mv.db │ ├── blog.trace.db │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── scaler │ │ │ └── blog_app │ │ │ ├── BlogAppApplication.java │ │ │ ├── articles │ │ │ ├── ArticleEntity.java │ │ │ ├── ArticlesController.java │ │ │ ├── ArticlesRepository.java │ │ │ └── ArticlesService.java │ │ │ ├── comments │ │ │ ├── CommentEntity.java │ │ │ ├── CommentsRepository.java │ │ │ └── CommentsService.java │ │ │ ├── common │ │ │ ├── BaseEntity.java │ │ │ └── StringModifierService.java │ │ │ └── users │ │ │ ├── UserEntity.java │ │ │ ├── UsersRepository.java │ │ │ └── UsersService.java │ └── resources │ │ └── application.yaml │ └── test │ └── java │ └── com │ └── scaler │ └── blog_app │ ├── BlogAppApplicationTests.java │ ├── articles │ ├── ArticlesControllerTests.java │ └── ArticlesRepositoryTests.java │ └── common │ └── StringModifierServiceTests.java └── README.md /01/01-todolist-doc.md: -------------------------------------------------------------------------------- 1 | # Todo List Backend Service 2 | 3 | ## API Docs 4 | 5 | **GET** `/tasks` 📄 6 | > get a list of all tasks 7 | 8 | ```json 9 | [ 10 | { 11 | "id": 1, 12 | "title": "this is something that i need to complete", 13 | "due_date": 20220205 14 | "completed": false 15 | }, 16 | { 17 | "id": 2, 18 | "title": "this is also something that i need to complete", 19 | "due_date": 20220206 20 | "completed": true 21 | } 22 | ] 23 | ``` 24 | 25 | **GET** `/tasks/{id}` 26 | > get a task by id 27 | 28 | ```json 29 | { 30 | "id": 1, 31 | "title": "this is something that i need to complete", 32 | "due_date": 20220205 33 | "completed": false, 34 | "notes": [ 35 | 36 | ] 37 | } 38 | ``` 39 | 40 | |query param | definition | 41 | | -----------|-----------| 42 | | `notes` | if true, include notes in results | 43 | 44 | examples - 45 | `/tasks/4?notes=true` - fetch details of task id = 4, including its notes 46 | 47 | 48 | **GET** `/tasks/{id}/notes` 49 | > get all notes inside a task 50 | 51 | ```json 52 | [ 53 | {}, 54 | {} 55 | ] 56 | ``` 57 | 58 | ### References 59 | 60 | If 📄 is used, it means the endpoint supports `?size=10&page=2` type of pagination properties 61 | 62 | ## Entities 63 | 64 | ![image](https://user-images.githubusercontent.com/1327050/180837289-72d49220-f104-45dd-80c6-e30378ab62a6.png) 65 | 66 | -------------------------------------------------------------------------------- /01/Projects.md: -------------------------------------------------------------------------------- 1 | # Projects 2 | 3 | ## 01 Todo List API 4 | 5 | ### Features 6 | 7 | - We have **Tasks** and **Notes** 8 | 9 | - Tasks 10 | - We can see all existing tasks 11 | - We can create new tasks 12 | - Every task has a title, a due date, and a boolean flag "completed" 13 | - Every task once created, also has a unique ID 14 | - A given task can be marked as completed (or undo completed too) 15 | - Due date of a task can be changed 16 | - Task can be deleted 17 | 18 | - Notes 19 | - Notes exist inside tasks 20 | - Every note has a title and a body 21 | - once a note is added, it should have an id too 22 | - Multiple notes can be added into a task 23 | 24 | > NOTE: Take other necessary assumptions 25 | 26 | 27 | 28 | ## 02 Blogging App 29 | 30 | ### Entities 31 | - Users 32 | - Articles 33 | - Comments 34 | 35 | ### Features 36 | 37 | - Users 38 | - signup user using following details 39 | - username, email, password, bio, avatar (just url of image) 40 | - login user 41 | - provided username + password, if correct, respond with a token 42 | 43 | - Articles 44 | - Each article is written by an "author" which is an existing user 45 | - Articles have 46 | - title, subtitle (use appropriate max lengths) 47 | - body (can be upto 5000 char) 48 | - tags (array of things like: tech, javascript, blog) 49 | - We can see all articles on the site 50 | - There can be thousands of articles, so pagination is needed 51 | - We should be able to filter articles by author and tags 52 | - i.e. show me all articles written on 'javascript' 53 | - show me all articles written by user 'johnwriter11' 54 | - Articles can be edited (title, subtitle, body, tags), by the author 55 | - Articles can be deleted by the author 56 | - Likes 57 | - Articles can be liked by anyone 58 | - We can see list of users who have liked the article 59 | 60 | 61 | - Comments 62 | - Comments are written under an article 63 | - Comments also have an author 64 | - We should be able to see all comments under an article 65 | - Comments can be deleted by the author of the comment 66 | 67 | 68 | > NOTE: Take other necessary assumptions 69 | 70 | 71 | 72 | ## 03 Event Ticketing System -------------------------------------------------------------------------------- /02/java-basics/.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | /.vscode 4 | /build 5 | -------------------------------------------------------------------------------- /02/java-basics/README.md: -------------------------------------------------------------------------------- 1 | ## Build and Run Project 2 | 3 | 4 | ```shell 5 | 6 | ./gradlew build 7 | 8 | java -jar build/libs/java-basics-1.0-SNAPSHOT.jar 9 | ``` -------------------------------------------------------------------------------- /02/java-basics/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | group 'org.example' 6 | version '1.0-SNAPSHOT' 7 | 8 | repositories { 9 | google() 10 | } 11 | 12 | jar { 13 | manifest { 14 | attributes( 15 | 'Main-Class': 'com.scaler.inheritence.TypeErasure' 16 | ) 17 | } 18 | } 19 | 20 | 21 | dependencies { 22 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' 23 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' 24 | } 25 | 26 | test { 27 | useJUnitPlatform() 28 | } -------------------------------------------------------------------------------- /02/java-basics/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/02/java-basics/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /02/java-basics/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /02/java-basics/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /02/java-basics/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /02/java-basics/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'java-basics' 2 | 3 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/inheritence/Apple.java: -------------------------------------------------------------------------------- 1 | package com.scaler.inheritence; 2 | 3 | public class Apple extends Fruit { 4 | public boolean isLarge() { 5 | return getSize() > 3; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/inheritence/Fruit.java: -------------------------------------------------------------------------------- 1 | package com.scaler.inheritence; 2 | 3 | public class Fruit { 4 | int size; // 4 bytes 5 | 6 | protected int getSize() { 7 | return size; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/inheritence/Main.java: -------------------------------------------------------------------------------- 1 | package com.scaler.inheritence; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Main { 7 | 8 | public static void main(String[] args) { 9 | Mango mango = new Mango(); // byte 10 | System.out.println(mango.isLarge()); 11 | 12 | List list = new ArrayList<>(); 13 | 14 | var list2 = new ArrayList(); 15 | 16 | var f = new ArrayList(); 17 | 18 | // type-erasure ? 19 | 20 | ArrayList fruitBasket = new ArrayList<>(); 21 | List fruitBasket2 = new ArrayList<>(); 22 | 23 | fruitBasket.add(new Apple()); 24 | fruitBasket.add(new Mango()); 25 | 26 | System.out.println(fruitBasket.get(0).size); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/inheritence/Mango.java: -------------------------------------------------------------------------------- 1 | package com.scaler.inheritence; 2 | 3 | public class Mango extends Fruit { 4 | boolean ripe; // 1 byte 5 | 6 | public boolean isLarge() { 7 | return getSize() > 5; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/inheritence/TypeErasure.java: -------------------------------------------------------------------------------- 1 | package com.scaler.inheritence; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TypeErasure { 7 | 8 | public static void main(String[] args) { 9 | ArrayList list = new ArrayList<>(); 10 | list.add("asdasd"); 11 | 12 | // ArrayList list2 = list; 13 | // 14 | // list2.add(123); 15 | 16 | Object x = "asd"; 17 | System.out.println(x); 18 | x = 10; 19 | System.out.println(x); 20 | 21 | 22 | ArrayList objList = new ArrayList<>(); 23 | objList.add("Asd"); 24 | objList.add(12); 25 | objList.add(new Apple()); 26 | 27 | objList.forEach(System.out::println); 28 | 29 | List fruitBasket = new ArrayList<>(); 30 | fruitBasket.add(new Apple()); 31 | fruitBasket.add(new Mango()); 32 | 33 | 34 | List appleDozen = new ArrayList(12); 35 | fruitBasket.addAll(appleDozen); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/com/scaler/threads/ThreadUsage.java: -------------------------------------------------------------------------------- 1 | package com.scaler.threads; 2 | 3 | public class ThreadUsage { 4 | 5 | public static void main(String[] args) { 6 | 7 | var start = System.currentTimeMillis(); 8 | System.out.println("wait started"); 9 | 10 | for (int i = 0; i < 5; i++) { 11 | int finalI = i; 12 | new Thread(() -> { 13 | int runCounter = 0; 14 | while (System.currentTimeMillis() - start < 10000) { 15 | // do nothing 16 | runCounter++; 17 | } 18 | System.out.println("wait " + finalI + " finished, ran " + runCounter + " times"); 19 | 20 | }).start(); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/org/example/Fruit.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | public class Fruit { 4 | String color; 5 | String taste; 6 | 7 | public Fruit(String color, String taste) { 8 | this.color = color; 9 | this.taste = taste; 10 | } 11 | 12 | public boolean isTasty() { 13 | return taste.equals("sweet"); 14 | } 15 | 16 | static public Fruit copy(Fruit oldFruit) { 17 | return new Fruit(oldFruit.color, oldFruit.taste); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /02/java-basics/src/main/java/org/example/Main.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | System.out.println("Hello world!"); 6 | 7 | Fruit apple = new Fruit("red", "sweet"); 8 | Fruit lime = new Fruit("yellow", "sour"); 9 | 10 | System.out.println("Is apple tasty? " + apple.isTasty()); 11 | System.out.println("Is lime tasty? " + lime.isTasty()); 12 | 13 | Fruit appleCopy = new Fruit(apple.color, apple.taste); 14 | } 15 | } -------------------------------------------------------------------------------- /02/java-basics/src/main/java/org/example/Sample.java: -------------------------------------------------------------------------------- 1 | package org.example; 2 | 3 | public class Sample { 4 | 5 | public static void main(String[] args) { 6 | System.out.println("Hello Sample!"); 7 | 8 | Person p = new Person("John", 32); 9 | 10 | } 11 | 12 | static class Person { 13 | String name; 14 | int age; 15 | 16 | public Person(String name, int age) { 17 | this.name = name; 18 | this.age = age; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /03/spring/basicapp/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /03/spring/basicapp/README.md: -------------------------------------------------------------------------------- 1 | # Basic Spring Boot App 2 | 3 | Generated via start.spring.io (Spring Initialzr) 4 | 5 | -------------------------------------------------------------------------------- /03/spring/basicapp/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.7.2' 3 | id 'io.spring.dependency-management' version '1.0.12.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.scaler' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '17' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-web' 17 | developmentOnly 'org.springframework.boot:spring-boot-devtools' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | 21 | tasks.named('test') { 22 | useJUnitPlatform() 23 | } 24 | -------------------------------------------------------------------------------- /03/spring/basicapp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/03/spring/basicapp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /03/spring/basicapp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /03/spring/basicapp/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /03/spring/basicapp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /03/spring/basicapp/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'basicapp' 2 | -------------------------------------------------------------------------------- /03/spring/basicapp/src/main/java/com/scaler/basicapp/BasicappApplication.java: -------------------------------------------------------------------------------- 1 | package com.scaler.basicapp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BasicappApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BasicappApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /03/spring/basicapp/src/main/java/com/scaler/basicapp/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.basicapp; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | import java.util.ArrayList; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | private ArrayList list = new ArrayList(); 11 | 12 | @GetMapping("/hello/{id}") 13 | public String hello(@PathVariable String id) { 14 | if (list.isEmpty()) { 15 | return "Hello World!"; 16 | } 17 | 18 | String greeting = list.get(Integer.parseInt(id)); 19 | 20 | return greeting; 21 | } 22 | 23 | @PostMapping("/greetings") 24 | public void greetings(@RequestParam String greeting) { 25 | System.out.println("greeting submitted: " + greeting); 26 | list.add(greeting); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /03/spring/basicapp/src/main/java/com/scaler/basicapp/UserController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.basicapp; 2 | 3 | import com.scaler.basicapp.pojos.User; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | import java.util.ArrayList; 7 | 8 | @RestController("/users") 9 | @RequestMapping("/users") 10 | public class UserController { 11 | 12 | private ArrayList users = new ArrayList<>(); 13 | 14 | @PostMapping("/") 15 | public User createUser(@RequestBody User user) { 16 | users.add(user); 17 | return user; 18 | } 19 | 20 | @GetMapping("/") 21 | public ArrayList getUsers() { 22 | return users; 23 | } 24 | 25 | @GetMapping("/{id}") 26 | public User getUser(@PathVariable("id") int id) { 27 | return users.get(id); 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /03/spring/basicapp/src/main/java/com/scaler/basicapp/pojos/User.java: -------------------------------------------------------------------------------- 1 | package com.scaler.basicapp.pojos; 2 | 3 | public class User { 4 | private String name; 5 | private String email; 6 | 7 | public User(String name, String email) { 8 | this.name = name; 9 | this.email = email; 10 | } 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | 16 | public void setName(String name) { 17 | this.name = name; 18 | } 19 | 20 | public String getEmail() { 21 | return email; 22 | } 23 | 24 | public void setEmail(String email) { 25 | this.email = email; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /03/spring/basicapp/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 4545 -------------------------------------------------------------------------------- /03/spring/basicapp/src/test/java/com/scaler/basicapp/BasicappApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.basicapp; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BasicappApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /03/spring/todoapp/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /03/spring/todoapp/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.7.2' 3 | id 'io.spring.dependency-management' version '1.0.12.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.scaler' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '17' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | compileOnly 'org.projectlombok:lombok' 24 | developmentOnly 'org.springframework.boot:spring-boot-devtools' 25 | annotationProcessor 'org.projectlombok:lombok' 26 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 27 | } 28 | 29 | tasks.named('test') { 30 | useJUnitPlatform() 31 | } 32 | -------------------------------------------------------------------------------- /03/spring/todoapp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/03/spring/todoapp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /03/spring/todoapp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /03/spring/todoapp/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /03/spring/todoapp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /03/spring/todoapp/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'todoapp' 2 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/TodoappApplication.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TodoappApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TodoappApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/notes/NoteEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.notes; 2 | 3 | import lombok.*; 4 | 5 | @AllArgsConstructor 6 | @NoArgsConstructor 7 | @Getter 8 | @Setter 9 | public class NoteEntity { 10 | Integer id; 11 | String title; 12 | String body; 13 | } 14 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/notes/NotesController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.notes; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | @RequestMapping("/tasks/{taskId}/notes") 8 | public class NotesController { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/notes/NotesService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.notes; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class NotesService { 7 | } 8 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/tasks/CreateTaskRequest.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.tasks; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | @Getter 11 | @Setter 12 | public class CreateTaskRequest { 13 | String name; 14 | String dueDate; 15 | } 16 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/tasks/TaskEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.tasks; 2 | 3 | import com.scaler.todoapp.notes.NoteEntity; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @Getter 15 | @Setter 16 | public class TaskEntity { 17 | Integer id; 18 | String name; 19 | Date dueDate; 20 | Boolean completed; 21 | List notes; 22 | } 23 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/tasks/TasksController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.tasks; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | @RestController 12 | @RequestMapping("/tasks") 13 | public class TasksController { 14 | 15 | private TasksService tasksService; 16 | 17 | public TasksController(TasksService tasksService) { 18 | this.tasksService = tasksService; 19 | } 20 | 21 | @GetMapping("/") 22 | public List getAllTasks() { 23 | return tasksService.getAllTasks(); 24 | } 25 | 26 | @PostMapping("/") 27 | public void createTask(CreateTaskRequest request) { 28 | tasksService.createTask(request.getName(), new Date()); 29 | // TODO: respond with 201 Created 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/java/com/scaler/todoapp/tasks/TasksService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.tasks; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | @Service 10 | public class TasksService { 11 | List tasks; 12 | 13 | public TasksService() { 14 | this.tasks = new ArrayList<>(); 15 | } 16 | 17 | /** 18 | * Get all tasks 19 | */ 20 | public List getAllTasks() { 21 | return tasks; 22 | } 23 | 24 | /** 25 | * Create a new task 26 | */ 27 | public void createTask(String name, Date dueDate) { 28 | int newTaskId = tasks.size(); 29 | TaskEntity task = new TaskEntity(newTaskId, name, dueDate, false, new ArrayList<>()); 30 | tasks.add(task); 31 | } 32 | 33 | /** 34 | * Get a task by id 35 | */ 36 | 37 | public TaskEntity getTaskById(int id) { 38 | return tasks.get(id); 39 | } 40 | 41 | /** 42 | * Delete a task by id 43 | */ 44 | public void deleteTaskById(int id) { 45 | tasks.remove(id); 46 | } 47 | 48 | /** 49 | * Update a task by id 50 | */ 51 | public void updateTaskById(int id, String name, Date dueDate, Boolean completed) { 52 | // TODO: if we add ids inside task object, then list index and task.id might not be same!! 53 | if (tasks.size() <= id) { 54 | throw new TaskNotFoundException(id); 55 | } 56 | TaskEntity task = tasks.get(id); 57 | 58 | if (name != null) { 59 | task.setName(name); 60 | } 61 | if (dueDate != null) { 62 | task.setDueDate(dueDate); 63 | } 64 | if (completed != null) { 65 | task.setCompleted(completed); 66 | } 67 | } 68 | 69 | static class TaskNotFoundException extends IllegalArgumentException { 70 | public TaskNotFoundException(int taskId) { 71 | super("Task with id = " + taskId + " not found"); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8989 -------------------------------------------------------------------------------- /03/spring/todoapp/src/test/java/com/scaler/todoapp/TodoappApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TodoappApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /03/spring/todoapp/src/test/java/com/scaler/todoapp/tasks/TasksServiceTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todoapp.tasks; 2 | 3 | 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.Date; 8 | 9 | public class TasksServiceTests { 10 | 11 | private TasksService tasksService = new TasksService(); 12 | 13 | /** 14 | * can create a new task 15 | */ 16 | @Test 17 | void canCreateTask() { 18 | tasksService.createTask("task1", new Date()); 19 | 20 | Assertions.assertEquals(1, tasksService.getAllTasks().size()); 21 | Assertions.assertEquals("task1", tasksService.getAllTasks().get(0).getName()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.7.2' 3 | id 'io.spring.dependency-management' version '1.0.12.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.scaler' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '17' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 23 | implementation 'org.springframework.boot:spring-boot-starter-web' 24 | implementation 'org.modelmapper:modelmapper:3.1.0' 25 | 26 | compileOnly 'org.projectlombok:lombok' 27 | developmentOnly 'org.springframework.boot:spring-boot-devtools' 28 | runtimeOnly 'com.h2database:h2' 29 | runtimeOnly 'org.postgresql:postgresql' 30 | annotationProcessor 'org.projectlombok:lombok' 31 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 32 | } 33 | 34 | tasks.named('test') { 35 | useJUnitPlatform() 36 | } 37 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/04/spring/todo_withdb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /04/spring/todo_withdb/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'todo_withdb' 2 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/TodoWithdbApplication.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Scope; 8 | 9 | @SpringBootApplication 10 | public class TodoWithdbApplication { 11 | 12 | @Bean 13 | @Scope("singleton") 14 | public ModelMapper modelMapper() { 15 | return new ModelMapper(); 16 | } 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(TodoWithdbApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/common/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.common; 2 | 3 | import lombok.Getter; 4 | import org.hibernate.annotations.CreationTimestamp; 5 | import org.hibernate.annotations.UpdateTimestamp; 6 | 7 | import javax.persistence.*; 8 | import java.util.Date; 9 | 10 | @MappedSuperclass 11 | @Getter 12 | public abstract class BaseEntity { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 16 | @Column(name = "id", nullable = false) 17 | Long id; 18 | 19 | @CreationTimestamp 20 | Date createdAt; 21 | 22 | @UpdateTimestamp 23 | Date updatedAt; 24 | } 25 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/common/ErrorResponseDto.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.common; 2 | 3 | import lombok.Data; 4 | import org.springframework.lang.NonNull; 5 | 6 | @Data 7 | public class ErrorResponseDto { 8 | @NonNull 9 | private String message; 10 | } 11 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/notes/NoteEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.notes; 2 | 3 | import com.scaler.todo_withdb.common.BaseEntity; 4 | import com.scaler.todo_withdb.tasks.TaskEntity; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | 9 | import javax.persistence.*; 10 | 11 | @Entity(name = "notes") 12 | @Getter 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | public class NoteEntity extends BaseEntity { 16 | 17 | @Column(name = "title", nullable = false, length = 100) 18 | String title; 19 | 20 | @Column(name = "body", nullable = false, length = 1000) 21 | String body; 22 | 23 | @ManyToOne(cascade = CascadeType.ALL) 24 | @JoinColumn(name = "task_id") 25 | TaskEntity task; 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/notes/NotesController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.notes; 2 | 3 | public class NotesController { 4 | } 5 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/notes/NotesRepository.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.notes; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public interface NotesRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/tasks/TaskDto.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import lombok.Data; 4 | import org.springframework.lang.Nullable; 5 | 6 | import java.util.Date; 7 | 8 | @Data 9 | public class TaskDto { 10 | @Nullable 11 | Long id; 12 | @Nullable 13 | String name; 14 | @Nullable 15 | Date dueDate; 16 | @Nullable 17 | Boolean done; 18 | } 19 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/tasks/TaskEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import com.scaler.todo_withdb.common.BaseEntity; 4 | import com.scaler.todo_withdb.notes.NoteEntity; 5 | import lombok.*; 6 | 7 | import javax.persistence.*; 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | @Entity(name = "tasks") 12 | @Getter 13 | @Setter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | @ToString 17 | public class TaskEntity extends BaseEntity { 18 | 19 | @Column(name = "name", nullable = false) 20 | String name; 21 | 22 | @Column(name = "due_date", nullable = false) 23 | Date dueDate; 24 | 25 | @Column(name = "done", nullable = false, columnDefinition = "boolean default false") 26 | boolean done; 27 | 28 | @OneToMany(mappedBy = "task", cascade = CascadeType.ALL) 29 | @ToString.Exclude 30 | List notes; 31 | 32 | public void setNotes(List notes) { 33 | this.notes = notes; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/tasks/TasksController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import com.scaler.todo_withdb.common.ErrorResponseDto; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.net.URI; 9 | import java.util.List; 10 | import java.util.logging.Logger; 11 | 12 | @RestController 13 | @RequestMapping("/tasks") 14 | public class TasksController { 15 | 16 | private TasksService tasksService; 17 | 18 | public TasksController(TasksService tasksService) { 19 | this.tasksService = tasksService; 20 | } 21 | 22 | @GetMapping("") 23 | ResponseEntity> getAllTasks() { 24 | var tasks = tasksService.getAllTasks(); 25 | return ResponseEntity.ok(tasks); 26 | } 27 | 28 | @PostMapping("") 29 | ResponseEntity createNewTask(@RequestBody TaskDto task) { 30 | var savedTask = tasksService.createNewTask(task); 31 | return ResponseEntity.created(URI.create("/tasks/" + savedTask.getId())).body(savedTask); 32 | } 33 | 34 | @GetMapping("/{id}") 35 | ResponseEntity getTaskById(@PathVariable Long id) { 36 | var task = tasksService.getTaskById(id); 37 | return ResponseEntity.ok(task); 38 | } 39 | 40 | @PatchMapping("/{id}") 41 | void updateTaskById() { 42 | } 43 | 44 | @ExceptionHandler({ 45 | TasksService.TaskNotFoundException.class, 46 | TasksService.TaskAlreadyExistsException.class, 47 | TasksService.TaskInvalidException.class 48 | }) 49 | ResponseEntity handleError(Exception e) { 50 | HttpStatus errorStatus; 51 | 52 | if (e instanceof TasksService.TaskNotFoundException) { 53 | errorStatus = HttpStatus.NOT_FOUND; 54 | } else if (e instanceof TasksService.TaskAlreadyExistsException) { 55 | errorStatus = HttpStatus.CONFLICT; 56 | } else if (e instanceof TasksService.TaskInvalidException) { 57 | errorStatus = HttpStatus.BAD_REQUEST; 58 | } else { 59 | errorStatus = HttpStatus.INTERNAL_SERVER_ERROR; 60 | } 61 | 62 | return ResponseEntity 63 | .status(errorStatus) 64 | .body(new ErrorResponseDto(e.getMessage())); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/tasks/TasksRepository.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public interface TasksRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/java/com/scaler/todo_withdb/tasks/TasksService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.Date; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | 10 | @Service 11 | public class TasksService { 12 | 13 | private TasksRepository tasksRepository; 14 | private ModelMapper modelMapper; 15 | 16 | public TasksService(TasksRepository tasksRepository, ModelMapper modelMapper) { 17 | this.tasksRepository = tasksRepository; 18 | this.modelMapper = modelMapper; 19 | } 20 | 21 | public List getAllTasks() { 22 | return tasksRepository.findAll() 23 | .stream() 24 | .map(task -> modelMapper.map(task, TaskDto.class)) 25 | .collect(Collectors.toList()); 26 | } 27 | 28 | public TaskDto getTaskById(Long id) { 29 | var task = tasksRepository.findById(id).orElseThrow(() -> new TaskNotFoundException(id)); 30 | return modelMapper.map(task, TaskDto.class); 31 | } 32 | 33 | public TaskDto createNewTask(TaskDto task) { 34 | if (task.getDueDate() != null && task.getDueDate().before(new Date())) { 35 | throw new TaskInvalidException("Due date must be in the future"); 36 | } 37 | var taskEntity = modelMapper.map(task, TaskEntity.class); 38 | var savedTask = tasksRepository.save(taskEntity); 39 | // TODO: TaskAlreadyExistsException 40 | 41 | return modelMapper.map(savedTask, TaskDto.class); 42 | } 43 | 44 | static class TaskNotFoundException extends IllegalArgumentException { 45 | public TaskNotFoundException(Long id) { 46 | super("Task with id " + id + " not found"); 47 | } 48 | } 49 | 50 | static class TaskAlreadyExistsException extends IllegalArgumentException { 51 | public TaskAlreadyExistsException(Long id) { 52 | super("Task with id " + id + " already exists"); 53 | } 54 | } 55 | 56 | static class TaskInvalidException extends IllegalArgumentException { 57 | public TaskInvalidException(String message) { 58 | super(message); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8282 3 | spring: 4 | datasource: 5 | driver-class-name: org.h2.Driver # In production use Postgres 6 | url: jdbc:h2:file:./todos;DB_CLOSE_DELAY=-1 7 | jpa: 8 | hibernate: 9 | ddl-auto: update 10 | show-sql: true 11 | properties: 12 | hibernate: 13 | format_sql: true -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/test/java/com/scaler/todo_withdb/TodoWithdbApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TodoWithdbApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/src/test/java/com/scaler/todo_withdb/tasks/TasksRepositoryTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.todo_withdb.tasks; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 6 | 7 | import java.util.Date; 8 | 9 | import static org.junit.jupiter.api.Assertions.assertEquals; 10 | 11 | @DataJpaTest 12 | public class TasksRepositoryTests { 13 | @Autowired private TasksRepository tasksRepository; 14 | 15 | @Test 16 | public void canCreateTask() { 17 | TaskEntity task = new TaskEntity(); 18 | task.name = "test task"; 19 | task.dueDate = new Date(); 20 | tasksRepository.save(task); 21 | 22 | TaskEntity savedTask = tasksRepository.findAll().get(0); 23 | 24 | assertEquals("test task", savedTask.name); 25 | 26 | System.out.println(savedTask); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /04/spring/todo_withdb/todos.mv.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/04/spring/todo_withdb/todos.mv.db -------------------------------------------------------------------------------- /04/spring/todo_withdb/todos.trace.db: -------------------------------------------------------------------------------- 1 | 2022-08-05 17:16:04 jdbc[3]: exception 2 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 3 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 4 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 5 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 6 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 7 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 8 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 9 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 10 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 11 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 12 | at java.base/java.security.AccessController.doPrivileged(Native Method) 13 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 14 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 15 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 16 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 17 | at java.base/java.security.AccessController.doPrivileged(Native Method) 18 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 19 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 20 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 21 | at java.base/java.lang.Thread.run(Thread.java:829) 22 | 2022-08-05 17:16:05 jdbc[4]: exception 23 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 24 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 25 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 26 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 27 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 28 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 29 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 30 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 31 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 32 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 33 | at java.base/java.security.AccessController.doPrivileged(Native Method) 34 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 35 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 36 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 37 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 38 | at java.base/java.security.AccessController.doPrivileged(Native Method) 39 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 40 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 41 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 42 | at java.base/java.lang.Thread.run(Thread.java:829) 43 | -------------------------------------------------------------------------------- /05/spring/blog_app/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /05/spring/blog_app/README.md: -------------------------------------------------------------------------------- 1 | # Blogging App (Spring Boot) 2 | 3 | ## Development 4 | 5 | ### Database Setup 6 | 7 | 1. Create a database 8 | 2. Create a user 9 | 3. Create a password 10 | 4. Grant access to created database to user 11 | 12 | #### Postgres 13 | 14 | 15 | ```postgresql 16 | CREATE DATABASE blog; 17 | CREATE USER blogadmin WITH ENCRYPTED PASSWORD 'blogpass'; 18 | GRANT ALL PRIVILEGES ON DATABASE blog TO blogadmin; 19 | ``` 20 | 21 | #### MySQL 22 | 23 | ```mysql 24 | CREATE DATABASE blog; 25 | CREATE USER 'blogadmin'@'localhost' IDENTIFIED BY 'blogpass'; 26 | GRANT ALL PRIVILEGES ON blog.* TO 'blogadmin'@'localhost'; 27 | ``` -------------------------------------------------------------------------------- /05/spring/blog_app/blog.mv.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/05/spring/blog_app/blog.mv.db -------------------------------------------------------------------------------- /05/spring/blog_app/blog.trace.db: -------------------------------------------------------------------------------- 1 | 2022-08-08 17:18:51 jdbc[3]: exception 2 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 3 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 4 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 5 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 6 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 7 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 8 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 9 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 10 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 11 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 12 | at java.base/java.security.AccessController.doPrivileged(Native Method) 13 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 14 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 15 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 16 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 17 | at java.base/java.security.AccessController.doPrivileged(Native Method) 18 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 19 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 20 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 21 | at java.base/java.lang.Thread.run(Thread.java:829) 22 | 2022-08-08 17:18:54 jdbc[3]: exception 23 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 24 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 25 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 26 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 27 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 28 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 29 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 30 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 31 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 32 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 33 | at java.base/java.security.AccessController.doPrivileged(Native Method) 34 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 35 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 36 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 37 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 38 | at java.base/java.security.AccessController.doPrivileged(Native Method) 39 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 40 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 41 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 42 | at java.base/java.lang.Thread.run(Thread.java:829) 43 | 2022-08-08 17:19:01 jdbc[4]: exception 44 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 45 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 46 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 47 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 48 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 49 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 50 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 51 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 52 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 53 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 54 | at java.base/java.security.AccessController.doPrivileged(Native Method) 55 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 56 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 57 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 58 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 59 | at java.base/java.security.AccessController.doPrivileged(Native Method) 60 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 61 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 62 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 63 | at java.base/java.lang.Thread.run(Thread.java:829) 64 | 2022-08-08 17:19:04 jdbc[5]: exception 65 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 66 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 67 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 68 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 69 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 70 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 71 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 72 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 73 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 74 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 75 | at java.base/java.security.AccessController.doPrivileged(Native Method) 76 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 77 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 78 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 79 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 80 | at java.base/java.security.AccessController.doPrivileged(Native Method) 81 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 82 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 83 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 84 | at java.base/java.lang.Thread.run(Thread.java:829) 85 | 2022-08-08 17:20:15 jdbc[3]: exception 86 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 87 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 88 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 89 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 90 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 91 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 92 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 93 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 94 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 95 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 96 | at java.base/java.security.AccessController.doPrivileged(Native Method) 97 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 98 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 99 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 100 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 101 | at java.base/java.security.AccessController.doPrivileged(Native Method) 102 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 103 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 104 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 105 | at java.base/java.lang.Thread.run(Thread.java:829) 106 | 2022-08-08 17:24:15 jdbc[3]: exception 107 | java.sql.SQLClientInfoException: Client info name 'ApplicationName' not supported. 108 | at org.h2.jdbc.JdbcConnection.setClientInfo(JdbcConnection.java:1573) 109 | at com.intellij.database.remote.jdbc.impl.RemoteConnectionImpl.setClientInfo(RemoteConnectionImpl.java:470) 110 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 111 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 112 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 113 | at java.base/java.lang.reflect.Method.invoke(Method.java:566) 114 | at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359) 115 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) 116 | at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) 117 | at java.base/java.security.AccessController.doPrivileged(Native Method) 118 | at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) 119 | at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562) 120 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796) 121 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677) 122 | at java.base/java.security.AccessController.doPrivileged(Native Method) 123 | at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676) 124 | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) 125 | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) 126 | at java.base/java.lang.Thread.run(Thread.java:829) 127 | 2022-08-08 23:09:59 database: flush 128 | org.h2.message.DbException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 129 | at org.h2.message.DbException.get(DbException.java:212) 130 | at org.h2.message.DbException.convert(DbException.java:395) 131 | at org.h2.mvstore.db.Store.lambda$new$0(Store.java:125) 132 | at org.h2.mvstore.MVStore.handleException(MVStore.java:3318) 133 | at org.h2.mvstore.MVStore.panic(MVStore.java:593) 134 | at org.h2.mvstore.MVStore.(MVStore.java:469) 135 | at org.h2.mvstore.MVStore$Builder.open(MVStore.java:4082) 136 | at org.h2.mvstore.db.Store.(Store.java:136) 137 | at org.h2.engine.Database.(Database.java:324) 138 | at org.h2.engine.Engine.openSession(Engine.java:92) 139 | at org.h2.engine.Engine.openSession(Engine.java:222) 140 | at org.h2.engine.Engine.createSession(Engine.java:201) 141 | at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338) 142 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:122) 143 | at org.h2.Driver.connect(Driver.java:59) 144 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) 145 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) 146 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) 147 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) 148 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) 149 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) 150 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) 151 | at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.lambda$logDataSources$0(H2ConsoleAutoConfiguration.java:75) 152 | at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) 153 | at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 154 | at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395) 155 | at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) 156 | at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258) 157 | at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) 158 | at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) 159 | at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) 160 | at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) 161 | at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) 162 | at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.logDataSources(H2ConsoleAutoConfiguration.java:81) 163 | at org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration.h2Console(H2ConsoleAutoConfiguration.java:68) 164 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 165 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 166 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 167 | at java.base/java.lang.reflect.Method.invoke(Method.java:568) 168 | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) 169 | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) 170 | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) 171 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) 172 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) 173 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) 174 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) 175 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) 176 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) 177 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) 178 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) 179 | at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) 180 | at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:203) 181 | at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97) 182 | at org.springframework.boot.web.servlet.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:86) 183 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:262) 184 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:236) 185 | at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) 186 | at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) 187 | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) 188 | at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) 189 | at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) 190 | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 191 | at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) 192 | at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) 193 | at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) 194 | at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) 195 | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) 196 | at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) 197 | at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) 198 | at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) 199 | at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) 200 | at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145) 201 | at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) 202 | at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:265) 203 | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) 204 | at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) 205 | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) 206 | at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) 207 | at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) 208 | at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) 209 | at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) 210 | at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:104) 211 | at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:479) 212 | at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) 213 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:184) 214 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) 215 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) 216 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) 217 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) 218 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) 219 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) 220 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) 221 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) 222 | at com.scaler.blog_app.BlogAppApplication.main(BlogAppApplication.java:10) 223 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 224 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 225 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 226 | at java.base/java.lang.reflect.Method.invoke(Method.java:568) 227 | at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) 228 | Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 229 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:554) 230 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) 231 | ... 99 more 232 | Caused by: org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7] 233 | at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004) 234 | at org.h2.mvstore.FileStore.open(FileStore.java:178) 235 | at org.h2.mvstore.FileStore.open(FileStore.java:128) 236 | at org.h2.mvstore.MVStore.(MVStore.java:452) 237 | ... 93 more 238 | 2022-08-08 23:10:00 database: flush 239 | org.h2.message.DbException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 240 | at org.h2.message.DbException.get(DbException.java:212) 241 | at org.h2.message.DbException.convert(DbException.java:395) 242 | at org.h2.mvstore.db.Store.lambda$new$0(Store.java:125) 243 | at org.h2.mvstore.MVStore.handleException(MVStore.java:3318) 244 | at org.h2.mvstore.MVStore.panic(MVStore.java:593) 245 | at org.h2.mvstore.MVStore.(MVStore.java:469) 246 | at org.h2.mvstore.MVStore$Builder.open(MVStore.java:4082) 247 | at org.h2.mvstore.db.Store.(Store.java:136) 248 | at org.h2.engine.Database.(Database.java:324) 249 | at org.h2.engine.Engine.openSession(Engine.java:92) 250 | at org.h2.engine.Engine.openSession(Engine.java:222) 251 | at org.h2.engine.Engine.createSession(Engine.java:201) 252 | at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338) 253 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:122) 254 | at org.h2.Driver.connect(Driver.java:59) 255 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) 256 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) 257 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) 258 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) 259 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) 260 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) 261 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) 262 | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) 263 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) 264 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) 265 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 266 | at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) 267 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) 268 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) 269 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 270 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) 271 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) 272 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) 273 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 274 | at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.(InFlightMetadataCollectorImpl.java:173) 275 | at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) 276 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) 277 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) 278 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) 279 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) 280 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) 281 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) 282 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) 283 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) 284 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) 285 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) 286 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) 287 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) 288 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) 289 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) 290 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) 291 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) 292 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) 293 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) 294 | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) 295 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) 296 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) 297 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) 298 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) 299 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) 300 | at com.scaler.blog_app.BlogAppApplication.main(BlogAppApplication.java:10) 301 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 302 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 303 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 304 | at java.base/java.lang.reflect.Method.invoke(Method.java:568) 305 | at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) 306 | Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 307 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:554) 308 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) 309 | ... 66 more 310 | Caused by: org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7] 311 | at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004) 312 | at org.h2.mvstore.FileStore.open(FileStore.java:178) 313 | at org.h2.mvstore.FileStore.open(FileStore.java:128) 314 | at org.h2.mvstore.MVStore.(MVStore.java:452) 315 | ... 60 more 316 | 2022-08-17 21:29:52 database: flush 317 | org.h2.message.DbException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 318 | at org.h2.message.DbException.get(DbException.java:212) 319 | at org.h2.message.DbException.convert(DbException.java:395) 320 | at org.h2.mvstore.db.Store.lambda$new$0(Store.java:125) 321 | at org.h2.mvstore.MVStore.handleException(MVStore.java:3318) 322 | at org.h2.mvstore.MVStore.panic(MVStore.java:593) 323 | at org.h2.mvstore.MVStore.(MVStore.java:469) 324 | at org.h2.mvstore.MVStore$Builder.open(MVStore.java:4082) 325 | at org.h2.mvstore.db.Store.(Store.java:136) 326 | at org.h2.engine.Database.(Database.java:324) 327 | at org.h2.engine.Engine.openSession(Engine.java:92) 328 | at org.h2.engine.Engine.openSession(Engine.java:222) 329 | at org.h2.engine.Engine.createSession(Engine.java:201) 330 | at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338) 331 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:122) 332 | at org.h2.Driver.connect(Driver.java:59) 333 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) 334 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) 335 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) 336 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) 337 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) 338 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) 339 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) 340 | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) 341 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) 342 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) 343 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 344 | at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) 345 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) 346 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) 347 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 348 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) 349 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) 350 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) 351 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 352 | at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.(InFlightMetadataCollectorImpl.java:173) 353 | at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) 354 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) 355 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) 356 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) 357 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) 358 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) 359 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) 360 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) 361 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) 362 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) 363 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) 364 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) 365 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) 366 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) 367 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) 368 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) 369 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) 370 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) 371 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) 372 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) 373 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) 374 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) 375 | at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:132) 376 | at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) 377 | at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 378 | at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) 379 | at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) 380 | at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) 381 | at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248) 382 | at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138) 383 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363) 384 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368) 385 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363) 386 | at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) 387 | at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) 388 | at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) 389 | at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) 390 | at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) 391 | at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310) 392 | at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735) 393 | at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734) 394 | at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762) 395 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:362) 396 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$6(ClassBasedTestDescriptor.java:283) 397 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 398 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:282) 399 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:272) 400 | at java.base/java.util.Optional.orElseGet(Optional.java:364) 401 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:271) 402 | at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31) 403 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:102) 404 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 405 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:101) 406 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:66) 407 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123) 408 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 409 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123) 410 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90) 411 | at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 412 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) 413 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) 414 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 415 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) 416 | at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) 417 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) 418 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 419 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) 420 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) 421 | at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 422 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) 423 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) 424 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 425 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) 426 | at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) 427 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) 428 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 429 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) 430 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) 431 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) 432 | at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) 433 | at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) 434 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) 435 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) 436 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) 437 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) 438 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) 439 | at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) 440 | at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) 441 | at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) 442 | at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) 443 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99) 444 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79) 445 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75) 446 | at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61) 447 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 448 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 449 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 450 | at java.base/java.lang.reflect.Method.invoke(Method.java:568) 451 | at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) 452 | at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 453 | at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) 454 | at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) 455 | at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source) 456 | at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193) 457 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) 458 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) 459 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) 460 | at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) 461 | at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133) 462 | at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71) 463 | at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) 464 | at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) 465 | Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 466 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:554) 467 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) 468 | ... 147 more 469 | Caused by: org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7] 470 | at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004) 471 | at org.h2.mvstore.FileStore.open(FileStore.java:178) 472 | at org.h2.mvstore.FileStore.open(FileStore.java:128) 473 | at org.h2.mvstore.MVStore.(MVStore.java:452) 474 | ... 141 more 475 | 2022-08-17 21:30:37 database: flush 476 | org.h2.message.DbException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 477 | at org.h2.message.DbException.get(DbException.java:212) 478 | at org.h2.message.DbException.convert(DbException.java:395) 479 | at org.h2.mvstore.db.Store.lambda$new$0(Store.java:125) 480 | at org.h2.mvstore.MVStore.handleException(MVStore.java:3318) 481 | at org.h2.mvstore.MVStore.panic(MVStore.java:593) 482 | at org.h2.mvstore.MVStore.(MVStore.java:469) 483 | at org.h2.mvstore.MVStore$Builder.open(MVStore.java:4082) 484 | at org.h2.mvstore.db.Store.(Store.java:136) 485 | at org.h2.engine.Database.(Database.java:324) 486 | at org.h2.engine.Engine.openSession(Engine.java:92) 487 | at org.h2.engine.Engine.openSession(Engine.java:222) 488 | at org.h2.engine.Engine.createSession(Engine.java:201) 489 | at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:338) 490 | at org.h2.jdbc.JdbcConnection.(JdbcConnection.java:122) 491 | at org.h2.Driver.connect(Driver.java:59) 492 | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121) 493 | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) 494 | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) 495 | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) 496 | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) 497 | at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) 498 | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) 499 | at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) 500 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181) 501 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) 502 | at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 503 | at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) 504 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) 505 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) 506 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 507 | at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:175) 508 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) 509 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) 510 | at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) 511 | at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.(InFlightMetadataCollectorImpl.java:173) 512 | at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) 513 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1460) 514 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1494) 515 | at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) 516 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) 517 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) 518 | at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) 519 | at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) 520 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863) 521 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800) 522 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) 523 | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) 524 | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) 525 | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) 526 | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) 527 | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) 528 | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) 529 | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) 530 | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) 531 | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) 532 | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) 533 | at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) 534 | at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:132) 535 | at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) 536 | at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 537 | at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) 538 | at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) 539 | at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) 540 | at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248) 541 | at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138) 542 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363) 543 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368) 544 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363) 545 | at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) 546 | at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) 547 | at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) 548 | at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) 549 | at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) 550 | at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310) 551 | at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735) 552 | at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734) 553 | at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762) 554 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:362) 555 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$6(ClassBasedTestDescriptor.java:283) 556 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 557 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:282) 558 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:272) 559 | at java.base/java.util.Optional.orElseGet(Optional.java:364) 560 | at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:271) 561 | at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31) 562 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:102) 563 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 564 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:101) 565 | at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:66) 566 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$2(NodeTestTask.java:123) 567 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 568 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:123) 569 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:90) 570 | at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 571 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) 572 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) 573 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 574 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) 575 | at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) 576 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) 577 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 578 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) 579 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) 580 | at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) 581 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41) 582 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155) 583 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 584 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) 585 | at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) 586 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) 587 | at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) 588 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) 589 | at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) 590 | at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35) 591 | at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) 592 | at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54) 593 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) 594 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) 595 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) 596 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) 597 | at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) 598 | at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) 599 | at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) 600 | at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) 601 | at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) 602 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99) 603 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79) 604 | at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75) 605 | at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61) 606 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 607 | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 608 | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 609 | at java.base/java.lang.reflect.Method.invoke(Method.java:568) 610 | at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) 611 | at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) 612 | at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) 613 | at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) 614 | at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source) 615 | at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193) 616 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) 617 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) 618 | at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) 619 | at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) 620 | at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133) 621 | at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71) 622 | at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) 623 | at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) 624 | Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7]" [50000-214] 625 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:554) 626 | at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) 627 | ... 147 more 628 | Caused by: org.h2.mvstore.MVStoreException: The file is locked: /Users/championswimmer/Development/Scaler/Classes/Project-Module-Jul-2022/05/spring/blog_app/blog.mv.db [2.1.214/7] 629 | at org.h2.mvstore.DataUtils.newMVStoreException(DataUtils.java:1004) 630 | at org.h2.mvstore.FileStore.open(FileStore.java:178) 631 | at org.h2.mvstore.FileStore.open(FileStore.java:128) 632 | at org.h2.mvstore.MVStore.(MVStore.java:452) 633 | ... 141 more 634 | -------------------------------------------------------------------------------- /05/spring/blog_app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.7.2' 3 | id 'io.spring.dependency-management' version '1.0.12.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.scaler' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '17' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 23 | implementation 'org.springframework.boot:spring-boot-starter-web' 24 | compileOnly 'org.projectlombok:lombok' 25 | developmentOnly 'org.springframework.boot:spring-boot-devtools' 26 | runtimeOnly 'com.h2database:h2' 27 | runtimeOnly 'org.postgresql:postgresql' 28 | annotationProcessor 'org.projectlombok:lombok' 29 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 30 | } 31 | 32 | tasks.named('test') { 33 | useJUnitPlatform() 34 | } 35 | -------------------------------------------------------------------------------- /05/spring/blog_app/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scaleracademy/Project-Module-Jul-2022/5131693361ad755f869580902b6150e801cae98e/05/spring/blog_app/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /05/spring/blog_app/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /05/spring/blog_app/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /05/spring/blog_app/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /05/spring/blog_app/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'blog_app' 2 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/BlogAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BlogAppApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BlogAppApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/articles/ArticleEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import com.scaler.blog_app.comments.CommentEntity; 4 | import com.scaler.blog_app.common.BaseEntity; 5 | import com.scaler.blog_app.users.UserEntity; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | 10 | import javax.persistence.*; 11 | import java.util.Set; 12 | 13 | @Entity(name = "articles") 14 | @Getter 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | public class ArticleEntity extends BaseEntity { 18 | 19 | @Column(nullable = false, length = 100) 20 | String title; 21 | 22 | @Column(nullable = false, unique = true, length = 100) 23 | String slug; 24 | 25 | @Column(length = 150) 26 | String subtitle; 27 | 28 | @Column(columnDefinition = "TEXT") 29 | String body; 30 | 31 | @ManyToOne 32 | @JoinColumn(name = "author_id", nullable = false) 33 | UserEntity author; 34 | 35 | @ManyToMany(fetch = FetchType.EAGER) 36 | @JoinTable( 37 | name = "likes", 38 | joinColumns = @JoinColumn(name = "article_id"), 39 | inverseJoinColumns = @JoinColumn(name = "user_id") 40 | ) 41 | Set likers; 42 | 43 | @OneToMany(mappedBy = "article", cascade = CascadeType.ALL, fetch = FetchType.LAZY) 44 | Set comments; 45 | } 46 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/articles/ArticlesController.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.util.List; 9 | 10 | @RestController 11 | @RequestMapping("/articles") 12 | public class ArticlesController { 13 | 14 | private ArticlesService articlesService; 15 | 16 | public ArticlesController(ArticlesService articlesService) { 17 | this.articlesService = articlesService; 18 | } 19 | 20 | @GetMapping("") 21 | public List getArticles() { 22 | return articlesService.getAllArticles(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/articles/ArticlesRepository.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Repository 10 | public interface ArticlesRepository extends JpaRepository { 11 | 12 | List findArticleEntitiesBySlugContaining(String slug); 13 | } 14 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/articles/ArticlesService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import java.util.List; 6 | 7 | @Service 8 | public class ArticlesService { 9 | private ArticlesRepository articlesRepository; 10 | 11 | // real > fake > mock > stub 12 | 13 | public ArticlesService(ArticlesRepository articlesRepository) { 14 | this.articlesRepository = articlesRepository; 15 | } 16 | 17 | List getAllArticles() { 18 | return articlesRepository.findAll(); 19 | } 20 | 21 | void getArticleById(Long id) { 22 | articlesRepository.findById(id); 23 | } 24 | 25 | void getArticleBySlug(String slug) { 26 | articlesRepository.findArticleEntitiesBySlugContaining(slug); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/comments/CommentEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.comments; 2 | 3 | import com.scaler.blog_app.articles.ArticleEntity; 4 | import com.scaler.blog_app.common.BaseEntity; 5 | import com.scaler.blog_app.users.UserEntity; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | 10 | import javax.persistence.Column; 11 | import javax.persistence.Entity; 12 | import javax.persistence.JoinColumn; 13 | import javax.persistence.ManyToOne; 14 | 15 | @Entity(name = "comments") 16 | @Getter 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class CommentEntity extends BaseEntity { 20 | 21 | @Column(nullable = false, length = 100) 22 | String title; 23 | 24 | @Column(columnDefinition = "TEXT") 25 | String body; 26 | 27 | @ManyToOne 28 | @JoinColumn(name = "author_id", nullable = false) 29 | UserEntity author; 30 | 31 | @ManyToOne 32 | @JoinColumn(name = "article_id", nullable = false) 33 | ArticleEntity article; 34 | } 35 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/comments/CommentsRepository.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.comments; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public interface CommentsRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/comments/CommentsService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.comments; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class CommentsService { 7 | private CommentsRepository commentsRepository; 8 | 9 | public CommentsService(CommentsRepository commentsRepository) { 10 | this.commentsRepository = commentsRepository; 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/common/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.common; 2 | 3 | import lombok.Setter; 4 | import org.hibernate.annotations.Generated; 5 | import org.hibernate.annotations.UpdateTimestamp; 6 | 7 | import javax.persistence.*; 8 | import java.util.Date; 9 | 10 | @MappedSuperclass 11 | public abstract class BaseEntity { 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 14 | @Column(name = "id", nullable = false) 15 | private Long id; 16 | 17 | @Setter @UpdateTimestamp 18 | Date createdAt; 19 | 20 | @Setter @UpdateTimestamp 21 | Date updatedAt; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/common/StringModifierService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.common; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class StringModifierService { 7 | 8 | public String removeSpecialCharacters(String input) { 9 | return input.replaceAll("[^a-zA-Z0-9]", " ").trim(); 10 | } 11 | 12 | public String slugify(String input) { 13 | return removeSpecialCharacters(input) 14 | .toLowerCase() 15 | .replaceAll("[^a-zA-Z0-9]", "-"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/users/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.users; 2 | 3 | import com.scaler.blog_app.articles.ArticleEntity; 4 | import com.scaler.blog_app.common.BaseEntity; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | import org.springframework.lang.Nullable; 10 | 11 | import javax.persistence.*; 12 | import java.util.Set; 13 | 14 | @Entity(name = "users") 15 | @Getter 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class UserEntity extends BaseEntity { 19 | 20 | @Column(nullable = false, unique = true) 21 | String username; 22 | @Column(nullable = false) 23 | @Setter 24 | String password; 25 | @Column(nullable = false, unique = true) 26 | String email; 27 | @Nullable 28 | @Setter 29 | String bio; 30 | @Nullable 31 | @Setter 32 | String image; 33 | 34 | @OneToMany(mappedBy = "author", cascade = CascadeType.ALL, fetch = FetchType.LAZY) 35 | Set authoredArticles; 36 | 37 | @ManyToMany(fetch = FetchType.LAZY, mappedBy = "likers") 38 | Set likedArticles; 39 | 40 | @ManyToMany(fetch = FetchType.LAZY) 41 | @JoinTable(name = "followers", 42 | joinColumns = @JoinColumn(name = "following_id"), 43 | inverseJoinColumns = @JoinColumn(name = "follower_id")) 44 | Set followers; 45 | 46 | @ManyToMany(fetch = FetchType.LAZY, mappedBy = "followers") 47 | Set following; 48 | } 49 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/users/UsersRepository.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.users; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | @Repository 7 | public interface UsersRepository extends JpaRepository { 8 | } 9 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/java/com/scaler/blog_app/users/UsersService.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.users; 2 | 3 | public class UsersService { 4 | } 5 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7766 3 | spring: 4 | datasource: 5 | driver-class-name: org.h2.Driver 6 | url: jdbc:h2:file:./blog;DB_CLOSE_DELAY=-1 7 | jpa: 8 | hibernate: 9 | ddl-auto: update 10 | show-sql: true 11 | properties: 12 | hibernate: 13 | format_sql: true -------------------------------------------------------------------------------- /05/spring/blog_app/src/test/java/com/scaler/blog_app/BlogAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BlogAppApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/test/java/com/scaler/blog_app/articles/ArticlesControllerTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | import static org.junit.jupiter.api.Assertions.assertEquals; 8 | 9 | @SpringBootTest 10 | public class ArticlesControllerTests { 11 | 12 | @Autowired 13 | private ArticlesController articlesController; 14 | 15 | @Test 16 | public void getArticlesWorks() { 17 | var result = articlesController.getArticles(); 18 | assertEquals(0, result.size()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/test/java/com/scaler/blog_app/articles/ArticlesRepositoryTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.articles; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 6 | 7 | @DataJpaTest 8 | public class ArticlesRepositoryTests { 9 | @Autowired 10 | private ArticlesRepository articlesRepository; 11 | 12 | 13 | @Test 14 | public void findAllArticlesWorks() { 15 | var articles = articlesRepository.findAll(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /05/spring/blog_app/src/test/java/com/scaler/blog_app/common/StringModifierServiceTests.java: -------------------------------------------------------------------------------- 1 | package com.scaler.blog_app.common; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | public class StringModifierServiceTests { 8 | private StringModifierService strModSvc; 9 | 10 | public StringModifierServiceTests() { 11 | strModSvc = new StringModifierService(); 12 | } 13 | 14 | @Test 15 | public void removeSpecialCharactersWorks() { 16 | var input = "Hello World!"; 17 | var expected = "Hello World"; 18 | var actual = strModSvc.removeSpecialCharacters(input); 19 | assertEquals(expected, actual); 20 | } 21 | 22 | @Test 23 | public void slugifyWorks() { 24 | var input = "Hello World!"; 25 | var expected = "hello-world"; 26 | var actual = strModSvc.slugify(input); 27 | assertEquals(expected, actual); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Projects - Jule 2022 2 | 3 | ## REST APIs 4 | 5 | | entities ➡️
actions ⬇️ | /tasks | /tasks/12 | 6 | |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| 7 | | GET | read all tasks

usually uses query params for search/filter/sort

?order=date (ORDER BY DATE DESC)

?due_by=20220505 (WHERE due_date < date(20220505)) | get details of task id 12 | 8 | | POST | create a new task
body will contain title, due date etc


(task id will be generated by server) | ❌

usually we do not have POST requests on individual entities | 9 | | PUT | ❌

usually we do not have PUT requests on collections | create a new task
body will contain title, due date etc
new task with id 12 will be created (or overwritten)


(task id generated by client) | 10 | | PATCH | ❌

usually we do not have PATCH requests on collections | update an existing task
body can contain new title, or new due date
| 11 | | DELETE | ❌

usually we do not have DELETE requests on collections | delete task id 12 | 12 | --------------------------------------------------------------------------------