mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:35:50 +00:00
merged with upstream
This commit is contained in:
commit
2b41f9e11b
184 changed files with 23753 additions and 5248 deletions
13
.devcontainer/Dockerfile
Normal file
13
.devcontainer/Dockerfile
Normal file
|
@ -0,0 +1,13 @@
|
|||
ARG VARIANT=17-bullseye
|
||||
FROM mcr.microsoft.com/vscode/devcontainers/java:0-${VARIANT}
|
||||
|
||||
ARG NODE_VERSION="none"
|
||||
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
||||
|
||||
ARG USER=vscode
|
||||
VOLUME /home/$USER/.m2
|
||||
VOLUME /home/$USER/.gradle
|
||||
|
||||
ARG JAVA_VERSION=17.0.7-ms
|
||||
RUN sudo mkdir /home/$USER/.m2 /home/$USER/.gradle && sudo chown $USER:$USER /home/$USER/.m2 /home/$USER/.gradle
|
||||
RUN bash -lc '. /usr/local/sdkman/bin/sdkman-init.sh && sdk install java $JAVA_VERSION && sdk use java $JAVA_VERSION'
|
32
.devcontainer/devcontainer.json
Normal file
32
.devcontainer/devcontainer.json
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "Petclinic",
|
||||
"dockerFile": "Dockerfile",
|
||||
"runArgs": [
|
||||
"--cap-add=SYS_PTRACE",
|
||||
"--security-opt",
|
||||
"seccomp=unconfined",
|
||||
"--mount",
|
||||
"type=bind,source=${env:HOME}/.m2,target=/home/vscode/.m2",
|
||||
"--mount",
|
||||
"type=bind,source=${env:HOME}/.gradle,target=/home/vscode/.gradle",
|
||||
"--env",
|
||||
"GRADLE_USER_HOME=/home/vscode/.gradle"
|
||||
],
|
||||
"initializeCommand": "mkdir -p ${env:HOME}/.m2 ${env:HOME}/.gradle",
|
||||
"postCreateCommand": "sudo chown vscode:vscode /home/vscode/.m2 /home/vscode/.gradle",
|
||||
"remoteUser": "vscode",
|
||||
"features": {
|
||||
"docker-in-docker": "latest"
|
||||
},
|
||||
"extensions": [
|
||||
"vscjava.vscode-java-pack",
|
||||
"redhat.vscode-xml",
|
||||
"vmware.vscode-boot-dev-pack",
|
||||
"mhutchie.git-graph"
|
||||
],
|
||||
"forwardPorts": [8080],
|
||||
"settings": {
|
||||
"java.import.gradle.enabled": false,
|
||||
"java.server.launchMode": "Standard"
|
||||
}
|
||||
}
|
|
@ -10,3 +10,12 @@ indent_style = space
|
|||
[*.{java,xml}]
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
|
||||
[{pom,wro}.xml]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
[*.{html,sql,less}]
|
||||
indent_size = 2
|
||||
|
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
mvnw text eol=lf
|
||||
*.java text eol=lf
|
29
.github/workflows/maven-build.yml
vendored
Normal file
29
.github/workflows/maven-build.yml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
name: Java CI with Maven
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [ '17' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up JDK ${{matrix.java}}
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: ${{matrix.java}}
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
- name: Build with Maven Wrapper
|
||||
run: ./mvnw -B package
|
10
.gitignore
vendored
10
.gitignore
vendored
|
@ -1,7 +1,17 @@
|
|||
target/*
|
||||
bin/*
|
||||
build/*
|
||||
.gradle/*
|
||||
.settings/*
|
||||
.classpath
|
||||
.project
|
||||
.factorypath
|
||||
.attach_pid*
|
||||
.idea
|
||||
*.iml
|
||||
/target
|
||||
.sts4-cache/
|
||||
.vscode
|
||||
_site/
|
||||
*.css
|
||||
!petclinic.css
|
||||
|
|
9
.gitpod.yml
Normal file
9
.gitpod.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
image:
|
||||
file: ./.devcontainer/Dockerfile
|
||||
tasks:
|
||||
- before: sudo usermod -a -G sdkman gitpod && sudo usermod -a -G nvm gitpod && sudo chown -R gitpod /usr/local/sdkman /usr/local/share/nvm
|
||||
- init: ./mvnw install
|
||||
vscode:
|
||||
extensions:
|
||||
- vscjava.vscode-java-pack
|
||||
- redhat.vscode-xml
|
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0'
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
18
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
18
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
|
20
.springBeans
20
.springBeans
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beansProjectDescription>
|
||||
<version>1</version>
|
||||
<pluginVersion><![CDATA[3.5.0.201404011509-RELEASE]]></pluginVersion>
|
||||
<configSuffixes>
|
||||
<configSuffix><![CDATA[xml]]></configSuffix>
|
||||
</configSuffixes>
|
||||
<enableImports><![CDATA[false]]></enableImports>
|
||||
<configs>
|
||||
<config>src/main/resources/spring/datasource-config.xml</config>
|
||||
<config>src/main/resources/spring/mvc-core-config.xml</config>
|
||||
<config>src/main/resources/spring/mvc-view-config.xml</config>
|
||||
<config>src/main/resources/spring/business-config.xml</config>
|
||||
</configs>
|
||||
<autoconfigs>
|
||||
<config>src/main/resources/spring/tools-config.xml</config>
|
||||
</autoconfigs>
|
||||
<configSets>
|
||||
</configSets>
|
||||
</beansProjectDescription>
|
202
LICENSE.txt
Normal file
202
LICENSE.txt
Normal file
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
https://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
https://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
42
build.gradle
Normal file
42
build.gradle
Normal file
|
@ -0,0 +1,42 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.1.0'
|
||||
id 'io.spring.dependency-management' version '1.1.0'
|
||||
id 'org.graalvm.buildtools.native' version '0.9.22'
|
||||
}
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
group = 'org.springframework.samples'
|
||||
version = '3.1.0'
|
||||
sourceCompatibility = '17'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext.webjarsFontawesomeVersion = "4.7.0"
|
||||
ext.webjarsBootstrapVersion = "5.2.3"
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-cache'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation 'javax.cache:cache-api'
|
||||
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
|
||||
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}"
|
||||
runtimeOnly "org.webjars.npm:font-awesome:${webjarsFontawesomeVersion}"
|
||||
runtimeOnly 'com.github.ben-manes.caffeine:caffeine'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||
runtimeOnly 'org.postgresql:postgresql'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
23
docker-compose.yml
Normal file
23
docker-compose.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
version: "2.2"
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
ports:
|
||||
- "3306:3306"
|
||||
environment:
|
||||
- MYSQL_ROOT_PASSWORD=
|
||||
- MYSQL_ALLOW_EMPTY_PASSWORD=true
|
||||
- MYSQL_USER=petclinic
|
||||
- MYSQL_PASSWORD=petclinic
|
||||
- MYSQL_DATABASE=petclinic
|
||||
volumes:
|
||||
- "./conf.d:/etc/mysql/conf.d:ro"
|
||||
postgres:
|
||||
image: postgres:15.3
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=petclinic
|
||||
- POSTGRES_USER=petclinic
|
||||
- POSTGRES_DB=petclinic
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
240
gradlew
vendored
Executable file
240
gradlew
vendored
Executable file
|
@ -0,0 +1,240 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
91
gradlew.bat
vendored
Normal file
91
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
308
mvnw
vendored
Executable file
308
mvnw
vendored
Executable file
|
@ -0,0 +1,308 @@
|
|||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.2.0
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# JAVA_HOME - location of a JDK home dir
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /usr/local/etc/mavenrc ] ; then
|
||||
. /usr/local/etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.mavenrc" ] ; then
|
||||
. "$HOME/.mavenrc"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
darwin=false;
|
||||
mingw=false
|
||||
case "$(uname)" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
|
||||
else
|
||||
JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
if [ -r /etc/gentoo-release ] ; then
|
||||
JAVA_HOME=$(java-config --jre-home)
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
|
||||
fi
|
||||
|
||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)"
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
javaExecutable="$(which javac)"
|
||||
if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=$(which readlink)
|
||||
if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
|
||||
if $darwin ; then
|
||||
javaHome="$(dirname "\"$javaExecutable\"")"
|
||||
javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
|
||||
else
|
||||
javaExecutable="$(readlink -f "\"$javaExecutable\"")"
|
||||
fi
|
||||
javaHome="$(dirname "\"$javaExecutable\"")"
|
||||
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
|
||||
JAVA_HOME="$javaHome"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$JAVACMD" ] ; then
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||
echo " We cannot execute $JAVACMD" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
basedir="$1"
|
||||
wdir="$1"
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||
if [ -d "${wdir}" ]; then
|
||||
wdir=$(cd "$wdir/.." || exit 1; pwd)
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
printf '%s' "$(cd "$basedir" || exit 1; pwd)"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
concat_lines() {
|
||||
if [ -f "$1" ]; then
|
||||
# Remove \r in case we run on Windows within Git Bash
|
||||
# and check out the repository with auto CRLF management
|
||||
# enabled. Otherwise, we may read lines that are delimited with
|
||||
# \r\n and produce $'-Xarg\r' rather than -Xarg due to word
|
||||
# splitting rules.
|
||||
tr -s '\r\n' ' ' < "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
log() {
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
printf '%s\n' "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
|
||||
log "$MAVEN_PROJECTBASEDIR"
|
||||
|
||||
##########################################################################################
|
||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
##########################################################################################
|
||||
wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
|
||||
if [ -r "$wrapperJarPath" ]; then
|
||||
log "Found $wrapperJarPath"
|
||||
else
|
||||
log "Couldn't find $wrapperJarPath, downloading it ..."
|
||||
|
||||
if [ -n "$MVNW_REPOURL" ]; then
|
||||
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
||||
else
|
||||
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
||||
fi
|
||||
while IFS="=" read -r key value; do
|
||||
# Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
|
||||
safeValue=$(echo "$value" | tr -d '\r')
|
||||
case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
|
||||
esac
|
||||
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
log "Downloading from: $wrapperUrl"
|
||||
|
||||
if $cygwin; then
|
||||
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
|
||||
fi
|
||||
|
||||
if command -v wget > /dev/null; then
|
||||
log "Found wget ... using wget"
|
||||
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
||||
else
|
||||
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
|
||||
fi
|
||||
elif command -v curl > /dev/null; then
|
||||
log "Found curl ... using curl"
|
||||
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
|
||||
else
|
||||
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
|
||||
fi
|
||||
else
|
||||
log "Falling back to using Java to download"
|
||||
javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
|
||||
# For Cygwin, switch paths to Windows format before running javac
|
||||
if $cygwin; then
|
||||
javaSource=$(cygpath --path --windows "$javaSource")
|
||||
javaClass=$(cygpath --path --windows "$javaClass")
|
||||
fi
|
||||
if [ -e "$javaSource" ]; then
|
||||
if [ ! -e "$javaClass" ]; then
|
||||
log " - Compiling MavenWrapperDownloader.java ..."
|
||||
("$JAVA_HOME/bin/javac" "$javaSource")
|
||||
fi
|
||||
if [ -e "$javaClass" ]; then
|
||||
log " - Running MavenWrapperDownloader.java ..."
|
||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
##########################################################################################
|
||||
# End of extension
|
||||
##########################################################################################
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven wrapper jar file
|
||||
wrapperSha256Sum=""
|
||||
while IFS="=" read -r key value; do
|
||||
case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
|
||||
esac
|
||||
done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
if [ -n "$wrapperSha256Sum" ]; then
|
||||
wrapperSha256Result=false
|
||||
if command -v sha256sum > /dev/null; then
|
||||
if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
|
||||
wrapperSha256Result=true
|
||||
fi
|
||||
elif command -v shasum > /dev/null; then
|
||||
if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
|
||||
wrapperSha256Result=true
|
||||
fi
|
||||
else
|
||||
echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
|
||||
echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
|
||||
exit 1
|
||||
fi
|
||||
if [ $wrapperSha256Result = false ]; then
|
||||
echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
|
||||
echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
|
||||
echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*"
|
||||
export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
# shellcheck disable=SC2086 # safe args
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
$MAVEN_DEBUG_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
205
mvnw.cmd
vendored
Normal file
205
mvnw.cmd
vendored
Normal file
|
@ -0,0 +1,205 @@
|
|||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.2.0
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
|
||||
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
||||
|
||||
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Found %WRAPPER_JAR%
|
||||
)
|
||||
) else (
|
||||
if not "%MVNW_REPOURL%" == "" (
|
||||
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
|
||||
)
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %WRAPPER_URL%
|
||||
)
|
||||
|
||||
powershell -Command "&{"^
|
||||
"$webclient = new-object System.Net.WebClient;"^
|
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||
"}"^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
|
||||
"}"
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
|
||||
SET WRAPPER_SHA_256_SUM=""
|
||||
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
|
||||
)
|
||||
IF NOT %WRAPPER_SHA_256_SUM%=="" (
|
||||
powershell -Command "&{"^
|
||||
"$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
|
||||
"If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
|
||||
" Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
|
||||
" Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
|
||||
" Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
|
||||
" exit 1;"^
|
||||
"}"^
|
||||
"}"
|
||||
if ERRORLEVEL 1 goto error
|
||||
)
|
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||
@REM work with both Windows and non-Windows executions.
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
%MAVEN_JAVA_EXE% ^
|
||||
%JVM_CONFIG_MAVEN_PROPS% ^
|
||||
%MAVEN_OPTS% ^
|
||||
%MAVEN_DEBUG_OPTS% ^
|
||||
-classpath %WRAPPER_JAR% ^
|
||||
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
|
||||
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
|
||||
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%"=="on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
|
||||
|
||||
cmd /C exit /B %ERROR_CODE%
|
785
pom.xml
785
pom.xml
|
@ -1,434 +1,415 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.samples</groupId>
|
||||
<artifactId>spring-petclinic</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.samples</groupId>
|
||||
<artifactId>spring-petclinic</artifactId>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
|
||||
<name>petclinic</name>
|
||||
<packaging>war</packaging>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</parent>
|
||||
<name>petclinic</name>
|
||||
|
||||
<properties>
|
||||
<properties>
|
||||
|
||||
<!-- Generic properties -->
|
||||
<java.version>1.7</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!-- Generic properties -->
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set -DnewVersion=... -->
|
||||
<project.build.outputTimestamp>2023-05-10T07:42:50Z</project.build.outputTimestamp>
|
||||
|
||||
<!-- Spring -->
|
||||
<spring-io-platform.version>1.1.3.RELEASE</spring-io-platform.version>
|
||||
<spring-data-jdbc.version>1.1.0.RELEASE</spring-data-jdbc.version>
|
||||
<!-- Web dependencies -->
|
||||
<webjars-bootstrap.version>5.2.3</webjars-bootstrap.version>
|
||||
<webjars-font-awesome.version>4.7.0</webjars-font-awesome.version>
|
||||
|
||||
<checkstyle.version>10.11.0</checkstyle.version>
|
||||
<jacoco.version>0.8.10</jacoco.version>
|
||||
<libsass.version>0.2.29</libsass.version>
|
||||
<lifecycle-mapping>1.0.0</lifecycle-mapping>
|
||||
<maven-checkstyle.version>3.2.2</maven-checkstyle.version>
|
||||
<nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version>
|
||||
<spring-format.version>0.0.39</spring-format.version>
|
||||
|
||||
<!-- Java EE / Java SE dependencies -->
|
||||
<tomcat.version>7.0.59</tomcat.version>
|
||||
</properties>
|
||||
|
||||
<!-- Test -->
|
||||
<assertj.version>2.2.0</assertj.version>
|
||||
<dependencies>
|
||||
<!-- Spring and Spring Boot dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Dates -->
|
||||
<jodatime-hibernate.version>1.4</jodatime-hibernate.version>
|
||||
<jodatime-jsptags.version>1.1.1</jodatime-jsptags.version>
|
||||
<jadira-usertype-core.version>3.2.0.GA</jadira-usertype-core.version>
|
||||
<!-- Databases - Uses H2 by default -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- MySql -->
|
||||
<mysql-driver.version>5.1.36</mysql-driver.version>
|
||||
<!-- caching -->
|
||||
<dependency>
|
||||
<groupId>javax.cache</groupId>
|
||||
<artifactId>cache-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Web dependencies -->
|
||||
<webjars-bootstrap.version>2.3.0</webjars-bootstrap.version>
|
||||
<webjars-jquery-ui.version>1.10.3</webjars-jquery-ui.version>
|
||||
<webjars-jquery.version>2.0.3-1</webjars-jquery.version>
|
||||
<dandelion.version>1.1.1</dandelion.version>
|
||||
<dandelion.datatables.version>1.1.0</dandelion.datatables.version>
|
||||
<!-- webjars -->
|
||||
<dependency>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<version>${webjars-bootstrap.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
<artifactId>font-awesome</artifactId>
|
||||
<version>${webjars-font-awesome.version}</version>
|
||||
</dependency>
|
||||
<!-- end of webjars -->
|
||||
|
||||
<cobertura.version>2.7</cobertura.version>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</properties>
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:https://github.com/liatrio/spring-petclinic/</developerConnection>
|
||||
<tag>spring-petclinic-1.0.0</tag>
|
||||
</scm>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<!-- Import the maven Spring IO Platform Bill Of Materials (BOM) -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
<version>${spring-format.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>validate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-java</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<message>This build requires at least Java ${java.version}, update your JVM, and run the build again</message>
|
||||
<version>${java.version}</version>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${maven-checkstyle.version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.spring.platform</groupId>
|
||||
<artifactId>platform-bom</artifactId>
|
||||
<version>${spring-io-platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>${checkstyle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spring.nohttp</groupId>
|
||||
<artifactId>nohttp-checkstyle</artifactId>
|
||||
<version>${nohttp-checkstyle.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>nohttp-checkstyle-validation</id>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<configLocation>src/checkstyle/nohttp-checkstyle.xml</configLocation>
|
||||
<suppressionsLocation>src/checkstyle/nohttp-checkstyle-suppressions.xml</suppressionsLocation>
|
||||
<sourceDirectories>${basedir}</sourceDirectories>
|
||||
<includes>**/*</includes>
|
||||
<excludes>**/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class</excludes>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<!-- Spring Boot Actuator displays build-related information
|
||||
if a META-INF/build-info.properties file is present -->
|
||||
<goals>
|
||||
<goal>build-info</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<additionalProperties>
|
||||
<encoding.source>${project.build.sourceEncoding}</encoding.source>
|
||||
<encoding.reporting>${project.reporting.outputEncoding}</encoding.reporting>
|
||||
<java.source>${java.version}</java.source>
|
||||
<java.target>${java.version}</java.target>
|
||||
</additionalProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>${jacoco.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jadira.usertype</groupId>
|
||||
<artifactId>usertype.core</artifactId>
|
||||
<version>${jadira-usertype-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jasper-el</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Spring Boot Actuator displays build-related information if a git.properties
|
||||
file is present at the classpath -->
|
||||
<plugin>
|
||||
<groupId>io.github.git-commit-id</groupId>
|
||||
<artifactId>git-commit-id-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp.jstl</groupId>
|
||||
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.taglibs</groupId>
|
||||
<artifactId>taglibs-standard-jstlel</artifactId>
|
||||
</dependency>
|
||||
<!-- JSon -->
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- SPRING, SPRING, SPRINGITY SPRING -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jdbc-core</artifactId>
|
||||
<version>${spring-data-jdbc.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
<!-- because Spring Data usually comes with a slightly older version of Spring -->
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<!-- used for EhCacheCacheManager -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-oxm</artifactId>
|
||||
</dependency>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<!-- Database connection pool
|
||||
See here for more details on commons-dbcp versus tomcat-jdbc:
|
||||
http://blog.ippon.fr/2013/03/13/improving-the-performance-of-the-spring-petclinic-sample-application-part-3-of-5/
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-jdbc</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging with SLF4J & LogBack -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Date and Time -->
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time-hibernate</artifactId>
|
||||
<version>${jodatime-hibernate.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time-jsptags</artifactId>
|
||||
<version>${jodatime-jsptags.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Databases - Uses HSQL by default -->
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- For MySql only -->
|
||||
<!--dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql-driver.version}</version>
|
||||
</dependency-->
|
||||
|
||||
<!-- HIBERNATE -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-ehcache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.ehcache</groupId>
|
||||
<artifactId>ehcache-core</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- Webjars (static dependencies distributed as JAR files) -->
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<version>${webjars-bootstrap.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>jquery-ui</artifactId>
|
||||
<version>${webjars-jquery-ui.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>jquery</artifactId>
|
||||
<version>${webjars-jquery.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test Artifacts -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Dandelion -->
|
||||
<dependency>
|
||||
<groupId>com.github.dandelion</groupId>
|
||||
<artifactId>dandelion-jsp</artifactId>
|
||||
<version>${dandelion.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.dandelion</groupId>
|
||||
<artifactId>datatables-jsp</artifactId>
|
||||
<version>${dandelion.datatables.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.dandelion</groupId>
|
||||
<artifactId>datatables-export-itext</artifactId>
|
||||
<version>${dandelion.datatables.version}</version>
|
||||
</dependency>
|
||||
<!-- temporary fix: below dependency should not be necessary as it is a transitive dependency.
|
||||
For some reason we can't build the app unless it is a first level dependency -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- Maven plugin versions are mentioned in order to guarantee the build reproducibility in the long term -->
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<!-- declared explicitly so Spring config files can be placed next to their corresponding JUnit test class -->
|
||||
<directory>${project.basedir}/src/test/java</directory>
|
||||
</testResource>
|
||||
<testResource>
|
||||
<directory>${project.basedir}/src/test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>css</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.0</version>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>unpack</id>
|
||||
<?m2e execute onConfiguration,onIncremental?>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<compilerArguments>
|
||||
<Xlint/>
|
||||
</compilerArguments>
|
||||
<verbose>true</verbose>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<showWarnings>true</showWarnings>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.webjars.npm</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<version>${webjars-bootstrap.version}</version>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
<outputDirectory>${project.build.directory}/webjars</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.gitlab.haynes</groupId>
|
||||
<artifactId>libsass-maven-plugin</artifactId>
|
||||
<version>${libsass.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
<?m2e execute onConfiguration,onIncremental?>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<inputPath>${basedir}/src/main/scss/</inputPath>
|
||||
<outputPath>${basedir}/src/main/resources/static/resources/css/</outputPath>
|
||||
<includePath>${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/</includePath>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>m2e</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>m2e.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!-- This plugin's configuration is used to store Eclipse m2e settings
|
||||
only. It has no influence on the Maven build itself. -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.13</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<warName>petclinic</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<configuration>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
<wtpversion>2.0</wtpversion>
|
||||
<sourceIncludes>
|
||||
<sourceInclude>**/*.*</sourceInclude>
|
||||
</sourceIncludes>
|
||||
<additionalBuildcommands>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.core.springbuilder</name>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
</buildCommand>
|
||||
</additionalBuildcommands>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
<projectnature>org.eclipse.m2e.core.maven2Nature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.tomcat.maven</groupId>
|
||||
<artifactId>tomcat7-maven-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<configuration>
|
||||
<server>tomcat-development-server</server>
|
||||
<port>9966</port>
|
||||
<path>/petclinic</path>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>${cobertura.version}</version>
|
||||
<configuration>
|
||||
<check/>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>${lifecycle-mapping}</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<versionRange>[1,)</versionRange>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
<goal>check</goal>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<versionRange>[1,)</versionRange>
|
||||
<goals>
|
||||
<goal>build-info</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>io.spring.javaformat</groupId>
|
||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||
<versionRange>[0,)</versionRange>
|
||||
<goals>
|
||||
<goal>validate</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<!-- integrate maven-cobertura-plugin to project site -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>${cobertura.version}</version>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<check/>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>snapshots</id>
|
||||
<url>http://nexus:8081/nexus/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<url>http://nexus:8081/nexus/content/repositories/releases</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<url>demopetclinic</url>
|
||||
</project>
|
||||
|
|
285
readme.md
285
readme.md
|
@ -1,207 +1,158 @@
|
|||
# Spring PetClinic Sample Application
|
||||
# Spring PetClinic Sample Application [](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)
|
||||
|
||||
[](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918)
|
||||
|
||||
|
||||
|
||||
|
||||
## Understanding the Spring Petclinic application with a few diagrams
|
||||
<a href="https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application">See the presentation here</a>
|
||||
|
||||
## Running petclinic locally
|
||||
Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). You can build a jar file and run it from the command line (it should work just as well with Java 17 or newer):
|
||||
|
||||
|
||||
```
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
mvn tomcat7:run
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
cd spring-petclinic
|
||||
./mvnw package
|
||||
java -jar target/*.jar
|
||||
```
|
||||
|
||||
You can then access petclinic here: http://localhost:9966/petclinic/
|
||||
You can then access petclinic at http://localhost:8080/
|
||||
|
||||
<img width="1042" alt="petclinic-screenshot" src="https://cloud.githubusercontent.com/assets/838318/19727082/2aee6d6c-9b8e-11e6-81fe-e889a5ddfded.png">
|
||||
|
||||
Or you can run it from Maven directly using the Spring Boot Maven plugin. If you do this, it will pick up changes that you make in the project immediately (changes to Java source files require a compile as well - most people use an IDE for this):
|
||||
|
||||
```
|
||||
./mvnw spring-boot:run
|
||||
```
|
||||
|
||||
> NOTE: If you prefer to use Gradle, you can build the app using `./gradlew build` and look for the jar file in `build/libs`.
|
||||
|
||||
## Building a Container
|
||||
|
||||
There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
|
||||
|
||||
```
|
||||
./mvnw spring-boot:build-image
|
||||
```
|
||||
|
||||
## In case you find a bug/suggested improvement for Spring Petclinic
|
||||
Our issue tracker is available here: https://github.com/spring-projects/spring-petclinic/issues
|
||||
Our issue tracker is available [here](https://github.com/spring-projects/spring-petclinic/issues)
|
||||
|
||||
|
||||
## Database configuration
|
||||
|
||||
In its default configuration, Petclinic uses an in-memory database (HSQLDB) which
|
||||
gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed.
|
||||
Note that whenever the database type is changed, the data-access.properties file needs to be updated and the mysql-connector-java artifact from the pom.xml needs to be uncommented.
|
||||
In its default configuration, Petclinic uses an in-memory database (H2) which
|
||||
gets populated at startup with data. The h2 console is exposed at `http://localhost:8080/h2-console`,
|
||||
and it is possible to inspect the content of the database using the `jdbc:h2:mem:testdb` url.
|
||||
|
||||
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL.
|
||||
|
||||
You may start a MySql database with docker:
|
||||
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
|
||||
|
||||
```
|
||||
docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
|
||||
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.0
|
||||
```
|
||||
|
||||
## Working with Petclinic in Eclipse/STS
|
||||
or
|
||||
|
||||
### prerequisites
|
||||
```
|
||||
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:15.2
|
||||
```
|
||||
|
||||
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)
|
||||
and for [PostgreSQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/postgres/petclinic_db_setup_postgres.txt).
|
||||
|
||||
## Compiling the CSS
|
||||
|
||||
There is a `petclinic.css` in `src/main/resources/static/resources/css`. It was generated from the `petclinic.scss` source, combined with the [Bootstrap](https://getbootstrap.com/) library. If you make changes to the `scss`, or upgrade Bootstrap, you will need to re-compile the CSS resources using the Maven profile "css", i.e. `./mvnw package -P css`. There is no build profile for Gradle to compile the CSS.
|
||||
|
||||
## Working with Petclinic in your IDE
|
||||
|
||||
### Prerequisites
|
||||
The following items should be installed in your system:
|
||||
* Maven 3 (http://www.sonatype.com/books/mvnref-book/reference/installation.html)
|
||||
* git command line tool (https://help.github.com/articles/set-up-git)
|
||||
* Eclipse with the m2e plugin (m2e is installed by default when using the STS (http://www.springsource.org/sts) distribution of Eclipse)
|
||||
|
||||
Note: when m2e is available, there is an m2 icon in Help -> About dialog.
|
||||
If m2e is not there, just follow the install process here: http://eclipse.org/m2e/download/
|
||||
|
||||
* Java 17 or newer (full JDK, not a JRE).
|
||||
* [git command line tool](https://help.github.com/articles/set-up-git)
|
||||
* Your preferred IDE
|
||||
* Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is
|
||||
not there, follow the install process [here](https://www.eclipse.org/m2e/)
|
||||
* [Spring Tools Suite](https://spring.io/tools) (STS)
|
||||
* [IntelliJ IDEA](https://www.jetbrains.com/idea/)
|
||||
* [VS Code](https://code.visualstudio.com)
|
||||
|
||||
### Steps:
|
||||
|
||||
1) In the command line
|
||||
```
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
```
|
||||
2) Inside Eclipse
|
||||
```
|
||||
File -> Import -> Maven -> Existing Maven project
|
||||
```
|
||||
1) On the command line run:
|
||||
```
|
||||
git clone https://github.com/spring-projects/spring-petclinic.git
|
||||
```
|
||||
2) Inside Eclipse or STS:
|
||||
```
|
||||
File -> Import -> Maven -> Existing Maven project
|
||||
```
|
||||
|
||||
Then either build on the command line `./mvnw generate-resources` or use the Eclipse launcher (right click on project and `Run As -> Maven install`) to generate the css. Run the application main method by right-clicking on it and choosing `Run As -> Java Application`.
|
||||
|
||||
3) Inside IntelliJ IDEA
|
||||
In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button.
|
||||
|
||||
CSS files are generated from the Maven build. You can build them on the command line `./mvnw generate-resources` or right-click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`.
|
||||
|
||||
A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right-clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`.
|
||||
|
||||
4) Navigate to Petclinic
|
||||
|
||||
Visit [http://localhost:8080](http://localhost:8080) in your browser.
|
||||
|
||||
|
||||
## Looking for something in particular?
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th width="300px">Java Config</th><th width="300px"></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Java Config branch</td>
|
||||
<td>
|
||||
Petclinic uses XML configuration by default. In case you'd like to use Java Config instead, there is a Java Config branch available <a href="https://github.com/spring-projects/spring-petclinic/tree/javaconfig">here</a>. Thanks to Antoine Rey for his contribution.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="300px">Inside the 'Web' layer</th><th width="300px">Files</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring MVC - XML integration</td>
|
||||
<td><a href="/src/main/resources/spring/mvc-view-config.xml">mvc-view-config.xml</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring MVC - ContentNegotiatingViewResolver</td>
|
||||
<td><a href="/src/main/resources/spring/mvc-view-config.xml">mvc-view-config.xml</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>JSP custom tags</td>
|
||||
<td>
|
||||
<a href="/src/main/webapp/WEB-INF/tags">WEB-INF/tags</a>
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp">createOrUpdateOwnerForm.jsp</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>webjars</td>
|
||||
<td>
|
||||
<a href="/pom.xml">webjars declaration inside pom.xml</a> <br />
|
||||
<a href="/src/main/resources/spring/mvc-core-config.xml#L24">Resource mapping in Spring configuration</a> <br />
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp#L12">sample usage in JSP</a></td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Dandelion-datatables</td>
|
||||
<td>
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp">ownersList.jsp</a>
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp">vetList.jsp</a>
|
||||
<a href="/src/main/webapp/WEB-INF/web.xml">web.xml</a>
|
||||
<a href="/src/main/resources/dandelion/datatables/datatables.properties">datatables.properties</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Thymeleaf branch</td>
|
||||
<td>
|
||||
<a href="http://www.thymeleaf.org/petclinic.html">See here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Branch using GemFire and Spring Data GemFire instead of ehcache (thanks Bijoy Choudhury)</td>
|
||||
<td>
|
||||
<a href="https://github.com/bijoych/spring-petclinic-gemfire">See here</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|Spring Boot Configuration | Class or Java property files |
|
||||
|--------------------------|---|
|
||||
|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) |
|
||||
|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) |
|
||||
|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) |
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th width="300px">'Service' and 'Repository' layers</th><th width="300px">Files</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Transactions</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java">ClinicServiceImpl.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Cache</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/tools-config.xml">tools-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java">ClinicServiceImpl.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Bean Profiles</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java">ClinicServiceJdbcTests.java</a>
|
||||
<a href="/src/main/webapp/WEB-INF/web.xml">web.xml</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>JdbcTemplate</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/jdbc">jdbc folder</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>JPA</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/jpa">jpa folder</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring Data JPA</td>
|
||||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/repository/springdatajpa">springdatajpa folder</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
## Interesting Spring Petclinic branches and forks
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th width="300px">Others</th><th width="300px">Files</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Gradle branch</td>
|
||||
<td>
|
||||
<a href="https://github.com/whimet/spring-petclinic">See here</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
The Spring Petclinic "main" branch in the [spring-projects](https://github.com/spring-projects/spring-petclinic)
|
||||
GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. There are
|
||||
[quite a few forks](https://spring-petclinic.github.io/docs/forks.html) in the GitHub org
|
||||
[spring-petclinic](https://github.com/spring-petclinic). If you are interested in using a different technology stack to implement the Pet Clinic, please join the community there.
|
||||
|
||||
|
||||
## Interaction with other open source projects
|
||||
|
||||
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found some bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
|
||||
One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days.
|
||||
Here is a list of them:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th width="300px">Name</th>
|
||||
<th width="300px"> Issue </th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Spring JDBC: simplify usage of NamedParameterJdbcTemplate</td>
|
||||
<td> <a href="https://jira.springsource.org/browse/SPR-10256"> SPR-10256</a> and <a href="https://jira.springsource.org/browse/SPR-10257"> SPR-10257</a> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility</td>
|
||||
<td>
|
||||
<a href="https://hibernate.atlassian.net/browse/HV-790"> HV-790</a> and <a href="https://hibernate.atlassian.net/browse/HV-792"> HV-792</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Spring Data: provide more flexibility when working with JPQL queries</td>
|
||||
<td>
|
||||
<a href="https://jira.springsource.org/browse/DATAJPA-292"> DATAJPA-292</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Eclipse: validation bug when working with .tag/.tagx files (has only been fixed for Eclipse 4.3 (Kepler)). <a href="https://github.com/spring-projects/spring-petclinic/issues/14">See here for more details.</a></td>
|
||||
<td>
|
||||
<a href="https://issuetracker.springsource.com/browse/STS-3294"> STS-3294</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
| Name | Issue |
|
||||
|------|-------|
|
||||
| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://jira.springsource.org/browse/SPR-10256) and [SPR-10257](https://jira.springsource.org/browse/SPR-10257) |
|
||||
| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) |
|
||||
| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://jira.springsource.org/browse/DATAJPA-292) |
|
||||
|
||||
|
||||
# Contributing
|
||||
|
||||
The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, features requests and submitting pull requests.
|
||||
|
||||
For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at <https://editorconfig.org>. If you have not previously done so, please fill out and submit the [Contributor License Agreement](https://cla.pivotal.io/sign/spring).
|
||||
|
||||
# License
|
||||
|
||||
The Spring PetClinic sample application is released under version 2.0 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
||||
[spring-petclinic]: https://github.com/spring-projects/spring-petclinic
|
||||
[spring-framework-petclinic]: https://github.com/spring-petclinic/spring-framework-petclinic
|
||||
[spring-petclinic-angularjs]: https://github.com/spring-petclinic/spring-petclinic-angularjs
|
||||
[javaconfig branch]: https://github.com/spring-petclinic/spring-framework-petclinic/tree/javaconfig
|
||||
[spring-petclinic-angular]: https://github.com/spring-petclinic/spring-petclinic-angular
|
||||
[spring-petclinic-microservices]: https://github.com/spring-petclinic/spring-petclinic-microservices
|
||||
[spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs
|
||||
[spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql
|
||||
[spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin
|
||||
[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest
|
||||
|
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
|
@ -0,0 +1 @@
|
|||
rootProject.name = 'spring-petclinic'
|
11
src/checkstyle/nohttp-checkstyle-suppressions.xml
Normal file
11
src/checkstyle/nohttp-checkstyle-suppressions.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE suppressions PUBLIC
|
||||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||
<suppressions>
|
||||
<suppress files="node_modules/.*" checks=".*"/>
|
||||
<suppress files="node/.*" checks=".*"/>
|
||||
<suppress files="build/.*" checks=".*"/>
|
||||
<suppress files="[\\/]build.log" checks="NoHttp"/>
|
||||
<suppress files=".+\.(jar|git|ico|p12|gif|jks|jpg|svg)" checks="NoHttp"/>
|
||||
</suppressions>
|
7
src/checkstyle/nohttp-checkstyle.xml
Normal file
7
src/checkstyle/nohttp-checkstyle.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
|
||||
"https://checkstyle.org/dtds/configuration_1_2.dtd">
|
||||
<module name="com.puppycrawl.tools.checkstyle.Checker">
|
||||
<module name="io.spring.nohttp.checkstyle.check.NoHttpCheck"/>
|
||||
</module>
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||
|
||||
/**
|
||||
* PetClinic Spring Boot Application.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ImportRuntimeHints(PetClinicRuntimeHints.class)
|
||||
public class PetClinicApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PetClinicApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
|
||||
public class PetClinicRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.resources().registerPattern("db/*"); // https://github.com/spring-projects/spring-boot/issues/32654
|
||||
hints.resources().registerPattern("messages/*");
|
||||
hints.resources().registerPattern("META-INF/resources/webjars/*");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -15,33 +15,37 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import java.io.Serializable;
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object with an id property. Used as a base class for objects needing this property.
|
||||
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
||||
* needing this property.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class BaseEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
protected Integer id;
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return (this.id == null);
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return this.id == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -15,13 +15,12 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as a base class for objects
|
||||
* needing these properties.
|
||||
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as
|
||||
* a base class for objects needing these properties.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
|
@ -29,20 +28,20 @@ import javax.persistence.MappedSuperclass;
|
|||
@MappedSuperclass
|
||||
public class NamedEntity extends BaseEntity {
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,153 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Digits;
|
||||
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an owner.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "owners")
|
||||
public class Owner extends Person {
|
||||
@Column(name = "address")
|
||||
@NotEmpty
|
||||
private String address;
|
||||
|
||||
@Column(name = "city")
|
||||
@NotEmpty
|
||||
private String city;
|
||||
|
||||
@Column(name = "telephone")
|
||||
@NotEmpty
|
||||
@Digits(fraction = 0, integer = 10)
|
||||
private String telephone;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
|
||||
private Set<Pet> pets;
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return this.city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return this.telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
protected Set<Pet> getPetsInternal() {
|
||||
if (this.pets == null) {
|
||||
this.pets = new HashSet<>();
|
||||
}
|
||||
return this.pets;
|
||||
}
|
||||
|
||||
protected void setPetsInternal(Set<Pet> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
public List<Pet> getPets() {
|
||||
List<Pet> sortedPets = new ArrayList<>(getPetsInternal());
|
||||
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
|
||||
return Collections.unmodifiableList(sortedPets);
|
||||
}
|
||||
|
||||
public void addPet(Pet pet) {
|
||||
getPetsInternal().add(pet);
|
||||
pet.setOwner(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
*
|
||||
* @param name to test
|
||||
* @return true if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name) {
|
||||
return getPet(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
*
|
||||
* @param name to test
|
||||
* @return true if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name, boolean ignoreNew) {
|
||||
name = name.toLowerCase();
|
||||
for (Pet pet : getPetsInternal()) {
|
||||
if (!ignoreNew || !pet.isNew()) {
|
||||
String compName = pet.getName();
|
||||
compName = compName.toLowerCase();
|
||||
if (compName.equals(name)) {
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
|
||||
.append("id", this.getId())
|
||||
.append("new", this.isNew())
|
||||
.append("lastName", this.getLastName())
|
||||
.append("firstName", this.getFirstName())
|
||||
.append("address", this.address)
|
||||
.append("city", this.city)
|
||||
.append("telephone", this.telephone)
|
||||
.toString();
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -15,10 +15,9 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an person.
|
||||
|
@ -28,29 +27,28 @@ import org.hibernate.validator.constraints.NotEmpty;
|
|||
@MappedSuperclass
|
||||
public class Person extends BaseEntity {
|
||||
|
||||
@Column(name = "first_name")
|
||||
@NotEmpty
|
||||
protected String firstName;
|
||||
@Column(name = "first_name")
|
||||
@NotEmpty
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "last_name")
|
||||
@NotEmpty
|
||||
protected String lastName;
|
||||
@Column(name = "last_name")
|
||||
@NotEmpty
|
||||
private String lastName;
|
||||
|
||||
public String getFirstName() {
|
||||
return this.firstName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return this.firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return this.lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return this.lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* Simple business object representing a pet.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "pets")
|
||||
public class Pet extends NamedEntity {
|
||||
|
||||
@Column(name = "birth_date")
|
||||
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
|
||||
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
||||
private DateTime birthDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "type_id")
|
||||
private PetType type;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "owner_id")
|
||||
private Owner owner;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
|
||||
private Set<Visit> visits;
|
||||
|
||||
public DateTime getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(DateTime birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public PetType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(PetType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Owner getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
protected void setOwner(Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
protected Set<Visit> getVisitsInternal() {
|
||||
if (this.visits == null) {
|
||||
this.visits = new HashSet<>();
|
||||
}
|
||||
return this.visits;
|
||||
}
|
||||
|
||||
protected void setVisitsInternal(Set<Visit> visits) {
|
||||
this.visits = visits;
|
||||
}
|
||||
|
||||
public List<Visit> getVisits() {
|
||||
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
|
||||
PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
|
||||
return Collections.unmodifiableList(sortedVisits);
|
||||
}
|
||||
|
||||
public void addVisit(Visit visit) {
|
||||
getVisitsInternal().add(visit);
|
||||
visit.setPet(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a veterinarian.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "vets")
|
||||
public class Vet extends Person {
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
|
||||
private Set<Specialty> specialties;
|
||||
|
||||
protected Set<Specialty> getSpecialtiesInternal() {
|
||||
if (this.specialties == null) {
|
||||
this.specialties = new HashSet<>();
|
||||
}
|
||||
return this.specialties;
|
||||
}
|
||||
|
||||
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
|
||||
this.specialties = specialties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
|
||||
PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
|
||||
return Collections.unmodifiableList(sortedSpecs);
|
||||
}
|
||||
|
||||
public int getNrOfSpecialties() {
|
||||
return getSpecialtiesInternal().size();
|
||||
}
|
||||
|
||||
public void addSpecialty(Specialty specialty) {
|
||||
getSpecialtiesInternal().add(specialty);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a visit.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "visits")
|
||||
public class Visit extends BaseEntity {
|
||||
|
||||
/**
|
||||
* Holds value of property date.
|
||||
*/
|
||||
@Column(name = "visit_date")
|
||||
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
|
||||
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
||||
private DateTime date;
|
||||
|
||||
/**
|
||||
* Holds value of property description.
|
||||
*/
|
||||
@NotEmpty
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Holds value of property pet.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "pet_id")
|
||||
private Pet pet;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of Visit for the current date
|
||||
*/
|
||||
public Visit() {
|
||||
this.date = new DateTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for property date.
|
||||
*
|
||||
* @return Value of property date.
|
||||
*/
|
||||
public DateTime getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for property date.
|
||||
*
|
||||
* @param date New value of property date.
|
||||
*/
|
||||
public void setDate(DateTime date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for property description.
|
||||
*
|
||||
* @return Value of property description.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for property description.
|
||||
*
|
||||
* @param description New value of property description.
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for property pet.
|
||||
*
|
||||
* @return Value of property pet.
|
||||
*/
|
||||
public Pet getPet() {
|
||||
return this.pet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for property pet.
|
||||
*
|
||||
* @param pet New value of property pet.
|
||||
*/
|
||||
public void setPet(Pet pet) {
|
||||
this.pet = pet;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,20 @@
|
|||
/**
|
||||
* The classes in this package represent PetClinic's business layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The classes in this package represent utilities used by the domain.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.style.ToStringCreator;
|
||||
import org.springframework.samples.petclinic.model.Person;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.Digits;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an owner.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "owners")
|
||||
public class Owner extends Person {
|
||||
|
||||
@Column(name = "address")
|
||||
@NotEmpty
|
||||
private String address;
|
||||
|
||||
@Column(name = "city")
|
||||
@NotEmpty
|
||||
private String city;
|
||||
|
||||
@Column(name = "telephone")
|
||||
@NotEmpty
|
||||
@Digits(fraction = 0, integer = 10)
|
||||
private String telephone;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "owner_id")
|
||||
@OrderBy("name")
|
||||
private List<Pet> pets = new ArrayList<>();
|
||||
|
||||
public String getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return this.city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return this.telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public List<Pet> getPets() {
|
||||
return this.pets;
|
||||
}
|
||||
|
||||
public void addPet(Pet pet) {
|
||||
if (pet.isNew()) {
|
||||
getPets().add(pet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
* @param name to test
|
||||
* @return a pet if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name) {
|
||||
return getPet(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Pet with the given id, or null if none found for this Owner.
|
||||
* @param id to test
|
||||
* @return a pet if pet id is already in use
|
||||
*/
|
||||
public Pet getPet(Integer id) {
|
||||
for (Pet pet : getPets()) {
|
||||
if (!pet.isNew()) {
|
||||
Integer compId = pet.getId();
|
||||
if (compId.equals(id)) {
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Pet with the given name, or null if none found for this Owner.
|
||||
* @param name to test
|
||||
* @return a pet if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name, boolean ignoreNew) {
|
||||
name = name.toLowerCase();
|
||||
for (Pet pet : getPets()) {
|
||||
if (!ignoreNew || !pet.isNew()) {
|
||||
String compName = pet.getName();
|
||||
compName = compName == null ? "" : compName.toLowerCase();
|
||||
if (compName.equals(name)) {
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this).append("id", this.getId())
|
||||
.append("new", this.isNew())
|
||||
.append("lastName", this.getLastName())
|
||||
.append("firstName", this.getFirstName())
|
||||
.append("address", this.address)
|
||||
.append("city", this.city)
|
||||
.append("telephone", this.telephone)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given {@link Visit} to the {@link Pet} with the given identifier.
|
||||
* @param petId the identifier of the {@link Pet}, must not be {@literal null}.
|
||||
* @param visit the visit to add, must not be {@literal null}.
|
||||
*/
|
||||
public void addVisit(Integer petId, Visit visit) {
|
||||
|
||||
Assert.notNull(petId, "Pet identifier must not be null!");
|
||||
Assert.notNull(visit, "Visit must not be null!");
|
||||
|
||||
Pet pet = getPet(petId);
|
||||
|
||||
Assert.notNull(pet, "Invalid Pet identifier!");
|
||||
|
||||
pet.addVisit(visit);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
class OwnerController {
|
||||
|
||||
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
|
||||
private final OwnerRepository owners;
|
||||
|
||||
public OwnerController(OwnerRepository clinicService) {
|
||||
this.owners = clinicService;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@ModelAttribute("owner")
|
||||
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
|
||||
return ownerId == null ? new Owner() : this.owners.findById(ownerId);
|
||||
}
|
||||
|
||||
@GetMapping("/owners/new")
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
Owner owner = new Owner();
|
||||
model.put("owner", owner);
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/owners/new")
|
||||
public String processCreationForm(@Valid Owner owner, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
this.owners.save(owner);
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
}
|
||||
|
||||
@GetMapping("/owners/find")
|
||||
public String initFindForm() {
|
||||
return "owners/findOwners";
|
||||
}
|
||||
|
||||
@GetMapping("/owners")
|
||||
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
|
||||
Model model) {
|
||||
// allow parameterless GET request for /owners to return all records
|
||||
if (owner.getLastName() == null) {
|
||||
owner.setLastName(""); // empty string signifies broadest possible search
|
||||
}
|
||||
|
||||
// find owners by last name
|
||||
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||
if (ownersResults.isEmpty()) {
|
||||
// no owners found
|
||||
result.rejectValue("lastName", "notFound", "not found");
|
||||
return "owners/findOwners";
|
||||
}
|
||||
|
||||
if (ownersResults.getTotalElements() == 1) {
|
||||
// 1 owner found
|
||||
owner = ownersResults.iterator().next();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
}
|
||||
|
||||
// multiple owners found
|
||||
return addPaginationModel(page, model, ownersResults);
|
||||
}
|
||||
|
||||
private String addPaginationModel(int page, Model model, Page<Owner> paginated) {
|
||||
model.addAttribute("listOwners", paginated);
|
||||
List<Owner> listOwners = paginated.getContent();
|
||||
model.addAttribute("currentPage", page);
|
||||
model.addAttribute("totalPages", paginated.getTotalPages());
|
||||
model.addAttribute("totalItems", paginated.getTotalElements());
|
||||
model.addAttribute("listOwners", listOwners);
|
||||
return "owners/ownersList";
|
||||
}
|
||||
|
||||
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
||||
int pageSize = 5;
|
||||
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||
return owners.findByLastName(lastname, pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/owners/{ownerId}/edit")
|
||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
model.addAttribute(owner);
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/owners/{ownerId}/edit")
|
||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
|
||||
@PathVariable("ownerId") int ownerId) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
owner.setId(ownerId);
|
||||
this.owners.save(owner);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom handler for displaying an owner.
|
||||
* @param ownerId the ID of the owner to display
|
||||
* @return a ModelMap with the model attributes for the view
|
||||
*/
|
||||
@GetMapping("/owners/{ownerId}")
|
||||
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
||||
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
mav.addObject(owner);
|
||||
return mav;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Owner</code> domain objects All method names are compliant
|
||||
* with Spring Data naming conventions so this interface can easily be extended for Spring
|
||||
* Data. See:
|
||||
* https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface OwnerRepository extends Repository<Owner, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve all {@link PetType}s from the data store.
|
||||
* @return a Collection of {@link PetType}s.
|
||||
*/
|
||||
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||
@Transactional(readOnly = true)
|
||||
List<PetType> findPetTypes();
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by last name, returning all owners
|
||||
* whose last name <i>starts</i> with the given name.
|
||||
* @param lastName Value to search for
|
||||
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
|
||||
* found)
|
||||
*/
|
||||
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join owner.pets WHERE owner.lastName LIKE :lastName% ")
|
||||
@Transactional(readOnly = true)
|
||||
Page<Owner> findByLastName(@Param("lastName") String lastName, Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieve an {@link Owner} from the data store by id.
|
||||
* @param id the id to search for
|
||||
* @return the {@link Owner} if found
|
||||
*/
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
@Transactional(readOnly = true)
|
||||
Owner findById(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* Save an {@link Owner} to the data store, either inserting or updating it.
|
||||
* @param owner the {@link Owner} to save
|
||||
*/
|
||||
void save(Owner owner);
|
||||
|
||||
/**
|
||||
* Returns all the owners from data store
|
||||
**/
|
||||
@Query("SELECT owner FROM Owner owner")
|
||||
@Transactional(readOnly = true)
|
||||
Page<Owner> findAll(Pageable pageable);
|
||||
|
||||
}
|
84
src/main/java/org/springframework/samples/petclinic/owner/Pet.java
Executable file
84
src/main/java/org/springframework/samples/petclinic/owner/Pet.java
Executable file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Simple business object representing a pet.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "pets")
|
||||
public class Pet extends NamedEntity {
|
||||
|
||||
@Column(name = "birth_date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate birthDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "type_id")
|
||||
private PetType type;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "pet_id")
|
||||
@OrderBy("visit_date ASC")
|
||||
private Set<Visit> visits = new LinkedHashSet<>();
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
|
||||
public PetType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(PetType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Collection<Visit> getVisits() {
|
||||
return this.visits;
|
||||
}
|
||||
|
||||
public void addVisit(Visit visit) {
|
||||
getVisits().add(visit);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
class PetController {
|
||||
|
||||
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
|
||||
|
||||
private final OwnerRepository owners;
|
||||
|
||||
public PetController(OwnerRepository owners) {
|
||||
this.owners = owners;
|
||||
}
|
||||
|
||||
@ModelAttribute("types")
|
||||
public Collection<PetType> populatePetTypes() {
|
||||
return this.owners.findPetTypes();
|
||||
}
|
||||
|
||||
@ModelAttribute("owner")
|
||||
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
|
||||
return this.owners.findById(ownerId);
|
||||
}
|
||||
|
||||
@ModelAttribute("pet")
|
||||
public Pet findPet(@PathVariable("ownerId") int ownerId,
|
||||
@PathVariable(name = "petId", required = false) Integer petId) {
|
||||
return petId == null ? new Pet() : this.owners.findById(ownerId).getPet(petId);
|
||||
}
|
||||
|
||||
@InitBinder("owner")
|
||||
public void initOwnerBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@InitBinder("pet")
|
||||
public void initPetBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setValidator(new PetValidator());
|
||||
}
|
||||
|
||||
@GetMapping("/pets/new")
|
||||
public String initCreationForm(Owner owner, ModelMap model) {
|
||||
Pet pet = new Pet();
|
||||
owner.addPet(pet);
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/pets/new")
|
||||
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
|
||||
if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
|
||||
result.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
|
||||
owner.addPet(pet);
|
||||
if (result.hasErrors()) {
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
this.owners.save(owner);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
@GetMapping("/pets/{petId}/edit")
|
||||
public String initUpdateForm(Owner owner, @PathVariable("petId") int petId, ModelMap model) {
|
||||
Pet pet = owner.getPet(petId);
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
@PostMapping("/pets/{petId}/edit")
|
||||
public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
|
||||
if (result.hasErrors()) {
|
||||
model.put("pet", pet);
|
||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||
}
|
||||
|
||||
owner.addPet(pet);
|
||||
this.owners.save(owner);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -13,14 +13,15 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* Can be Cat, Dog, Hamster...
|
||||
* @author Juergen Hoeller Can be Cat, Dog, Hamster...
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "types")
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting
|
||||
* from Spring 3.0, Formatters have come as an improvement in comparison to legacy
|
||||
* PropertyEditors. See the following links for more details: - The Spring ref doc:
|
||||
* https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#format
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Component
|
||||
public class PetTypeFormatter implements Formatter<PetType> {
|
||||
|
||||
private final OwnerRepository owners;
|
||||
|
||||
@Autowired
|
||||
public PetTypeFormatter(OwnerRepository owners) {
|
||||
this.owners = owners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String print(PetType petType, Locale locale) {
|
||||
return petType.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PetType parse(String text, Locale locale) throws ParseException {
|
||||
Collection<PetType> findPetTypes = this.owners.findPetTypes();
|
||||
for (PetType type : findPetTypes) {
|
||||
if (type.getName().equals(text)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new ParseException("type not found: " + text, 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
/**
|
||||
* <code>Validator</code> for <code>Pet</code> forms.
|
||||
* <p>
|
||||
* We're not using Bean Validation annotations here because it is easier to define such
|
||||
* validation rule in Java.
|
||||
* </p>
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class PetValidator implements Validator {
|
||||
|
||||
private static final String REQUIRED = "required";
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors errors) {
|
||||
Pet pet = (Pet) obj;
|
||||
String name = pet.getName();
|
||||
// name validation
|
||||
if (!StringUtils.hasLength(name)) {
|
||||
errors.rejectValue("name", REQUIRED, REQUIRED);
|
||||
}
|
||||
|
||||
// type validation
|
||||
if (pet.isNew() && pet.getType() == null) {
|
||||
errors.rejectValue("type", REQUIRED, REQUIRED);
|
||||
}
|
||||
|
||||
// birth date validation
|
||||
if (pet.getBirthDate() == null) {
|
||||
errors.rejectValue("birthDate", REQUIRED, REQUIRED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This Validator validates *just* Pet instances
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Pet.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
}
|
68
src/main/java/org/springframework/samples/petclinic/owner/Visit.java
Executable file
68
src/main/java/org/springframework/samples/petclinic/owner/Visit.java
Executable file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a visit.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "visits")
|
||||
public class Visit extends BaseEntity {
|
||||
|
||||
@Column(name = "visit_date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate date;
|
||||
|
||||
@NotEmpty
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Creates a new instance of Visit for the current date
|
||||
*/
|
||||
public Visit() {
|
||||
this.date = LocalDate.now();
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Controller
|
||||
class VisitController {
|
||||
|
||||
private final OwnerRepository owners;
|
||||
|
||||
public VisitController(OwnerRepository owners) {
|
||||
this.owners = owners;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before each and every @RequestMapping annotated method. 2 goals: - Make sure
|
||||
* we always have fresh data - Since we do not use the session scope, make sure that
|
||||
* Pet object always has an id (Even though id is not part of the form fields)
|
||||
* @param petId
|
||||
* @return Pet
|
||||
*/
|
||||
@ModelAttribute("visit")
|
||||
public Visit loadPetWithVisit(@PathVariable("ownerId") int ownerId, @PathVariable("petId") int petId,
|
||||
Map<String, Object> model) {
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
|
||||
Pet pet = owner.getPet(petId);
|
||||
model.put("pet", pet);
|
||||
model.put("owner", owner);
|
||||
|
||||
Visit visit = new Visit();
|
||||
pet.addVisit(visit);
|
||||
return visit;
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is
|
||||
// called
|
||||
@GetMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||
public String initNewVisitForm() {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
|
||||
// called
|
||||
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
|
||||
BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
owner.addVisit(petId, visit);
|
||||
this.owners.save(owner);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Owner</code> domain objects All method names are compliant with Spring Data naming
|
||||
* conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface OwnerRepository {
|
||||
|
||||
/**
|
||||
* Retrieve <code>Owner</code>s from the data store by last name, returning all owners whose last name <i>starts</i>
|
||||
* with the given name.
|
||||
*
|
||||
* @param lastName Value to search for
|
||||
* @return a <code>Collection</code> of matching <code>Owner</code>s (or an empty <code>Collection</code> if none
|
||||
* found)
|
||||
*/
|
||||
Collection<Owner> findByLastName(String lastName) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Retrieve an <code>Owner</code> from the data store by id.
|
||||
*
|
||||
* @param id the id to search for
|
||||
* @return the <code>Owner</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
*/
|
||||
Owner findById(int id) throws DataAccessException;
|
||||
|
||||
|
||||
/**
|
||||
* Save an <code>Owner</code> to the data store, either inserting or updating it.
|
||||
*
|
||||
* @param owner the <code>Owner</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
*/
|
||||
void save(Owner owner) throws DataAccessException;
|
||||
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Pet</code> domain objects All method names are compliant with Spring Data naming
|
||||
* conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface PetRepository {
|
||||
|
||||
/**
|
||||
* Retrieve all <code>PetType</code>s from the data store.
|
||||
*
|
||||
* @return a <code>Collection</code> of <code>PetType</code>s
|
||||
*/
|
||||
List<PetType> findPetTypes() throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Retrieve a <code>Pet</code> from the data store by id.
|
||||
*
|
||||
* @param id the id to search for
|
||||
* @return the <code>Pet</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
*/
|
||||
Pet findById(int id) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Save a <code>Pet</code> to the data store, either inserting or updating it.
|
||||
*
|
||||
* @param pet the <code>Pet</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
*/
|
||||
void save(Pet pet) throws DataAccessException;
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Vet</code> domain objects All method names are compliant with Spring Data naming
|
||||
* conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface VetRepository {
|
||||
|
||||
/**
|
||||
* Retrieve all <code>Vet</code>s from the data store.
|
||||
*
|
||||
* @return a <code>Collection</code> of <code>Vet</code>s
|
||||
*/
|
||||
Collection<Vet> findAll() throws DataAccessException;
|
||||
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Visit</code> domain objects All method names are compliant with Spring Data naming
|
||||
* conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface VisitRepository {
|
||||
|
||||
/**
|
||||
* Save a <code>Visit</code> to the data store, either inserting or updating it.
|
||||
*
|
||||
* @param visit the <code>Visit</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
*/
|
||||
void save(Visit visit) throws DataAccessException;
|
||||
|
||||
List<Visit> findByPetId(Integer petId);
|
||||
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link OwnerRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertOwner;
|
||||
|
||||
@Autowired
|
||||
public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||
|
||||
this.insertOwner = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("owners")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads {@link Owner Owners} from the data store by last name, returning all owners whose last name <i>starts</i> with
|
||||
* the given name; also loads the {@link Pet Pets} and {@link Visit Visits} for the corresponding owners, if not
|
||||
* already loaded.
|
||||
*/
|
||||
@Override
|
||||
public Collection<Owner> findByLastName(String lastName) throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("lastName", lastName + "%");
|
||||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
loadOwnersPetsAndVisits(owners);
|
||||
return owners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link Owner} with the supplied <code>id</code>; also loads the {@link Pet Pets} and {@link Visit Visits}
|
||||
* for the corresponding owner, if not already loaded.
|
||||
*/
|
||||
@Override
|
||||
public Owner findById(int id) throws DataAccessException {
|
||||
Owner owner;
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
owner = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Owner.class, id);
|
||||
}
|
||||
loadPetsAndVisits(owner);
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void loadPetsAndVisits(final Owner owner) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", owner.getId());
|
||||
final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
);
|
||||
Collection<PetType> petTypes = getPetTypes();
|
||||
for (JdbcPet pet : pets) {
|
||||
pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId()));
|
||||
owner.addPet(pet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Owner owner) throws DataAccessException {
|
||||
BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
|
||||
if (owner.isNew()) {
|
||||
Number newKey = this.insertOwner.executeAndReturnKey(parameterSource);
|
||||
owner.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
|
||||
"city=:city, telephone=:telephone WHERE id=:id",
|
||||
parameterSource);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(),
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the {@link Pet} and {@link Visit} data for the supplied {@link List} of {@link Owner Owners}.
|
||||
*
|
||||
* @param owners the list of owners for whom the pet and visit data should be loaded
|
||||
* @see #loadPetsAndVisits(Owner)
|
||||
*/
|
||||
private void loadOwnersPetsAndVisits(List<Owner> owners) {
|
||||
for (Owner owner : owners) {
|
||||
loadPetsAndVisits(owner);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
|
||||
/**
|
||||
* Subclass of Pet that carries temporary id properties which are only relevant for a JDBC implementation of the
|
||||
* PetRepository.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class JdbcPet extends Pet {
|
||||
|
||||
private int typeId;
|
||||
|
||||
private int ownerId;
|
||||
|
||||
public int getTypeId() {
|
||||
return this.typeId;
|
||||
}
|
||||
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public int getOwnerId() {
|
||||
return this.ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(int ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcPetRepositoryImpl implements PetRepository {
|
||||
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertPet;
|
||||
|
||||
private OwnerRepository ownerRepository;
|
||||
|
||||
private VisitRepository visitRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public JdbcPetRepositoryImpl(DataSource dataSource, OwnerRepository ownerRepository, VisitRepository visitRepository) {
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
this.insertPet = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("pets")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.visitRepository = visitRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PetType> findPetTypes() throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pet findById(int id) throws DataAccessException {
|
||||
JdbcPet pet;
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
pet = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
|
||||
params,
|
||||
new JdbcPetRowMapper());
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Pet.class, id);
|
||||
}
|
||||
Owner owner = this.ownerRepository.findById(pet.getOwnerId());
|
||||
owner.addPet(pet);
|
||||
pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));
|
||||
|
||||
List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
|
||||
for (Visit visit : visits) {
|
||||
pet.addVisit(visit);
|
||||
}
|
||||
return pet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Pet pet) throws DataAccessException {
|
||||
if (pet.isNew()) {
|
||||
Number newKey = this.insertPet.executeAndReturnKey(
|
||||
createPetParameterSource(pet));
|
||||
pet.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
|
||||
"owner_id=:owner_id WHERE id=:id",
|
||||
createPetParameterSource(pet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Pet} instance.
|
||||
*/
|
||||
private MapSqlParameterSource createPetParameterSource(Pet pet) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", pet.getId())
|
||||
.addValue("name", pet.getName())
|
||||
.addValue("birth_date", pet.getBirthDate().toDate())
|
||||
.addValue("type_id", pet.getType().getId())
|
||||
.addValue("owner_id", pet.getOwner().getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
* {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* of the {@link JdbcPet} class.
|
||||
*/
|
||||
class JdbcPetRowMapper implements RowMapper<JdbcPet> {
|
||||
|
||||
@Override
|
||||
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
|
||||
JdbcPet pet = new JdbcPet();
|
||||
pet.setId(rs.getInt("pets.id"));
|
||||
pet.setName(rs.getString("name"));
|
||||
Date birthDate = rs.getDate("birth_date");
|
||||
pet.setBirthDate(new DateTime(birthDate));
|
||||
pet.setTypeId(rs.getInt("type_id"));
|
||||
pet.setOwnerId(rs.getInt("owner_id"));
|
||||
return pet;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import org.springframework.data.jdbc.core.OneToManyResultSetExtractor;
|
||||
import org.springframework.jdbc.core.ResultSetExtractor;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* {@link ResultSetExtractor} implementation by using the
|
||||
* {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions.
|
||||
*/
|
||||
public class JdbcPetVisitExtractor extends
|
||||
OneToManyResultSetExtractor<JdbcPet, Visit, Integer> {
|
||||
|
||||
public JdbcPetVisitExtractor() {
|
||||
super(new JdbcPetRowMapper(), new JdbcVisitRowMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer mapPrimaryKey(ResultSet rs) throws SQLException {
|
||||
return rs.getInt("pets.id");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer mapForeignKey(ResultSet rs) throws SQLException {
|
||||
if (rs.getObject("visits.pet_id") == null) {
|
||||
return null;
|
||||
} else {
|
||||
return rs.getInt("visits.pet_id");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addChild(JdbcPet root, Visit child) {
|
||||
root.addVisit(child);
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.samples.petclinic.model.Specialty;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link VetRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcVetRepositoryImpl implements VetRepository {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public JdbcVetRepositoryImpl(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the cache of Vets that the ClinicService is holding.
|
||||
*/
|
||||
@Override
|
||||
public Collection<Vet> findAll() throws DataAccessException {
|
||||
List<Vet> vets = new ArrayList<>();
|
||||
// Retrieve the list of all vets.
|
||||
vets.addAll(this.jdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
|
||||
BeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
|
||||
// Retrieve the list of all possible specialties.
|
||||
final List<Specialty> specialties = this.jdbcTemplate.query(
|
||||
"SELECT id, name FROM specialties",
|
||||
BeanPropertyRowMapper.newInstance(Specialty.class));
|
||||
|
||||
// Build each vet's list of specialties.
|
||||
for (Vet vet : vets) {
|
||||
final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
|
||||
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
|
||||
new BeanPropertyRowMapper<Integer>() {
|
||||
@Override
|
||||
public Integer mapRow(ResultSet rs, int row) throws SQLException {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
},
|
||||
vet.getId());
|
||||
for (int specialtyId : vetSpecialtiesIds) {
|
||||
Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
|
||||
vet.addSpecialty(specialty);
|
||||
}
|
||||
}
|
||||
return vets;
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple JDBC-based implementation of the {@link VisitRepository} interface.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Sam Brannen
|
||||
* @author Thomas Risberg
|
||||
* @author Mark Fisher
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Repository
|
||||
public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private SimpleJdbcInsert insertVisit;
|
||||
|
||||
@Autowired
|
||||
public JdbcVisitRepositoryImpl(DataSource dataSource) {
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
this.insertVisit = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("visits")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Visit visit) throws DataAccessException {
|
||||
if (visit.isNew()) {
|
||||
Number newKey = this.insertVisit.executeAndReturnKey(
|
||||
createVisitParameterSource(visit));
|
||||
visit.setId(newKey.intValue());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Visit update not supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
|
||||
*/
|
||||
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", visit.getId())
|
||||
.addValue("visit_date", visit.getDate().toDate())
|
||||
.addValue("description", visit.getDescription())
|
||||
.addValue("pet_id", visit.getPet().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
return this.jdbcTemplate.query(
|
||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
new JdbcVisitRowMapper(), petId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* of the {@link Visit} class.
|
||||
*/
|
||||
class JdbcVisitRowMapper implements RowMapper<Visit> {
|
||||
|
||||
@Override
|
||||
public Visit mapRow(ResultSet rs, int row) throws SQLException {
|
||||
Visit visit = new Visit();
|
||||
visit.setId(rs.getInt("visit_id"));
|
||||
Date visitDate = rs.getDate("visit_date");
|
||||
visit.setDate(new DateTime(visitDate));
|
||||
visit.setDescription(rs.getString("description"));
|
||||
return visit;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The classes in this package represent the JDBC implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link OwnerRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
/**
|
||||
* Important: in the current version of this method, we load Owners with all their Pets and Visits while
|
||||
* we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
|
||||
* There are some ways to improve it such as:
|
||||
* - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
|
||||
* - Turning on lazy-loading and using {@link OpenSessionInViewFilter}
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Owner> findByLastName(String lastName) {
|
||||
// using 'join fetch' because a single query should load both owners and pets
|
||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||
Query query = this.em.createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName");
|
||||
query.setParameter("lastName", lastName + "%");
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Owner findById(int id) {
|
||||
// using 'join fetch' because a single query should load both owners and pets
|
||||
// using 'left join fetch' because it might happen that an owner does not have pets yet
|
||||
Query query = this.em.createQuery("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id");
|
||||
query.setParameter("id", id);
|
||||
return (Owner) query.getSingleResult();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Owner owner) {
|
||||
if (owner.getId() == null) {
|
||||
this.em.persist(owner);
|
||||
} else {
|
||||
this.em.merge(owner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link PetRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaPetRepositoryImpl implements PetRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<PetType> findPetTypes() {
|
||||
return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pet findById(int id) {
|
||||
return this.em.find(Pet.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Pet pet) {
|
||||
if (pet.getId() == null) {
|
||||
this.em.persist(pet);
|
||||
} else {
|
||||
this.em.merge(pet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the {@link VetRepository} interface.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaVetRepositoryImpl implements VetRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "vets")
|
||||
@SuppressWarnings("unchecked")
|
||||
public Collection<Vet> findAll() {
|
||||
return this.em.createQuery("SELECT distinct vet FROM Vet vet left join fetch vet.specialties ORDER BY vet.lastName, vet.firstName").getResultList();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* JPA implementation of the ClinicService interface using EntityManager.
|
||||
* <p/>
|
||||
* <p>The mappings are defined in "orm.xml" located in the META-INF directory.
|
||||
*
|
||||
* @author Mike Keith
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @since 22.4.2006
|
||||
*/
|
||||
@Repository
|
||||
public class JpaVisitRepositoryImpl implements VisitRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
@Override
|
||||
public void save(Visit visit) {
|
||||
if (visit.getId() == null) {
|
||||
this.em.persist(visit);
|
||||
} else {
|
||||
this.em.merge(visit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
|
||||
query.setParameter("id", petId);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The classes in this package represent the JPA implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link OwnerRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataOwnerRepository extends OwnerRepository, Repository<Owner, Integer> {
|
||||
|
||||
@Override
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
public Collection<Owner> findByLastName(@Param("lastName") String lastName);
|
||||
|
||||
@Override
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
public Owner findById(@Param("id") int id);
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link PetRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataPetRepository extends PetRepository, Repository<Pet, Integer> {
|
||||
|
||||
@Override
|
||||
@Query("SELECT ptype FROM PetType ptype ORDER BY ptype.name")
|
||||
List<PetType> findPetTypes() throws DataAccessException;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link VetRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataVetRepository extends VetRepository, Repository<Vet, Integer> {
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
||||
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA specialization of the {@link VisitRepository} interface
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataVisitRepository extends VisitRepository, Repository<Visit, Integer> {
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
|
||||
|
||||
/**
|
||||
* Mostly used as a facade so all controllers have a single point of entry
|
||||
*
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface ClinicService {
|
||||
|
||||
Collection<PetType> findPetTypes() throws DataAccessException;
|
||||
|
||||
Owner findOwnerById(int id) throws DataAccessException;
|
||||
|
||||
Pet findPetById(int id) throws DataAccessException;
|
||||
|
||||
void savePet(Pet pet) throws DataAccessException;
|
||||
|
||||
void saveVisit(Visit visit) throws DataAccessException;
|
||||
|
||||
Collection<Vet> findVets() throws DataAccessException;
|
||||
|
||||
void saveOwner(Owner owner) throws DataAccessException;
|
||||
|
||||
Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException;
|
||||
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Mostly used as a facade for all Petclinic controllers
|
||||
* Also a placeholder for @Transactional and @Cacheable annotations
|
||||
*
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Service
|
||||
public class ClinicServiceImpl implements ClinicService {
|
||||
|
||||
private PetRepository petRepository;
|
||||
private VetRepository vetRepository;
|
||||
private OwnerRepository ownerRepository;
|
||||
private VisitRepository visitRepository;
|
||||
|
||||
@Autowired
|
||||
public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) {
|
||||
this.petRepository = petRepository;
|
||||
this.vetRepository = vetRepository;
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.visitRepository = visitRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Collection<PetType> findPetTypes() throws DataAccessException {
|
||||
return petRepository.findPetTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Owner findOwnerById(int id) throws DataAccessException {
|
||||
return ownerRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException {
|
||||
return ownerRepository.findByLastName(lastName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveOwner(Owner owner) throws DataAccessException {
|
||||
ownerRepository.save(owner);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void saveVisit(Visit visit) throws DataAccessException {
|
||||
visitRepository.save(visit);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Pet findPetById(int id) throws DataAccessException {
|
||||
return petRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void savePet(Pet pet) throws DataAccessException {
|
||||
petRepository.save(pet);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(value = "vets")
|
||||
public Collection<Vet> findVets() throws DataAccessException {
|
||||
return vetRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
|
||||
/**
|
||||
* Cache configuration intended for caches providing the JCache API. This configuration
|
||||
* creates the used cache for the application and enables statistics that become
|
||||
* accessible via JMX.
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableCaching
|
||||
class CacheConfiguration {
|
||||
|
||||
@Bean
|
||||
public JCacheManagerCustomizer petclinicCacheConfigurationCustomizer() {
|
||||
return cm -> cm.createCache("vets", cacheConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a simple configuration that enable statistics via the JCache programmatic
|
||||
* configuration API.
|
||||
* <p>
|
||||
* Within the configuration object that is provided by the JCache API standard, there
|
||||
* is only a very limited set of configuration options. The really relevant
|
||||
* configuration options (like the size limit) must be set via a configuration
|
||||
* mechanism that is provided by the selected JCache implementation.
|
||||
*/
|
||||
private javax.cache.configuration.Configuration<Object, Object> cacheConfiguration() {
|
||||
return new MutableConfiguration<>().setStatisticsEnabled(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* Controller used to showcase what happens when an exception is thrown
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* <p/>
|
||||
* Also see how a view that resolves to "error" has been added ("error.html").
|
||||
*/
|
||||
@Controller
|
||||
class CrashController {
|
||||
|
||||
@GetMapping("/oups")
|
||||
public String triggerException() {
|
||||
throw new RuntimeException(
|
||||
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
class WelcomeController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String welcome() {
|
||||
return "welcome";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.util;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be
|
||||
* monitored using any JMX console such as the jConsole
|
||||
* <p/>
|
||||
* This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Michael Isvy
|
||||
* @since 2.5
|
||||
*/
|
||||
@ManagedResource("petclinic:type=CallMonitor")
|
||||
@Aspect
|
||||
public class CallMonitoringAspect {
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
private int callCount = 0;
|
||||
|
||||
private long accumulatedCallTime = 0;
|
||||
|
||||
@ManagedAttribute
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
this.callCount = 0;
|
||||
this.accumulatedCallTime = 0;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public int getCallCount() {
|
||||
return callCount;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public long getCallTime() {
|
||||
if (this.callCount > 0)
|
||||
return this.accumulatedCallTime / this.callCount;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Around("within(@org.springframework.stereotype.Repository *)")
|
||||
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
if (this.enabled) {
|
||||
StopWatch sw = new StopWatch(joinPoint.toShortString());
|
||||
|
||||
sw.start("invoke");
|
||||
try {
|
||||
return joinPoint.proceed();
|
||||
} finally {
|
||||
sw.stop();
|
||||
synchronized (this) {
|
||||
this.callCount++;
|
||||
this.accumulatedCallTime += sw.getTotalTimeMillis();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.samples.petclinic.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
|
||||
/**
|
||||
* Utility methods for handling entities. Separate from the BaseEntity class mainly because of dependency on the
|
||||
* ORM-associated ObjectRetrievalFailureException.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @see org.springframework.samples.petclinic.model.BaseEntity
|
||||
* @since 29.10.2003
|
||||
*/
|
||||
public abstract class EntityUtils {
|
||||
|
||||
/**
|
||||
* Look up the entity of the given class with the given id in the given collection.
|
||||
*
|
||||
* @param entities the collection to search
|
||||
* @param entityClass the entity class to look up
|
||||
* @param entityId the entity id to look up
|
||||
* @return the found entity
|
||||
* @throws ObjectRetrievalFailureException if the entity was not found
|
||||
*/
|
||||
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
|
||||
throws ObjectRetrievalFailureException {
|
||||
for (T entity : entities) {
|
||||
if (entity.getId() == entityId && entityClass.isInstance(entity)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
throw new ObjectRetrievalFailureException(entityClass, entityId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -13,10 +13,12 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
/**
|
||||
* Models a {@link Vet Vet's} specialty (for example, dentistry).
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
import org.springframework.samples.petclinic.model.Person;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a veterinarian.
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "vets")
|
||||
public class Vet extends Person {
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
|
||||
private Set<Specialty> specialties;
|
||||
|
||||
protected Set<Specialty> getSpecialtiesInternal() {
|
||||
if (this.specialties == null) {
|
||||
this.specialties = new HashSet<>();
|
||||
}
|
||||
return this.specialties;
|
||||
}
|
||||
|
||||
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
|
||||
this.specialties = specialties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
|
||||
PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true));
|
||||
return Collections.unmodifiableList(sortedSpecs);
|
||||
}
|
||||
|
||||
public int getNrOfSpecialties() {
|
||||
return getSpecialtiesInternal().size();
|
||||
}
|
||||
|
||||
public void addSpecialty(Specialty specialty) {
|
||||
getSpecialtiesInternal().add(specialty);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Controller
|
||||
class VetController {
|
||||
|
||||
private final VetRepository vetRepository;
|
||||
|
||||
public VetController(VetRepository clinicService) {
|
||||
this.vetRepository = clinicService;
|
||||
}
|
||||
|
||||
@GetMapping("/vets.html")
|
||||
public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||
// objects so it is simpler for Object-Xml mapping
|
||||
Vets vets = new Vets();
|
||||
Page<Vet> paginated = findPaginated(page);
|
||||
vets.getVetList().addAll(paginated.toList());
|
||||
return addPaginationModel(page, paginated, model);
|
||||
|
||||
}
|
||||
|
||||
private String addPaginationModel(int page, Page<Vet> paginated, Model model) {
|
||||
List<Vet> listVets = paginated.getContent();
|
||||
model.addAttribute("currentPage", page);
|
||||
model.addAttribute("totalPages", paginated.getTotalPages());
|
||||
model.addAttribute("totalItems", paginated.getTotalElements());
|
||||
model.addAttribute("listVets", listVets);
|
||||
return "vets/vetList";
|
||||
}
|
||||
|
||||
private Page<Vet> findPaginated(int page) {
|
||||
int pageSize = 5;
|
||||
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||
return vetRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
@GetMapping({ "/vets" })
|
||||
public @ResponseBody Vets showResourcesVetList() {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||
// objects so it is simpler for JSon/Object mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.vetRepository.findAll());
|
||||
return vets;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Repository class for <code>Vet</code> domain objects All method names are compliant
|
||||
* with Spring Data naming conventions so this interface can easily be extended for Spring
|
||||
* Data. See:
|
||||
* https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-creation
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public interface VetRepository extends Repository<Vet, Integer> {
|
||||
|
||||
/**
|
||||
* Retrieve all <code>Vet</code>s from the data store.
|
||||
* @return a <code>Collection</code> of <code>Vet</code>s
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable("vets")
|
||||
Collection<Vet> findAll() throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Retrieve all <code>Vet</code>s from data store in Pages
|
||||
* @param pageable
|
||||
* @return
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable("vets")
|
||||
Page<Vet> findAll(Pageable pageable) throws DataAccessException;
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -13,31 +13,31 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
* Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link
|
||||
* org.springframework.web.servlet.view.xml.MarshallingView}.
|
||||
* Simple domain object representing a list of veterinarians. Mostly here to be used for
|
||||
* the 'vets' {@link org.springframework.web.servlet.view.xml.MarshallingView}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class Vets {
|
||||
|
||||
private List<Vet> vets;
|
||||
private List<Vet> vets;
|
||||
|
||||
@XmlElement
|
||||
public List<Vet> getVetList() {
|
||||
if (vets == null) {
|
||||
vets = new ArrayList<>();
|
||||
}
|
||||
return vets;
|
||||
}
|
||||
@XmlElement
|
||||
public List<Vet> getVetList() {
|
||||
if (vets == null) {
|
||||
vets = new ArrayList<>();
|
||||
}
|
||||
return vets;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
* Controller used to showcase what happens when an exception is thrown
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* <p/>
|
||||
* Also see how the bean of type 'SimpleMappingExceptionResolver' has been declared inside
|
||||
* /WEB-INF/mvc-core-config.xml
|
||||
*/
|
||||
@Controller
|
||||
public class CrashController {
|
||||
|
||||
@RequestMapping(value = "/oups", method = RequestMethod.GET)
|
||||
public String triggerException() {
|
||||
throw new RuntimeException("Expected: controller used to showcase what " +
|
||||
"happens when an exception is thrown");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
public class OwnerController {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public OwnerController(ClinicService clinicService) {
|
||||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/new", method = RequestMethod.GET)
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
Owner owner = new Owner();
|
||||
model.put("owner", owner);
|
||||
return "owners/createOrUpdateOwnerForm";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
|
||||
public String processCreationForm(@Valid Owner owner, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return "owners/createOrUpdateOwnerForm";
|
||||
} else {
|
||||
this.clinicService.saveOwner(owner);
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/find", method = RequestMethod.GET)
|
||||
public String initFindForm(Map<String, Object> model) {
|
||||
model.put("owner", new Owner());
|
||||
return "owners/findOwners";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners", method = RequestMethod.GET)
|
||||
public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
|
||||
|
||||
// allow parameterless GET request for /owners to return all records
|
||||
if (owner.getLastName() == null) {
|
||||
owner.setLastName(""); // empty string signifies broadest possible search
|
||||
}
|
||||
|
||||
// find owners by last name
|
||||
Collection<Owner> results = this.clinicService.findOwnerByLastName(owner.getLastName());
|
||||
if (results.isEmpty()) {
|
||||
// no owners found
|
||||
result.rejectValue("lastName", "notFound", "not found");
|
||||
return "owners/findOwners";
|
||||
} else if (results.size() == 1) {
|
||||
// 1 owner found
|
||||
owner = results.iterator().next();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
} else {
|
||||
// multiple owners found
|
||||
model.put("selections", results);
|
||||
return "owners/ownersList";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
|
||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
Owner owner = this.clinicService.findOwnerById(ownerId);
|
||||
model.addAttribute(owner);
|
||||
return "owners/createOrUpdateOwnerForm";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.POST)
|
||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return "owners/createOrUpdateOwnerForm";
|
||||
} else {
|
||||
this.clinicService.saveOwner(owner);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom handler for displaying an owner.
|
||||
*
|
||||
* @param ownerId the ID of the owner to display
|
||||
* @return a ModelMap with the model attributes for the view
|
||||
*/
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
||||
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||
mav.addObject(this.clinicService.findOwnerById(ownerId));
|
||||
return mav;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
public class PetController {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
||||
@Autowired
|
||||
public PetController(ClinicService clinicService) {
|
||||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@ModelAttribute("types")
|
||||
public Collection<PetType> populatePetTypes() {
|
||||
return this.clinicService.findPetTypes();
|
||||
}
|
||||
|
||||
@ModelAttribute("owner")
|
||||
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
|
||||
Owner owner = this.clinicService.findOwnerById(ownerId);
|
||||
return owner;
|
||||
}
|
||||
|
||||
@InitBinder("owner")
|
||||
public void initOwnerBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
@InitBinder("pet")
|
||||
public void initPetBinder(WebDataBinder dataBinder) {
|
||||
dataBinder.setValidator(new PetValidator());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pets/new", method = RequestMethod.GET)
|
||||
public String initCreationForm(Owner owner, ModelMap model) {
|
||||
Pet pet = new Pet();
|
||||
owner.addPet(pet);
|
||||
model.put("pet", pet);
|
||||
return "pets/createOrUpdatePetForm";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pets/new", method = RequestMethod.POST)
|
||||
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
|
||||
if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
|
||||
result.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
if (result.hasErrors()) {
|
||||
model.put("pet", pet);
|
||||
return "pets/createOrUpdatePetForm";
|
||||
} else {
|
||||
owner.addPet(pet);
|
||||
this.clinicService.savePet(pet);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.GET)
|
||||
public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
|
||||
Pet pet = this.clinicService.findPetById(petId);
|
||||
model.put("pet", pet);
|
||||
return "pets/createOrUpdatePetForm";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.POST)
|
||||
public String processUpdateForm(@Valid Pet pet, Owner owner, BindingResult result, ModelMap model) {
|
||||
if (result.hasErrors()) {
|
||||
model.put("pet", pet);
|
||||
return "pets/createOrUpdatePetForm";
|
||||
} else {
|
||||
owner.addPet(pet);
|
||||
this.clinicService.savePet(pet);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.Formatter;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
|
||||
/**
|
||||
* Instructs Spring MVC on how to parse and print elements of type 'PetType'. Starting from Spring 3.0, Formatters have
|
||||
* come as an improvement in comparison to legacy PropertyEditors. See the following links for more details: - The
|
||||
* Spring ref doc: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/validation.html#format-Formatter-SPI
|
||||
* - A nice blog entry from Gordon Dickens: http://gordondickens.com/wordpress/2010/09/30/using-spring-3-0-custom-type-converter/
|
||||
* <p/>
|
||||
* Also see how the bean 'conversionService' has been declared inside /WEB-INF/mvc-core-config.xml
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
public class PetTypeFormatter implements Formatter<PetType> {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public PetTypeFormatter(ClinicService clinicService) {
|
||||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String print(PetType petType, Locale locale) {
|
||||
return petType.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PetType parse(String text, Locale locale) throws ParseException {
|
||||
Collection<PetType> findPetTypes = this.clinicService.findPetTypes();
|
||||
for (PetType type : findPetTypes) {
|
||||
if (type.getName().equals(text)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new ParseException("type not found: " + text, 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
/**
|
||||
* <code>Validator</code> for <code>Pet</code> forms.
|
||||
* <p>
|
||||
* We're not using Bean Validation annotations here because it is easier to define such validation rule in Java.
|
||||
* </p>
|
||||
*
|
||||
* @author Ken Krebs
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class PetValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors errors) {
|
||||
Pet pet = (Pet) obj;
|
||||
String name = pet.getName();
|
||||
// name validation
|
||||
if (!StringUtils.hasLength(name)) {
|
||||
errors.rejectValue("name", "required", "required");
|
||||
}
|
||||
|
||||
// type validation
|
||||
if (pet.isNew() && pet.getType() == null) {
|
||||
errors.rejectValue("type", "required", "required");
|
||||
}
|
||||
|
||||
// birth date validation
|
||||
if (pet.getBirthDate() == null) {
|
||||
errors.rejectValue("birthDate", "required", "required");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This Validator validates *just* Pet instances
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Pet.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Vets;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Controller
|
||||
public class VetController {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public VetController(ClinicService clinicService) {
|
||||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/vets.xml", "/vets.html"})
|
||||
public String showVetList(Map<String, Object> model) {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// so it is simpler for Object-Xml mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.clinicService.findVets());
|
||||
model.put("vets", vets);
|
||||
return "vets/vetList";
|
||||
}
|
||||
|
||||
@RequestMapping("/vets.json")
|
||||
public
|
||||
@ResponseBody
|
||||
Vets showResourcesVetList() {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// so it is simpler for JSon/Object mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.clinicService.findVets());
|
||||
return vets;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Ken Krebs
|
||||
* @author Arjen Poutsma
|
||||
* @author Michael Isvy
|
||||
*/
|
||||
@Controller
|
||||
public class VisitController {
|
||||
|
||||
private final ClinicService clinicService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public VisitController(ClinicService clinicService) {
|
||||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before each and every @RequestMapping annotated method.
|
||||
* 2 goals:
|
||||
* - Make sure we always have fresh data
|
||||
* - Since we do not use the session scope, make sure that Pet object always has an id
|
||||
* (Even though id is not part of the form fields)
|
||||
*
|
||||
* @param petId
|
||||
* @return Pet
|
||||
*/
|
||||
@ModelAttribute("visit")
|
||||
public Visit loadPetWithVisit(@PathVariable("petId") int petId) {
|
||||
Pet pet = this.clinicService.findPetById(petId);
|
||||
Visit visit = new Visit();
|
||||
pet.addVisit(visit);
|
||||
return visit;
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
|
||||
@RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET)
|
||||
public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Object> model) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
|
||||
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
|
||||
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
} else {
|
||||
this.clinicService.saveVisit(visit);
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/*/pets/{petId}/visits", method = RequestMethod.GET)
|
||||
public String showVisits(@PathVariable int petId, Map<String, Object> model) {
|
||||
model.put("visits", this.clinicService.findPetById(petId).getVisits());
|
||||
return "visitList";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
/**
|
||||
* The classes in this package represent PetClinic's web presentation layer.
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<html>
|
||||
<body>
|
||||
<p>
|
||||
The Spring Data Binding framework, an internal library used by Spring Web Flow.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,53 +0,0 @@
|
|||
<head>
|
||||
<style type="text/css">
|
||||
table.speakersTable {
|
||||
width: 70%;
|
||||
padding: 10;
|
||||
spacing: 10;
|
||||
}
|
||||
|
||||
img.speakerPic {
|
||||
float: right;
|
||||
padding: 10;
|
||||
width: 90;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<h1>Organisation</h1>
|
||||
|
||||
<h1>Speakers</h1>
|
||||
<table class="speakersTable">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img class="speakerPic" alt="Sergiu Bodiu"
|
||||
src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img alt="Sergiu Bodiu" src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"
|
||||
width="84" height="84" align="right" hspace="10"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
7
src/main/resources/application-mysql.properties
Normal file
7
src/main/resources/application-mysql.properties
Normal file
|
@ -0,0 +1,7 @@
|
|||
# database init, supports mysql too
|
||||
database=mysql
|
||||
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost/petclinic}
|
||||
spring.datasource.username=${MYSQL_USER:petclinic}
|
||||
spring.datasource.password=${MYSQL_PASS:petclinic}
|
||||
# SQL is written to be idempotent so this is safe
|
||||
spring.sql.init.mode=always
|
6
src/main/resources/application-postgres.properties
Normal file
6
src/main/resources/application-postgres.properties
Normal file
|
@ -0,0 +1,6 @@
|
|||
database=postgres
|
||||
spring.datasource.url=${POSTGRES_URL:jdbc:postgresql://localhost/petclinic}
|
||||
spring.datasource.username=${POSTGRES_USER:petclinic}
|
||||
spring.datasource.password=${POSTGRES_PASS:petclinic}
|
||||
# SQL is written to be idempotent so this is safe
|
||||
spring.sql.init.mode=always
|
25
src/main/resources/application.properties
Normal file
25
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,25 @@
|
|||
# database init, supports mysql too
|
||||
database=h2
|
||||
spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql
|
||||
spring.sql.init.data-locations=classpath*:db/${database}/data.sql
|
||||
|
||||
# Web
|
||||
spring.thymeleaf.mode=HTML
|
||||
|
||||
# JPA
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.open-in-view=true
|
||||
|
||||
# Internationalization
|
||||
spring.messages.basename=messages/messages
|
||||
|
||||
# Actuator
|
||||
management.endpoints.web.exposure.include=*
|
||||
|
||||
# Logging
|
||||
logging.level.org.springframework=INFO
|
||||
# logging.level.org.springframework.web=DEBUG
|
||||
# logging.level.org.springframework.context.annotation=TRACE
|
||||
|
||||
# Maximum time static resources should be cached
|
||||
spring.web.resources.cache.cachecontrol.max-age=12h
|
15
src/main/resources/banner.txt
Normal file
15
src/main/resources/banner.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
|\ _,,,--,,_
|
||||
/,`.-'`' ._ \-;;,_
|
||||
_______ __|,4- ) )_ .;.(__`'-'__ ___ __ _ ___ _______
|
||||
| | '---''(_/._)-'(_\_) | | | | | | | | |
|
||||
| _ | ___|_ _| | | | | |_| | | | __ _ _
|
||||
| |_| | |___ | | | | | | | | | | \ \ \ \
|
||||
| ___| ___| | | | _| |___| | _ | | _| \ \ \ \
|
||||
| | | |___ | | | |_| | | | | | | |_ ) ) ) )
|
||||
|___| |_______| |___| |_______|_______|___|_| |__|___|_______| / / / /
|
||||
==================================================================/_/_/_/
|
||||
|
||||
:: Built with Spring Boot :: ${spring-boot.version}
|
||||
|
17
src/main/resources/cache/ehcache.xml
vendored
17
src/main/resources/cache/ehcache.xml
vendored
|
@ -1,17 +0,0 @@
|
|||
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="ehcache.xsd"
|
||||
updateCheck="false">
|
||||
<diskStore path="java.io.tmpdir"/>
|
||||
|
||||
<!-- objects are evicted from the cache every 60 seconds -->
|
||||
<cache name="vets"
|
||||
timeToLiveSeconds="60"
|
||||
maxElementsInMemory="100"
|
||||
eternal="false"
|
||||
overflowToDisk="false"
|
||||
maxElementsOnDisk="10000000"
|
||||
diskPersistent="false"
|
||||
diskExpiryThreadIntervalSeconds="1"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
</ehcache>
|
419
src/main/resources/cache/ehcache.xsd
vendored
419
src/main/resources/cache/ehcache.xsd
vendored
|
@ -1,419 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.7">
|
||||
|
||||
<xs:element name="ehcache">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="managementRESTService"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="diskStore"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="sizeOfPolicy"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="transactionManagerLookup"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="cacheManagerEventListenerFactory"/>
|
||||
<xs:element maxOccurs="unbounded" minOccurs="0" ref="cacheManagerPeerProviderFactory"/>
|
||||
<xs:element maxOccurs="unbounded" minOccurs="0" ref="cacheManagerPeerListenerFactory"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="terracottaConfig"/>
|
||||
<xs:element maxOccurs="1" minOccurs="0" ref="defaultCache"/>
|
||||
<xs:element maxOccurs="unbounded" minOccurs="0" ref="cache"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="name" use="optional"/>
|
||||
<xs:attribute default="true" name="updateCheck" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute default="autodetect" name="monitoring" type="monitoringType" use="optional"/>
|
||||
<xs:attribute default="true" name="dynamicConfig" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute default="15" name="defaultTransactionTimeoutInSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalHeap" type="memoryUnitOrPercentage" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalOffHeap" type="memoryUnit" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalDisk" type="memoryUnit" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="managementRESTService">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="enabled" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="bind" use="optional"/>
|
||||
<xs:attribute name="securityServiceLocation" use="optional"/>
|
||||
<xs:attribute name="securityServiceTimeout" use="optional" type="xs:integer"/>
|
||||
<xs:attribute name="sslEnabled" use="optional" type="xs:boolean"/>
|
||||
<xs:attribute name="needClientAuth" use="optional" type="xs:boolean"/>
|
||||
<xs:attribute name="sampleHistorySize" use="optional" type="xs:integer"/>
|
||||
<xs:attribute name="sampleIntervalSeconds" use="optional" type="xs:integer"/>
|
||||
<xs:attribute name="sampleSearchIntervalSeconds" use="optional" type="xs:integer"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="diskStore">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="path" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="transactionManagerLookup">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheManagerEventListenerFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheManagerPeerProviderFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheManagerPeerListenerFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="terracottaConfig">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element maxOccurs="1" minOccurs="0" name="tc-config">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:any maxOccurs="unbounded" minOccurs="0" processContents="skip"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute default="localhost:9510" name="url" use="optional"/>
|
||||
<xs:attribute name="rejoin" type="xs:boolean" use="optional" default="false"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<!-- add clone support for addition of cacheExceptionHandler. Important! -->
|
||||
<xs:element name="defaultCache">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheEventListenerFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheExtensionFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheLoaderFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheDecoratorFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="bootstrapCacheLoaderFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="cacheExceptionHandlerFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="pinning"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="terracotta"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="cacheWriter"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="copyStrategy"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="elementValueComparator"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="sizeOfPolicy"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="persistence"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="diskExpiryThreadIntervalSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="diskSpoolBufferSizeMB" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="diskPersistent" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="diskAccessStripes" type="xs:integer" use="optional" default="1"/>
|
||||
<xs:attribute name="eternal" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="maxElementsInMemory" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxEntriesLocalHeap" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="clearOnFlush" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="memoryStoreEvictionPolicy" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="overflowToDisk" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="timeToIdleSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="timeToLiveSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxElementsOnDisk" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxEntriesLocalDisk" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="transactionalMode" type="transactionalMode" use="optional" default="off"/>
|
||||
<xs:attribute name="statistics" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="copyOnRead" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="copyOnWrite" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="cacheLoaderTimeoutMillis" type="xs:integer" use="optional" default="0"/>
|
||||
<xs:attribute name="overflowToOffHeap" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="maxMemoryOffHeap" type="xs:string" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cache">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheEventListenerFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheExtensionFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheLoaderFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="cacheDecoratorFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="bootstrapCacheLoaderFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="cacheExceptionHandlerFactory"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="pinning"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="terracotta"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="cacheWriter"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="copyStrategy"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="searchable"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="elementValueComparator"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="sizeOfPolicy"/>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="persistence"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="diskExpiryThreadIntervalSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="diskSpoolBufferSizeMB" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="diskPersistent" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="diskAccessStripes" type="xs:integer" use="optional" default="1"/>
|
||||
<xs:attribute name="eternal" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="maxElementsInMemory" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxEntriesLocalHeap" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="memoryStoreEvictionPolicy" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="clearOnFlush" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="overflowToDisk" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="timeToIdleSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="timeToLiveSeconds" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxElementsOnDisk" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="maxEntriesLocalDisk" type="xs:integer" use="optional"/>
|
||||
<xs:attribute name="transactionalMode" type="transactionalMode" use="optional" default="off"/>
|
||||
<xs:attribute name="statistics" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="copyOnRead" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="copyOnWrite" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="logging" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="cacheLoaderTimeoutMillis" type="xs:integer" use="optional" default="0"/>
|
||||
<xs:attribute name="overflowToOffHeap" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="maxMemoryOffHeap" type="xs:string" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalHeap" type="memoryUnitOrPercentage" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalOffHeap" type="memoryUnitOrPercentage" use="optional"/>
|
||||
<xs:attribute default="0" name="maxBytesLocalDisk" type="memoryUnitOrPercentage" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheEventListenerFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
<xs:attribute name="listenFor" use="optional" type="notificationScope" default="all"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="bootstrapCacheLoaderFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheExtensionFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheExceptionHandlerFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheLoaderFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="cacheDecoratorFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="searchAttribute">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="name" use="required" type="xs:string"/>
|
||||
<xs:attribute name="expression" type="xs:string"/>
|
||||
<xs:attribute name="class" type="xs:string"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="searchable">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="unbounded" ref="searchAttribute"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="keys" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="values" use="optional" type="xs:boolean" default="true"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="pinning">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="store" use="required" type="pinningStoreType"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="terracotta">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="nonstop"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="clustered" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="valueMode" use="optional" type="terracottaCacheValueType" default="serialization"/>
|
||||
<xs:attribute name="coherentReads" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="localKeyCache" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="localKeyCacheSize" use="optional" type="xs:positiveInteger" default="300000"/>
|
||||
<xs:attribute name="orphanEviction" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="orphanEvictionPeriod" use="optional" type="xs:positiveInteger" default="4"/>
|
||||
<xs:attribute name="copyOnRead" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="coherent" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="consistency" use="optional" type="consistencyType" default="eventual"/>
|
||||
<xs:attribute name="synchronousWrites" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="concurrency" use="optional" type="xs:nonNegativeInteger" default="0"/>
|
||||
<xs:attribute name="localCacheEnabled" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="compressionEnabled" use="optional" type="xs:boolean" default="false"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:simpleType name="consistencyType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="strong"/>
|
||||
<xs:enumeration value="eventual"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:element name="nonstop">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="timeoutBehavior"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="enabled" use="optional" type="xs:boolean" default="true"/>
|
||||
<xs:attribute name="immediateTimeout" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="timeoutMillis" use="optional" type="xs:positiveInteger" default="30000"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="timeoutBehavior">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="type" use="optional" type="timeoutBehaviorType" default="exception"/>
|
||||
<xs:attribute name="properties" use="optional" default=""/>
|
||||
<xs:attribute name="propertySeparator" use="optional" default=","/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:simpleType name="timeoutBehaviorType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="noop"/>
|
||||
<xs:enumeration value="exception"/>
|
||||
<xs:enumeration value="localReads"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="monitoringType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="autodetect"/>
|
||||
<xs:enumeration value="on"/>
|
||||
<xs:enumeration value="off"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="pinningStoreType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="localHeap"/>
|
||||
<xs:enumeration value="localMemory"/>
|
||||
<xs:enumeration value="inCache"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="terracottaCacheValueType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="serialization"/>
|
||||
<xs:enumeration value="identity"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="transactionalMode">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="off"/>
|
||||
<xs:enumeration value="xa_strict"/>
|
||||
<xs:enumeration value="xa"/>
|
||||
<xs:enumeration value="local"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:element name="cacheWriter">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element minOccurs="0" maxOccurs="1" ref="cacheWriterFactory"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="writeMode" use="optional" type="writeModeType" default="write-through"/>
|
||||
<xs:attribute name="notifyListenersOnException" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="minWriteDelay" use="optional" type="xs:nonNegativeInteger" default="1"/>
|
||||
<xs:attribute name="maxWriteDelay" use="optional" type="xs:nonNegativeInteger" default="1"/>
|
||||
<xs:attribute name="rateLimitPerSecond" use="optional" type="xs:nonNegativeInteger" default="0"/>
|
||||
<xs:attribute name="writeCoalescing" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="writeBatching" use="optional" type="xs:boolean" default="false"/>
|
||||
<xs:attribute name="writeBatchSize" use="optional" type="xs:positiveInteger" default="1"/>
|
||||
<xs:attribute name="retryAttempts" use="optional" type="xs:nonNegativeInteger" default="0"/>
|
||||
<xs:attribute name="retryAttemptDelaySeconds" use="optional" type="xs:nonNegativeInteger" default="1"/>
|
||||
<xs:attribute name="writeBehindConcurrency" use="optional" type="xs:nonNegativeInteger" default="1"/>
|
||||
<xs:attribute name="writeBehindMaxQueueSize" use="optional" type="xs:nonNegativeInteger" default="0"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:simpleType name="writeModeType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="write-through"/>
|
||||
<xs:enumeration value="write-behind"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:element name="cacheWriterFactory">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required"/>
|
||||
<xs:attribute name="properties" use="optional"/>
|
||||
<xs:attribute name="propertySeparator" use="optional"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="copyStrategy">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="elementValueComparator">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="class" use="required" type="xs:string"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="sizeOfPolicy">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="maxDepth" use="required" type="xs:integer"/>
|
||||
<xs:attribute name="maxDepthExceededBehavior" use="optional" default="continue"
|
||||
type="maxDepthExceededBehavior"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:element name="persistence">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="strategy" use="required" type="persistenceStrategy"/>
|
||||
<xs:attribute name="synchronousWrites" use="optional" default="false" type="xs:boolean"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
<xs:simpleType name="persistenceStrategy">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="localTempSwap"/>
|
||||
<xs:enumeration value="localRestartable"/>
|
||||
<xs:enumeration value="none"/>
|
||||
<xs:enumeration value="distributed"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="maxDepthExceededBehavior">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="continue"/>
|
||||
<xs:enumeration value="abort"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
<xs:simpleType name="notificationScope">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:enumeration value="local"/>
|
||||
<xs:enumeration value="remote"/>
|
||||
<xs:enumeration value="all"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="memoryUnit">
|
||||
<xs:restriction base="xs:token">
|
||||
<xs:pattern value="[0-9]+[bBkKmMgG]?"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="memoryUnitOrPercentage">
|
||||
<xs:restriction base="xs:token">
|
||||
<xs:pattern value="([0-9]+[bBkKmMgG]?|100%|[0-9]{1,2}%)"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:schema>
|
|
@ -1,6 +0,0 @@
|
|||
# ==================================
|
||||
# Dandelion-Datatables configuration
|
||||
# ==================================
|
||||
|
||||
# Disable the asset management of Dandelion-Core for all non-DataTable-related assets
|
||||
main.standalone=true
|
53
src/main/resources/db/h2/data.sql
Normal file
53
src/main/resources/db/h2/data.sql
Normal file
|
@ -0,0 +1,53 @@
|
|||
INSERT INTO vets VALUES (default, 'James', 'Carter');
|
||||
INSERT INTO vets VALUES (default, 'Helen', 'Leary');
|
||||
INSERT INTO vets VALUES (default, 'Linda', 'Douglas');
|
||||
INSERT INTO vets VALUES (default, 'Rafael', 'Ortega');
|
||||
INSERT INTO vets VALUES (default, 'Henry', 'Stevens');
|
||||
INSERT INTO vets VALUES (default, 'Sharon', 'Jenkins');
|
||||
|
||||
INSERT INTO specialties VALUES (default, 'radiology');
|
||||
INSERT INTO specialties VALUES (default, 'surgery');
|
||||
INSERT INTO specialties VALUES (default, 'dentistry');
|
||||
|
||||
INSERT INTO vet_specialties VALUES (2, 1);
|
||||
INSERT INTO vet_specialties VALUES (3, 2);
|
||||
INSERT INTO vet_specialties VALUES (3, 3);
|
||||
INSERT INTO vet_specialties VALUES (4, 2);
|
||||
INSERT INTO vet_specialties VALUES (5, 1);
|
||||
|
||||
INSERT INTO types VALUES (default, 'cat');
|
||||
INSERT INTO types VALUES (default, 'dog');
|
||||
INSERT INTO types VALUES (default, 'lizard');
|
||||
INSERT INTO types VALUES (default, 'snake');
|
||||
INSERT INTO types VALUES (default, 'bird');
|
||||
INSERT INTO types VALUES (default, 'hamster');
|
||||
|
||||
INSERT INTO owners VALUES (default, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023');
|
||||
INSERT INTO owners VALUES (default, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749');
|
||||
INSERT INTO owners VALUES (default, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763');
|
||||
INSERT INTO owners VALUES (default, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198');
|
||||
INSERT INTO owners VALUES (default, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765');
|
||||
INSERT INTO owners VALUES (default, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654');
|
||||
INSERT INTO owners VALUES (default, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387');
|
||||
INSERT INTO owners VALUES (default, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683');
|
||||
INSERT INTO owners VALUES (default, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435');
|
||||
INSERT INTO owners VALUES (default, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
INSERT INTO pets VALUES (default, 'Leo', '2010-09-07', 1, 1);
|
||||
INSERT INTO pets VALUES (default, 'Basil', '2012-08-06', 6, 2);
|
||||
INSERT INTO pets VALUES (default, 'Rosy', '2011-04-17', 2, 3);
|
||||
INSERT INTO pets VALUES (default, 'Jewel', '2010-03-07', 2, 3);
|
||||
INSERT INTO pets VALUES (default, 'Iggy', '2010-11-30', 3, 4);
|
||||
INSERT INTO pets VALUES (default, 'George', '2010-01-20', 4, 5);
|
||||
INSERT INTO pets VALUES (default, 'Samantha', '2012-09-04', 1, 6);
|
||||
INSERT INTO pets VALUES (default, 'Max', '2012-09-04', 1, 6);
|
||||
INSERT INTO pets VALUES (default, 'Lucky', '2011-08-06', 5, 7);
|
||||
INSERT INTO pets VALUES (default, 'Mulligan', '2007-02-24', 2, 8);
|
||||
INSERT INTO pets VALUES (default, 'Freddy', '2010-03-09', 5, 9);
|
||||
INSERT INTO pets VALUES (default, 'Lucky', '2010-06-24', 2, 10);
|
||||
INSERT INTO pets VALUES (default, 'Sly', '2012-06-08', 1, 10);
|
||||
|
||||
INSERT INTO visits VALUES (default, 7, '2013-01-01', 'rabies shot');
|
||||
INSERT INTO visits VALUES (default, 8, '2013-01-02', 'rabies shot');
|
||||
INSERT INTO visits VALUES (default, 8, '2013-01-03', 'neutered');
|
||||
INSERT INTO visits VALUES (default, 7, '2013-01-04', 'spayed');
|
64
src/main/resources/db/h2/schema.sql
Normal file
64
src/main/resources/db/h2/schema.sql
Normal file
|
@ -0,0 +1,64 @@
|
|||
DROP TABLE vet_specialties IF EXISTS;
|
||||
DROP TABLE vets IF EXISTS;
|
||||
DROP TABLE specialties IF EXISTS;
|
||||
DROP TABLE visits IF EXISTS;
|
||||
DROP TABLE pets IF EXISTS;
|
||||
DROP TABLE types IF EXISTS;
|
||||
DROP TABLE owners IF EXISTS;
|
||||
|
||||
|
||||
CREATE TABLE vets (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
first_name VARCHAR(30),
|
||||
last_name VARCHAR(30)
|
||||
);
|
||||
CREATE INDEX vets_last_name ON vets (last_name);
|
||||
|
||||
CREATE TABLE specialties (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR(80)
|
||||
);
|
||||
CREATE INDEX specialties_name ON specialties (name);
|
||||
|
||||
CREATE TABLE vet_specialties (
|
||||
vet_id INTEGER NOT NULL,
|
||||
specialty_id INTEGER NOT NULL
|
||||
);
|
||||
ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id);
|
||||
ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id);
|
||||
|
||||
CREATE TABLE types (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR(80)
|
||||
);
|
||||
CREATE INDEX types_name ON types (name);
|
||||
|
||||
CREATE TABLE owners (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
first_name VARCHAR(30),
|
||||
last_name VARCHAR_IGNORECASE(30),
|
||||
address VARCHAR(255),
|
||||
city VARCHAR(80),
|
||||
telephone VARCHAR(20)
|
||||
);
|
||||
CREATE INDEX owners_last_name ON owners (last_name);
|
||||
|
||||
CREATE TABLE pets (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name VARCHAR(30),
|
||||
birth_date DATE,
|
||||
type_id INTEGER NOT NULL,
|
||||
owner_id INTEGER
|
||||
);
|
||||
ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id);
|
||||
ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id);
|
||||
CREATE INDEX pets_name ON pets (name);
|
||||
|
||||
CREATE TABLE visits (
|
||||
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
pet_id INTEGER,
|
||||
visit_date DATE,
|
||||
description VARCHAR(255)
|
||||
);
|
||||
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
||||
CREATE INDEX visits_pet_id ON visits (pet_id);
|
|
@ -36,7 +36,7 @@ CREATE INDEX types_name ON types (name);
|
|||
CREATE TABLE owners (
|
||||
id INTEGER IDENTITY PRIMARY KEY,
|
||||
first_name VARCHAR(30),
|
||||
last_name VARCHAR(30),
|
||||
last_name VARCHAR_IGNORECASE(30),
|
||||
address VARCHAR(255),
|
||||
city VARCHAR(80),
|
||||
telephone VARCHAR(20)
|
||||
|
@ -48,7 +48,7 @@ CREATE TABLE pets (
|
|||
name VARCHAR(30),
|
||||
birth_date DATE,
|
||||
type_id INTEGER NOT NULL,
|
||||
owner_id INTEGER NOT NULL
|
||||
owner_id INTEGER
|
||||
);
|
||||
ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id);
|
||||
ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id);
|
||||
|
@ -56,7 +56,7 @@ CREATE INDEX pets_name ON pets (name);
|
|||
|
||||
CREATE TABLE visits (
|
||||
id INTEGER IDENTITY PRIMARY KEY,
|
||||
pet_id INTEGER NOT NULL,
|
||||
pet_id INTEGER,
|
||||
visit_date DATE,
|
||||
description VARCHAR(255)
|
||||
);
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue